-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathalgorithm.dox
More file actions
493 lines (283 loc) · 13 KB
/
algorithm.dox
File metadata and controls
493 lines (283 loc) · 13 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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/*!
\page batch_detail_algo algorithm
This function runs across all batches in the input simultaneously.
*/
/**
\addtogroup arrayfire_func
@{
\defgroup reduce_func_sum sum
\ingroup reduce_mat
Sum array elements over a given dimension.
This table defines output types for corresponding input types:
Input Type | Output Type
--------------------|---------------------
f32, f64, c32, c64 | same as input
s32, s64, u32, u64 | same as input
s16, s8 | s32
u16, u8, b8 | u32
\copydoc batch_detail_algo
\defgroup reduce_func_sum_by_key sumByKey
\ingroup reduce_mat
Sum array elements over a given dimension, according to an array of keys.
The values corresponding to each group of consecutive equal keys will be summed
together. Keys can repeat; however, only consecutive key values will be
considered for each reduction. If a key value is repeated somewhere else in the
keys array it will be considered the start of a new reduction. There are two
outputs: the reduced set of consecutive keys and the corresponding final
set of reduced values.
An example demonstrating the reduction behavior can be seen in the following
snippet.
\snippet test/reduce.cpp ex_reduce_sum_by_key
The keys' input type must be integer (s32 or u32).
This table defines output types for corresponding input types:
Input Type | Output Type
--------------------|---------------------
f32, f64, c32, c64 | same as input
s32, s64, u32, u64 | same as input
s16, s8 | s32
u16, u8, b8 | u32
f16 | f32
The keys array must be 1-dimensional matching the size of the reduced
dimension. An example of multi-dimensional reduce-by-key can be seen below:
\snippet test/reduce.cpp ex_reduce_sum_by_key_dim
\defgroup reduce_func_product product
\ingroup reduce_mat
Multiply array elements over a given dimension.
This table defines output types for corresponding input types:
Input Type | Output Type
--------------------|---------------------
f32, f64, c32, c64 | same as input
s32, u32, s64, u64 | same as input
s16, s8 | s32
u16, u8, b8 | u32
\copydoc batch_detail_algo
\defgroup reduce_func_product_by_key productByKey
\ingroup reduce_mat
Multiply array elements over a given dimension, according to an array of keys.
The values corresponding to each group of consecutive equal keys will be
multiplied together. Keys can repeat; however, only consecutive key values will
be considered for each reduction. If a key value is repeated somewhere else in
the keys array it will be considered the start of a new reduction. There are
two outputs: the reduced set of consecutive keys and the corresponding final
set of reduced values.
An example demonstrating the reduction behavior can be seen in the following
snippet.
\snippet test/reduce.cpp ex_reduce_product_by_key
The keys' input type must be integer (s32 or u32).
This table defines output types for corresponding input types:
Input Type | Output Type
--------------------|---------------------
f32, f64, c32, c64 | same as input
s32, u32, s64, u64 | same as input
s16, s8 | s32
u16, u8, b8 | u32
f16 | f32
The keys array must be 1-dimenstional matching the size of the reduced
dimension. An example of multi-dimensional reduce-by-key can be seen below:
\snippet test/reduce.cpp ex_reduce_product_by_key_dim
\defgroup reduce_func_min min
\ingroup reduce_mat
Return the minimum along a given dimension.
\copydoc batch_detail_algo
\defgroup reduce_func_min_by_key minByKey
\ingroup reduce_mat
Return the minimum along a given dimension, according to an array of keys.
The minimum is returned from the values corresponding to each group of
consecutive equal keys. Keys can repeat; however, only consecutive key values
will be considered for each reduction. If a key value is repeated somewhere
else in the keys array it will be considered the start of a new reduction.
There are two outputs: the reduced set of consecutive keys and the
corresponding final set of reduced values.
An example demonstrating the reduction behavior can be seen in the following
snippet.
\snippet test/reduce.cpp ex_reduce_min_by_key
The keys' input type must be integer (s32 or u32).
The output type is the same as input type.
The keys array must be 1-dimenstional matching the size of the reduced
dimension. An example of multi-dimensional reduce-by-key can be seen below:
\snippet test/reduce.cpp ex_reduce_min_by_key_dim
\defgroup reduce_func_max max
\ingroup reduce_mat
Return the maximum along a given dimension.
\copydoc batch_detail_algo
\defgroup reduce_func_max_by_key maxByKey
\ingroup reduce_mat
Return the maximum along a given dimension, according to an array of keys.
The maximum is returned from the values corresponding to each group of
consecutive equal keys. Keys can repeat; however, only consecutive key values
will be considered for each reduction. If a key value is repeated somewhere
else in the keys array it will be considered the start of a new reduction.
There are two outputs: the reduced set of consecutive keys and the
corresponding final set of reduced values.
An example demonstrating the reduction behavior can be seen in the following
snippet.
\snippet test/reduce.cpp ex_reduce_max_by_key
The keys' input type must be integer (s32 or u32).
The output type is the same as input type.
The keys array must be 1-dimenstional matching the size of the reduced
dimension. An example of multi-dimensional reduce-by-key can be seen below:
\snippet test/reduce.cpp ex_reduce_max_by_key_dim
\defgroup reduce_func_all_true allTrue
\ingroup reduce_mat
Check if all values along a given dimension are true.
Return type is `b8` for all input types.
\copydoc batch_detail_algo
\defgroup reduce_func_all_true_by_key allTrueByKey
\ingroup reduce_mat
Check if all values along a given dimension are true, according to an array of
keys.
All values corresponding to each group of consecutive equal keys will be tested
to make sure all are true. Keys can repeat; however, only consecutive key
values will be considered for each reduction. If a key value is repeated
somewhere else in the keys array it will be considered the start of a new
reduction. There are two outputs: the reduced set of consecutive keys and the
corresponding final set of reduced values.
An example demonstrating the reduction behavior can be seen in the following
snippet.
\snippet test/reduce.cpp ex_reduce_alltrue_by_key
The keys' input type must be integer (s32 or u32).
The output type is `b8`.
The keys array must be 1-dimenstional matching the size of the reduced
dimension. An example of multi-dimensional reduce-by-key can be seen below:
\snippet test/reduce.cpp ex_reduce_alltrue_by_key_dim
\defgroup reduce_func_any_true anytrue
\ingroup reduce_mat
Check if any values along a given dimension are true.
The output type is `b8`.
\copydoc batch_detail_algo
\defgroup reduce_func_anytrue_by_key anyTrueByKey
\ingroup reduce_mat
Check if any values along a given dimension are true, according to an array of
keys.
Values corresponding to each group of consecutive equal keys will be tested to
check if any are true. Keys can repeat; however, only consecutive key
values will be considered for each reduction. If a key value is repeated
somewhere else in the keys array it will be considered the start of a new
reduction. There are two outputs: the reduced set of consecutive keys and the
corresponding final set of reduced values.
An example demonstrating the reduction behavior can be seen in the following
snippet.
\snippet test/reduce.cpp ex_reduce_anytrue_by_key
The keys' input type must be integer (s32 or u32).
The output type is `b8`.
The keys array must be 1-dimenstional matching the size of the reduced
dimension. An example of multi-dimensional reduce-by-key can be seen below:
\snippet test/reduce.cpp ex_reduce_anytrue_by_key_dim
\defgroup reduce_func_count count
\ingroup reduce_mat
Count non-zero values in an array along a given dimension.
The output type is `u32`.
\copydoc batch_detail_algo
\defgroup reduce_func_count_by_key countByKey
\ingroup reduce_mat
Count non-zero values in an array, according to an array of keys.
All non-zero values corresponding to each group of consecutive equal keys will
be counted. Keys can repeat; however, only consecutive key values will be
considered for each reduction. If a key value is repeated somewhere else in the
keys array it will be considered the start of a new reduction. There are two
outputs: the reduced set of consecutive keys and the corresponding final set of
reduced values.
An example demonstrating the reduction behavior can be seen in the following
snippet.
\snippet test/reduce.cpp ex_reduce_count_by_key
The keys' input type must be integer (s32 or u32).
The output type is `u32`.
The keys array must be 1-dimenstional matching the size of the reduced
dimension. An example of multi-dimensional reduce-by-key can be seen below:
\snippet test/reduce.cpp ex_reduce_count_by_key_dim
\defgroup scan_func_accum accum
\ingroup scan_mat
Evaluate the cumulative sum (inclusive) along a given dimension.
For a 1D array \f$X\f$, the inclusive cumulative sum calculates \f$x_i =
\sum_{p=0}^{i}x_p\f$ for every \f$x \in X\f$. Here is a simple example for the
1D case:
\snippet test/scan.cpp ex_accum_1D
For 2D arrays and higher dimensions, you can specify the dimension along which
the cumulative sum will be calculated. Thus, the formula above will be
calculated for all array slices along the specified dimension (in the 2D case
for example, this looks like \f$x_{i,j} = \sum_{p=0}^{j}x_{i,p}\f$ if the second
dimension (dim1) was chosen). If no dimension is specified, then the first
dimension (dim0) is used by default (only in the C++ API; the dimension is
required to be specified in the C API):
\snippet test/scan.cpp ex_accum_2D
The output array type may be different from the input array type. The following
table defines corresponding output types for each input type:
Input Type | Output Type
--------------------|---------------------
f32, f64, c32, c64 | same as input
s32, s64, u32, u64 | same as input
s16, s8 | s32
u16, u8, b8 | u32
\copydoc batch_detail_algo
\defgroup scan_func_scan scan
\ingroup scan_mat
Scan an array (generalized) over a given dimension.
Perform inclusive or exclusive scan using a given binary operation along a
given dimension.
Binary operations can be [add](\ref AF_BINARY_ADD), [mul](\ref AF_BINARY_MUL),
[min](\ref AF_BINARY_MIN), [max](\ref AF_BINARY_MAX) as defined by \ref
af_binary_op.
\defgroup scan_func_scanbykey scanByKey
\ingroup scan_mat
Scan an array (generalized) over a given dimension, according to an array of
keys.
Perform inclusive or exclusive scan using a given binary operation along a
given dimension using a key.
Binary operations can be [add](\ref AF_BINARY_ADD), [mul](\ref AF_BINARY_MUL),
[min](\ref AF_BINARY_MIN), [max](\ref AF_BINARY_MAX) as defined by \ref
af_binary_op.
\defgroup scan_func_where where
\ingroup scan_mat
Locate the indices of the non-zero values in an array.
Output type is `u32`.
The locations are provided by flattening the input into a linear array.
\defgroup calc_func_diff1 diff1
\ingroup calc_mat
Calculate the first order difference in an array over a given dimension.
\copydoc batch_detail_algo
\defgroup calc_func_diff2 diff2
\ingroup calc_mat
Calculate the second order difference in an array over a given dimension.
\copydoc batch_detail_algo
\defgroup sort_func_sort sort
\ingroup sort_mat
Sort an array over a given dimension.
\defgroup sort_func_sort_index sortIndex
\ingroup sort_mat
Sort an array over a given dimension and return the original indices.
Output type is `u32`.
\defgroup sort_func_sort_keys sortByKey
\ingroup sort_mat
Sort an array over a given dimension, according to an array of keys.
\defgroup set_func_unique setunique
\ingroup set_mat
Return the unique values in an array.
The input must be a one-dimensional array. Batching is not currently supported.
An example, unsorted:
\snippet test/set.cpp ex_set_unique_simple
The function can be sped up if it is known that the inputs are sorted.
An example, sorted (ascending):
\snippet test/set.cpp ex_set_unique_sorted
The inputs can be sorted in ascending or descending order.
An example, sorted (descending):
\snippet test/set.cpp ex_set_unique_desc
\defgroup set_func_union setunion
\ingroup set_mat
Evaluate the union of two arrays.
The inputs must be one-dimensional arrays. Batching is not currently supported.
An example:
\snippet test/set.cpp ex_set_union_simple
The function can be sped up if the input is sorted in increasing order and its
values are unique.
\snippet test/set.cpp ex_set_union
\defgroup set_func_intersect setintersect
\ingroup set_mat
Evaluate the intersection of two arrays.
The inputs must be one-dimensional arrays. Batching is not currently supported.
An example:
\snippet test/set.cpp ex_set_intersect_simple
The function can be sped up if the input is sorted in increasing order and its
values are unique.
\snippet test/set.cpp ex_set_intersect
@}
*/