FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
arrayfire/src/api/cpp/reduce.cpp at feature/optional-graphics · arrayfire/arrayfire · GitHub
arrayfire
arrayfire
Repository navigation
Code
Issues
292
(292)
Pull requests
39
(39)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
arrayfire
/
src
/
api
/
cpp
/
reduce.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
346 lines (301 loc) · 12.6 KB
Breadcrumbs
arrayfire
/
src
/
api
/
cpp
/
reduce.cpp
Copy path
File metadata and controls
346 lines (301 loc) · 12.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
******************************************************
* 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
<
af/algorithm.h
>
#
include
<
af/array.h
>
#
include
<
af/compatible.h
>
#
include
"
common.hpp
"
#
include
"
error.hpp
"
namespace
af
{
array
sum
(
const
array &in,
const
int
dim) {
af_array out =
0
;
AF_THROW
(
af_sum
(&out, in.
get
(),
getFNSD
(dim, in.
dims
())));
return
array
(out);
}
array
sum
(
const
array &in,
const
int
dim,
const
double
nanval) {
af_array out =
0
;
AF_THROW
(
af_sum_nan
(&out, in.
get
(), dim, nanval));
return
array
(out);
}
void
sumByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim) {
af_array okeys, ovals;
AF_THROW
(
af_sum_by_key
(&okeys, &ovals, keys.
get
(), vals.
get
(),
getFNSD
(dim, vals.
dims
())));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
void
sumByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim,
const
double
nanval) {
af_array okeys, ovals;
AF_THROW
(
af_sum_by_key_nan
(&okeys, &ovals, keys.
get
(), vals.
get
(), dim, nanval));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
array
product
(
const
array &in,
const
int
dim) {
af_array out =
0
;
AF_THROW
(
af_product
(&out, in.
get
(),
getFNSD
(dim, in.
dims
())));
return
array
(out);
}
array
product
(
const
array &in,
const
int
dim,
const
double
nanval) {
af_array out =
0
;
AF_THROW
(
af_product_nan
(&out, in.
get
(), dim, nanval));
return
array
(out);
}
void
productByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim) {
af_array okeys, ovals;
AF_THROW
(
af_product_by_key
(&okeys, &ovals, keys.
get
(), vals.
get
(),
getFNSD
(dim, vals.
dims
())));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
void
productByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim,
const
double
nanval) {
af_array okeys, ovals;
AF_THROW
(
af_product_by_key_nan
(&okeys, &ovals, keys.
get
(), vals.
get
(), dim,
nanval));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
array
mul
(
const
array &in,
const
int
dim) {
return
product
(in, dim); }
array
min
(
const
array &in,
const
int
dim) {
af_array out =
0
;
AF_THROW
(
af_min
(&out, in.
get
(),
getFNSD
(dim, in.
dims
())));
return
array
(out);
}
void
minByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim) {
af_array okeys, ovals;
AF_THROW
(
af_min_by_key
(&okeys, &ovals, keys.
get
(), vals.
get
(),
getFNSD
(dim, vals.
dims
())));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
array
max
(
const
array &in,
const
int
dim) {
af_array out =
0
;
AF_THROW
(
af_max
(&out, in.
get
(),
getFNSD
(dim, in.
dims
())));
return
array
(out);
}
void
maxByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim) {
af_array okeys, ovals;
AF_THROW
(
af_max_by_key
(&okeys, &ovals, keys.
get
(), vals.
get
(),
getFNSD
(dim, vals.
dims
())));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
void
max
(array &val, array &idx,
const
array &in,
const
array &ragged_len,
const
int
dim) {
af_array oval, oidx;
AF_THROW
(
af_max_ragged
(&oval, &oidx, in.
get
(), ragged_len.
get
(), dim));
val =
array
(oval);
idx =
array
(oidx);
}
//
2.1 compatibility
array
alltrue
(
const
array &in,
const
int
dim) {
return
allTrue
(in, dim); }
array
allTrue
(
const
array &in,
const
int
dim) {
af_array out =
0
;
AF_THROW
(
af_all_true
(&out, in.
get
(),
getFNSD
(dim, in.
dims
())));
return
array
(out);
}
void
allTrueByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim) {
af_array okeys, ovals;
AF_THROW
(
af_all_true_by_key
(&okeys, &ovals, keys.
get
(), vals.
get
(),
getFNSD
(dim, vals.
dims
())));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
//
2.1 compatibility
array
anytrue
(
const
array &in,
const
int
dim) {
return
anyTrue
(in, dim); }
array
anyTrue
(
const
array &in,
const
int
dim) {
af_array out =
0
;
AF_THROW
(
af_any_true
(&out, in.
get
(),
getFNSD
(dim, in.
dims
())));
return
array
(out);
}
void
anyTrueByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim) {
af_array okeys, ovals;
AF_THROW
(
af_any_true_by_key
(&okeys, &ovals, keys.
get
(), vals.
get
(),
getFNSD
(dim, vals.
dims
())));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
array
count
(
const
array &in,
const
int
dim) {
af_array out =
0
;
AF_THROW
(
af_count
(&out, in.
get
(),
getFNSD
(dim, in.
dims
())));
return
array
(out);
}
void
countByKey
(array &keys_out, array &vals_out,
const
array &keys,
const
array &vals,
const
int
dim) {
af_array okeys, ovals;
AF_THROW
(
af_count_by_key
(&okeys, &ovals, keys.
get
(), vals.
get
(),
getFNSD
(dim, vals.
dims
())));
keys_out =
array
(okeys);
vals_out =
array
(ovals);
}
void
min
(array &val, array &idx,
const
array &in,
const
int
dim) {
af_array out =
0
;
af_array loc =
0
;
AF_THROW
(
af_imin
(&out, &loc, in.
get
(),
getFNSD
(dim, in.
dims
())));
val =
array
(out);
idx =
array
(loc);
}
void
max
(array &val, array &idx,
const
array &in,
const
int
dim) {
af_array out =
0
;
af_array loc =
0
;
AF_THROW
(
af_imax
(&out, &loc, in.
get
(),
getFNSD
(dim, in.
dims
())));
val =
array
(out);
idx =
array
(loc);
}
#
define
INSTANTIATE
(
fnC, fnCPP
) \
INSTANTIATE_REAL
(fnC, fnCPP,
float
) \
INSTANTIATE_REAL
(fnC, fnCPP,
double
) \
INSTANTIATE_REAL
(fnC, fnCPP,
int
) \
INSTANTIATE_REAL
(fnC, fnCPP,
unsigned
) \
INSTANTIATE_REAL
(fnC, fnCPP,
long
) \
INSTANTIATE_REAL
(fnC, fnCPP,
unsigned
long
) \
INSTANTIATE_REAL
(fnC, fnCPP,
long
long
) \
INSTANTIATE_REAL
(fnC, fnCPP,
unsigned
long
long
) \
INSTANTIATE_REAL
(fnC, fnCPP,
short
) \
INSTANTIATE_REAL
(fnC, fnCPP,
unsigned
short
) \
INSTANTIATE_REAL
(fnC, fnCPP,
char
) \
INSTANTIATE_REAL
(fnC, fnCPP,
signed
char
) \
INSTANTIATE_REAL
(fnC, fnCPP,
unsigned
char
) \
INSTANTIATE_CPLX
(fnC, fnCPP, af_cfloat,
float
) \
INSTANTIATE_CPLX
(fnC, fnCPP, af_cdouble,
double
)
#
define
INSTANTIATE_REAL
(
fnC, fnCPP, T
) \
template
<> \
AFAPI
T
fnCPP
(
const
array &in) { \
double
rval, ival; \
AF_THROW
(af_##fnC##
_all
(&rval, &ival, in.
get
())); \
return
(T)(rval); \
}
#
define
INSTANTIATE_CPLX
(
fnC, fnCPP, T, Tr
) \
template
<> \
AFAPI
T
fnCPP
(
const
array &in) { \
double
rval, ival; \
AF_THROW
(af_##fnC##
_all
(&rval, &ival, in.
get
())); \
T
out
((Tr)rval, (Tr)ival); \
return
out; \
}
#
define
INSTANTIATE_ARRAY
(
fnC, fnCPP
) \
template
<> \
AFAPI
af::array
fnCPP
(
const
array &in) { \
af_array out =
0
; \
AF_THROW
(af_##fnC##
_all_array
(&out, in.
get
())); \
return
array
(out); \
}
INSTANTIATE
(sum, sum)
INSTANTIATE
(product, product)
INSTANTIATE
(min, min)
INSTANTIATE
(max, max)
INSTANTIATE
(all_true, allTrue)
INSTANTIATE
(any_true, anyTrue)
INSTANTIATE
(count, count)
INSTANTIATE_REAL
(all_true, allTrue,
bool
);
INSTANTIATE_REAL
(any_true, anyTrue,
bool
);
INSTANTIATE_ARRAY
(sum, sum)
INSTANTIATE_ARRAY
(product, product)
INSTANTIATE_ARRAY
(min, min)
INSTANTIATE_ARRAY
(max, max)
INSTANTIATE_ARRAY
(all_true, allTrue)
INSTANTIATE_ARRAY
(any_true, anyTrue)
INSTANTIATE_ARRAY
(count, count)
#
undef
INSTANTIATE_REAL
#
undef
INSTANTIATE_CPLX
#
undef
INSTANTIATE_ARRAY
#
define
INSTANTIATE_REAL
(
fnC, fnCPP, T
) \
template
<> \
AFAPI
T
fnCPP
(
const
array &in,
const
double
nanval) { \
double
rval, ival; \
AF_THROW
(af_##fnC##
_all
(&rval, &ival, in.
get
(), nanval)); \
return
(T)(rval); \
}
#
define
INSTANTIATE_CPLX
(
fnC, fnCPP, T, Tr
) \
template
<> \
AFAPI
T
fnCPP
(
const
array &in,
const
double
nanval) { \
double
rval, ival; \
AF_THROW
(af_##fnC##
_all
(&rval, &ival, in.
get
(), nanval)); \
T
out
((Tr)rval, (Tr)ival); \
return
out; \
}
#
define
INSTANTIATE_ARRAY
(
fnC, fnCPP
) \
template
<> \
AFAPI
af::array
fnCPP
(
const
array &in,
const
double
nanval) { \
af_array out =
0
; \
AF_THROW
(af_##fnC##
_all_array
(&out, in.
get
(), nanval)); \
return
array
(out); \
}
INSTANTIATE_ARRAY
(sum_nan, sum)
INSTANTIATE_ARRAY
(product_nan, product)
INSTANTIATE
(sum_nan, sum)
INSTANTIATE
(product_nan, product)
#
undef
INSTANTIATE_REAL
#
undef
INSTANTIATE_CPLX
#
undef
INSTANTIATE
#
undef
INSTANTIATE_ARRAY
#
define
INSTANTIATE_COMPAT
(
fnCPP, fnCompat, T
) \
template
<> \
AFAPI
T
fnCompat
(
const
array &in) { \
return
fnCPP<T>(in); \
}
#
define
INSTANTIATE
(
fnCPP, fnCompat
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
float
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
double
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
int
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
unsigned
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
long
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
unsigned
long
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
long
long
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
unsigned
long
long
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
char
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
signed
char
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
unsigned
char
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat, af_cfloat) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat, af_cdouble) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
short
) \
INSTANTIATE_COMPAT
(fnCPP, fnCompat,
unsigned
short
)
INSTANTIATE
(product, mul)
INSTANTIATE
(allTrue, alltrue)
INSTANTIATE
(anyTrue, anytrue)
INSTANTIATE_COMPAT
(allTrue, alltrue,
bool
)
INSTANTIATE_COMPAT
(anyTrue, anytrue,
bool
)
#
undef
INSTANTIATE
#
undef
INSTANTIATE_COMPAT
#
define
INSTANTIATE_REAL
(
fn, T
) \
template
<> \
AFAPI
void
fn
(T *val,
unsigned
*idx,
const
array &in) { \
double
rval, ival; \
AF_THROW
(af_i##fn##
_all
(&rval, &ival, idx, in.
get
())); \
*val = (T)(rval); \
}
#
define
INSTANTIATE_CPLX
(
fn, T, Tr
) \
template
<> \
AFAPI
void
fn
(T *val,
unsigned
*idx,
const
array &in) { \
double
rval, ival; \
AF_THROW
(af_i##fn##
_all
(&rval, &ival, idx, in.
get
())); \
*val =
T
((Tr)rval, (Tr)ival); \
}
#
define
INSTANTIATE
(
fn
) \
INSTANTIATE_REAL
(fn,
float
) \
INSTANTIATE_REAL
(fn,
double
) \
INSTANTIATE_REAL
(fn,
int
) \
INSTANTIATE_REAL
(fn,
unsigned
) \
INSTANTIATE_REAL
(fn,
char
) \
INSTANTIATE_REAL
(fn,
signed
char
) \
INSTANTIATE_REAL
(fn,
unsigned
char
) \
INSTANTIATE_REAL
(fn,
short
) \
INSTANTIATE_REAL
(fn,
unsigned
short
) \
INSTANTIATE_CPLX
(fn, af_cfloat,
float
) \
INSTANTIATE_CPLX
(fn, af_cdouble,
double
)
INSTANTIATE
(min)
INSTANTIATE
(max)
}
//
namespace af
Back
|
FazBrowse Home
|
New Git URL