forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.cpp
More file actions
113 lines (90 loc) · 3.6 KB
/
set.cpp
File metadata and controls
113 lines (90 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <complex>
#include <af/defines.h>
#include <af/algorithm.h>
#include <err_common.hpp>
#include <handle.hpp>
#include <backend.hpp>
#include <set.hpp>
using af::dim4;
using namespace detail;
template<typename T>
static inline af_array setUnique(const af_array in, const bool is_sorted)
{
return getHandle(setUnique(getArray<T>(in), is_sorted));
}
af_err af_set_unique(af_array *out, const af_array in, const bool is_sorted)
{
try {
af_dtype type = getInfo(in).getType();
af_array res;
switch(type) {
case f32: res = setUnique<float >(in, is_sorted); break;
case f64: res = setUnique<double >(in, is_sorted); break;
case s32: res = setUnique<int >(in, is_sorted); break;
case u32: res = setUnique<uint >(in, is_sorted); break;
case b8: res = setUnique<char >(in, is_sorted); break;
case u8: res = setUnique<uchar >(in, is_sorted); break;
default: TYPE_ERROR(1, type);
}
std::swap(*out, res);
} CATCHALL;
return AF_SUCCESS;
}
template<typename T>
static inline af_array setUnion(const af_array first, const af_array second, const bool is_unique)
{
return getHandle(setUnion(getArray<T>(first), getArray<T>(second), is_unique));
}
af_err af_set_union(af_array *out, const af_array first, const af_array second, const bool is_unique)
{
try {
af_dtype first_type = getInfo(first).getType();
af_dtype second_type = getInfo(second).getType();
ARG_ASSERT(1, first_type == second_type);
af_array res;
switch(first_type) {
case f32: res = setUnion<float >(first, second, is_unique); break;
case f64: res = setUnion<double >(first, second, is_unique); break;
case s32: res = setUnion<int >(first, second, is_unique); break;
case u32: res = setUnion<uint >(first, second, is_unique); break;
case b8: res = setUnion<char >(first, second, is_unique); break;
case u8: res = setUnion<uchar >(first, second, is_unique); break;
default: TYPE_ERROR(1, first_type);
}
std::swap(*out, res);
} CATCHALL;
return AF_SUCCESS;
}
template<typename T>
static inline af_array setIntersect(const af_array first, const af_array second, const bool is_unique)
{
return getHandle(setIntersect(getArray<T>(first), getArray<T>(second), is_unique));
}
af_err af_set_intersect(af_array *out, const af_array first, const af_array second, const bool is_unique)
{
try {
af_dtype first_type = getInfo(first).getType();
af_dtype second_type = getInfo(second).getType();
ARG_ASSERT(1, first_type == second_type);
af_array res;
switch(first_type) {
case f32: res = setIntersect<float >(first, second, is_unique); break;
case f64: res = setIntersect<double >(first, second, is_unique); break;
case s32: res = setIntersect<int >(first, second, is_unique); break;
case u32: res = setIntersect<uint >(first, second, is_unique); break;
case b8: res = setIntersect<char >(first, second, is_unique); break;
case u8: res = setIntersect<uchar >(first, second, is_unique); break;
default: TYPE_ERROR(1, first_type);
}
std::swap(*out, res);
} CATCHALL;
return AF_SUCCESS;
}