forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm.h
More file actions
1559 lines (1219 loc) · 51.6 KB
/
Copy pathalgorithm.h
File metadata and controls
1559 lines (1219 loc) · 51.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
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************
* 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
********************************************************/
#pragma once
#include <af/defines.h>
#ifdef __cplusplus
namespace af
{
class array;
/**
C++ Interface to sum array elements over a given dimension.
\param[in] in input array
\param[in] dim dimension along which the summation occurs, -1 denotes
the first non-singleton dimension
\return sum
\ingroup reduce_func_sum
*/
AFAPI array sum(const array &in, const int dim = -1);
#if AF_API_VERSION >= 31
/**
C++ Interface to sum array elements over a given dimension, replacing
any NaNs with a specified value.
\param[in] in input array
\param[in] dim dimension along which the summation occurs
\param[in] nanval value that replaces NaNs
\return sum
\ingroup reduce_func_sum
*/
AFAPI array sum(const array &in, const int dim, const double nanval);
#endif
#if AF_API_VERSION >= 37
/**
C++ Interface to sum array elements over a given dimension, according to
an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out sum
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the summation occurs, -1
denotes the first non-singleton dimension
\ingroup reduce_func_sum_by_key
*/
AFAPI void sumByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim = -1);
/**
C++ Interface to sum array elements over a given dimension, replacing
any NaNs with a specified value, according to an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out sum
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the summation occurs
\param[in] nanval value that replaces NaNs
\ingroup reduce_func_sum_by_key
*/
AFAPI void sumByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim, const double nanval);
#endif
/**
C++ Interface to multiply array elements over a given dimension.
\param[in] in input array
\param[in] dim dimension along which the product occurs, -1 denotes the
first non-singleton dimension
\return product
\ingroup reduce_func_product
*/
AFAPI array product(const array &in, const int dim = -1);
#if AF_API_VERSION >= 31
/**
C++ Interface to multiply array elements over a given dimension,
replacing any NaNs with a specified value.
\param[in] in input array
\param[in] dim dimension along which the product occurs
\param[in] nanval value that replaces NaNs
\return product
\ingroup reduce_func_product
*/
AFAPI array product(const array &in, const int dim, const double nanval);
#endif
#if AF_API_VERSION >= 37
/**
C++ Interface to multiply array elements over a given dimension,
according to an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out product
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the product occurs, -1
denotes the first non-singleton dimension
\ingroup reduce_func_product_by_key
*/
AFAPI void productByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim = -1);
/**
C++ Interface to multiply array elements over a given dimension,
replacing any NaNs with a specified value, according to an array of
keys.
\param[out] keys_out reduced keys
\param[out] vals_out product
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the product occurs
\param[in] nanval value that replaces NaNs
\ingroup reduce_func_product_by_key
*/
AFAPI void productByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim, const double nanval);
#endif
/**
C++ Interface to return the minimum along a given dimension.
NaN values are ignored.
\param[in] in input array
\param[in] dim dimension along which the minimum is found, -1 denotes
the first non-singleton dimension
\return minimum
\ingroup reduce_func_min
*/
AFAPI array min(const array &in, const int dim = -1);
#if AF_API_VERSION >= 37
/**
C++ Interface to return the minimum along a given dimension, according
to an array of keys.
NaN values are ignored.
\param[out] keys_out reduced keys
\param[out] vals_out minimum
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the minimum is found, -1
denotes the first non-singleton dimension
\ingroup reduce_func_min_by_key
*/
AFAPI void minByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim = -1);
#endif
/**
C++ Interface to return the maximum along a given dimension.
NaN values are ignored.
\param[in] in input array
\param[in] dim dimension along which the maximum is found, -1 denotes
the first non-singleton dimension
\return maximum
\ingroup reduce_func_max
*/
AFAPI array max(const array &in, const int dim = -1);
#if AF_API_VERSION >= 37
/**
C++ Interface to return the maximum along a given dimension, according
to an array of keys.
NaN values are ignored.
\param[out] keys_out reduced keys
\param[out] vals_out maximum
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the maximum is found, -1
denotes the first non-singleton dimension
\ingroup reduce_func_max_by_key
*/
AFAPI void maxByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim = -1);
#endif
#if AF_API_VERSION >= 38
/**
C++ Interface to return the ragged maximum along a given dimension.
Input parameter `ragged_len` sets the number of elements to consider.
NaN values are ignored.
\param[out] val ragged maximum
\param[out] idx locations of the maximum ragged values
\param[in] in input array
\param[in] ragged_len array containing the number of elements to use
\param[in] dim dimension along which the maximum is found
\ingroup reduce_func_max
*/
AFAPI void max(array &val, array &idx, const array &in, const array &ragged_len, const int dim);
#endif
/**
C++ Interface to check if all values along a given dimension are true.
NaN values are ignored.
\param[in] in input array
\param[in] dim dimension along which the check occurs, -1 denotes the
first non-singleton dimension
\return array containing 1's if all true; 0's otherwise
\ingroup reduce_func_all_true
*/
AFAPI array allTrue(const array &in, const int dim = -1);
#if AF_API_VERSION >= 37
/**
C++ Interface to check if all values along a given dimension are true,
according to an array of keys.
NaN values are ignored.
\param[out] keys_out reduced keys
\param[out] vals_out array containing 1's if all true; 0's otherwise
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the check occurs
\ingroup reduce_func_alltrue_by_key
*/
AFAPI void allTrueByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim = -1);
#endif
/**
C++ Interface to check if any values along a given dimension are true.
NaN values are ignored.
\param[in] in input array
\param[in] dim dimension along which the check occurs, -1 denotes the
first non-singleton dimension
\return array containing 1's if any true; 0's otherwise
\ingroup reduce_func_any_true
*/
AFAPI array anyTrue(const array &in, const int dim = -1);
#if AF_API_VERSION >= 37
/**
C++ Interface to check if any values along a given dimension are true,
according to an array of keys.
NaN values are ignored.
\param[out] keys_out reduced keys
\param[out] vals_out array containing 1's if any true; 0's otherwise
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the check occurs
\ingroup reduce_func_anytrue_by_key
*/
AFAPI void anyTrueByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim = -1);
#endif
/**
C++ Interface to count non-zero values in an array along a given
dimension.
NaN values are treated as non-zero.
\param[in] in input array
\param[in] dim dimension along which the count occurs, -1 denotes the
first non-singleton dimension
\return count
\ingroup reduce_func_count
*/
AFAPI array count(const array &in, const int dim = -1);
#if AF_API_VERSION >= 37
/**
C++ Interface to count non-zero values in an array, according to an
array of keys.
NaN values are treated as non-zero.
\param[out] keys_out reduced keys
\param[out] vals_out count
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the count occurs, -1 denotes
the first non-singleton dimension
\ingroup reduce_func_count_by_key
*/
AFAPI void countByKey(array &keys_out, array &vals_out,
const array &keys, const array &vals,
const int dim = -1);
#endif
/**
C++ Interface to sum array elements over all dimensions.
Results in a single value as an output, which may be a single element
`af::array`.
\param[in] in input array
\return sum
\ingroup reduce_func_sum
*/
template<typename T> T sum(const array &in);
#if AF_API_VERSION >= 31
/**
C++ Interface to sum array elements over all dimensions, replacing any
NaNs with a specified value.
Results in a single value as an output, which may be a single element
`af::array`.
\param[in] in input array
\param[in] nanval value that replaces NaNs
\return sum
\ingroup reduce_func_sum
*/
template<typename T> T sum(const array &in, double nanval);
#endif
/**
C++ Interface to multiply array elements over the first non-singleton
dimension.
\param[in] in input array
\return product
\ingroup reduce_func_product
*/
template<typename T> T product(const array &in);
#if AF_API_VERSION >= 31
/**
C++ Interface to multiply array elements over the first non-singleton
dimension, replacing any NaNs with a specified value.
\param[in] in input array
\param[in] nanval value that replaces NaNs
\return product
\ingroup reduce_func_product
*/
template<typename T> T product(const array &in, double nanval);
#endif
/**
C++ Interface to return the minimum along the first non-singleton
dimension.
NaN values are ignored.
\param[in] in input array
\return minimum
\ingroup reduce_func_min
*/
template<typename T> T min(const array &in);
/**
C++ Interface to return the maximum along the first non-singleton
dimension.
NaN values are ignored.
\param[in] in input array
\return maximum
\ingroup reduce_func_max
*/
template<typename T> T max(const array &in);
/**
C++ Interface to check if all values along the first non-singleton
dimension are true.
NaN values are ignored.
\param[in] in input array
\return array containing 1's if all true; 0's otherwise
\ingroup reduce_func_all_true
*/
template<typename T> T allTrue(const array &in);
/**
C++ Interface to check if any values along the first non-singleton
dimension are true.
NaN values are ignored.
\param[in] in input array
\return array containing 1's if any true; 0's otherwise
\ingroup reduce_func_any_true
*/
template<typename T> T anyTrue(const array &in);
/**
C++ Interface to count non-zero values along the first non-singleton
dimension.
NaN values are treated as non-zero.
\param[in] in input array
\return count
\ingroup reduce_func_count
*/
template<typename T> T count(const array &in);
/**
C++ Interface to return the minimum and its location along a given
dimension.
NaN values are ignored.
\param[out] val minimum
\param[out] idx location
\param[in] in input array
\param[in] dim dimension along which the minimum is found, -1 denotes
the first non-singleton dimension
\ingroup reduce_func_min
*/
AFAPI void min(array &val, array &idx, const array &in, const int dim = -1);
/**
C++ Interface to return the maximum and its location along a given
dimension.
NaN values are ignored.
\param[out] val maximum
\param[out] idx location
\param[in] in input array
\param[in] dim dimension along which the maximum is found, -1 denotes
the first non-singleton dimension
\ingroup reduce_func_max
*/
AFAPI void max(array &val, array &idx, const array &in, const int dim = -1);
/**
C++ Interface to return the minimum and its location over all
dimensions.
NaN values are ignored.
Often used to return values directly to the host.
\param[out] val minimum
\param[out] idx location
\param[in] in input array
\ingroup reduce_func_min
*/
template<typename T> void min(T *val, unsigned *idx, const array &in);
/**
C++ Interface to return the maximum and its location over all
dimensions.
NaN values are ignored.
Often used to return values directly to the host.
\param[out] val maximum
\param[out] idx location
\param[in] in input array
\ingroup reduce_func_max
*/
template<typename T> void max(T *val, unsigned *idx, const array &in);
/**
C++ Interface to evaluate the cumulative sum (inclusive) along a given
dimension.
\param[in] in input array
\param[in] dim dimension along which the sum is accumulated, 0 denotes
the first non-singleton dimension
\return cumulative sum
\ingroup scan_func_accum
*/
AFAPI array accum(const array &in, const int dim = 0);
#if AF_API_VERSION >=34
/**
C++ Interface to scan an array (generalized) over a given dimension.
\param[in] in input array
\param[in] dim dimension along which the scan occurs, 0
denotes the first non-singleton dimension
\param[in] op type of binary operation used
\param[in] inclusive_scan flag specifying whether the scan is inclusive
\return scan
\ingroup scan_func_scan
*/
AFAPI array scan(const array &in, const int dim = 0,
binaryOp op = AF_BINARY_ADD, bool inclusive_scan = true);
/**
C++ Interface to scan an array (generalized) over a given dimension,
according to an array of keys.
\param[in] key keys array
\param[in] in input array
\param[in] dim dimension along which the scan occurs, 0
denotes the first non-singleton dimension
\param[in] op type of binary operation used
\param[in] inclusive_scan flag specifying whether the scan is inclusive
\return scan
\ingroup scan_func_scanbykey
*/
AFAPI array scanByKey(const array &key, const array& in, const int dim = 0,
binaryOp op = AF_BINARY_ADD, bool inclusive_scan = true);
#endif
/**
C++ Interface to locate the indices of the non-zero values in an array.
\param[in] in input array
\return linear indices where `in` is non-zero
\ingroup scan_func_where
*/
AFAPI array where(const array &in);
/**
C++ Interface to calculate the first order difference in an array over a
given dimension.
\param[in] in input array
\param[in] dim dimension along which the difference occurs, 0
denotes the first non-singleton dimension
\return first order numerical difference
\ingroup calc_func_diff1
*/
AFAPI array diff1(const array &in, const int dim = 0);
/**
C++ Interface to calculate the second order difference in an array over
a given dimension.
\param[in] in input array
\param[in] dim dimension along which the difference occurs, 0
denotes the first non-singleton dimension
\return second order numerical difference
\ingroup calc_func_diff2
*/
AFAPI array diff2(const array &in, const int dim = 0);
/**
C++ Interface to sort an array over a given dimension.
\param[in] in input array
\param[in] dim dimension along which the sort occurs, 0 denotes
the first non-singleton dimension
\param[in] isAscending specifies the sorting order
\return sorted output
\ingroup sort_func_sort
*/
AFAPI array sort(const array &in, const unsigned dim = 0,
const bool isAscending = true);
/**
C++ Interface to sort an array over a given dimension and to return the
original indices.
\param[out] out sorted output
\param[out] indices indices from the input
\param[in] in input array
\param[in] dim dimension along which the sort occurs, 0 denotes
the first non-singleton dimension
\param[in] isAscending specifies the sorting order
\ingroup sort_func_sort_index
*/
AFAPI void sort(array &out, array &indices, const array &in, const unsigned dim = 0,
const bool isAscending = true);
/**
C++ Interface to sort an array over a given dimension, according to an
array of keys.
\param[out] out_keys sorted keys
\param[out] out_values sorted output
\param[in] keys keys array
\param[in] values input array
\param[in] dim dimension along which the sort occurs, 0 denotes
the first non-singleton dimension
\param[in] isAscending specifies the sorting order
\ingroup sort_func_sort_keys
*/
AFAPI void sort(array &out_keys, array &out_values, const array &keys,
const array &values, const unsigned dim = 0,
const bool isAscending = true);
/**
C++ Interface to return the unique values in an array.
\param[in] in input array
\param[in] is_sorted if true, skip the sorting steps internally
\return unique values
\ingroup set_func_unique
*/
AFAPI array setUnique(const array &in, const bool is_sorted=false);
/**
C++ Interface to evaluate the union of two arrays.
\param[in] first input array
\param[in] second input array
\param[in] is_unique if true, skip calling setUnique internally
\return union, values in increasing order
\ingroup set_func_union
*/
AFAPI array setUnion(const array &first, const array &second,
const bool is_unique=false);
/**
C++ Interface to evaluate the intersection of two arrays.
\param[in] first input array
\param[in] second input array
\param[in] is_unique if true, skip calling setUnique internally
\return intersection, values in increasing order
\ingroup set_func_intersect
*/
AFAPI array setIntersect(const array &first, const array &second,
const bool is_unique=false);
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
C Interface to sum array elements over a given dimension.
\param[out] out sum
\param[in] in input array
\param[in] dim dimension along which the summation occurs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_sum
*/
AFAPI af_err af_sum(af_array *out, const af_array in, const int dim);
#if AF_API_VERSION >= 39
/**
C Interface to sum array elements over all dimensions.
Results in a single element `af::array`.
\param[out] out sum
\param[in] in input array
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_sum
*/
AFAPI af_err af_sum_all_array(af_array *out, const af_array in);
#endif
#if AF_API_VERSION >= 31
/**
C Interface to sum array elements over a given dimension, replacing any
NaNs with a specified value.
\param[out] out sum
\param[in] in input array
\param[in] dim dimension along which the summation occurs
\param[in] nanval value that replaces NaNs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_sum
*/
AFAPI af_err af_sum_nan(af_array *out, const af_array in,
const int dim, const double nanval);
#endif
#if AF_API_VERSION >= 39
/**
C Interface to sum array elements over all dimensions, replacing any
NaNs with a specified value.
Results in a single element `af::array`.
\param[out] out sum
\param[in] in input array
\param[in] nanval value that replaces NaNs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_sum
*/
AFAPI af_err af_sum_nan_all_array(af_array *out, const af_array in, const double nanval);
#endif
#if AF_API_VERSION >= 37
/**
C Interface to sum array elements over a given dimension, according to
an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out sum
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the summation occurs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_sum_by_key
*/
AFAPI af_err af_sum_by_key(af_array *keys_out, af_array *vals_out,
const af_array keys, const af_array vals, const int dim);
/**
C Interface to sum array elements over a given dimension, replacing any
NaNs with a specified value, according to an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out sum
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the summation occurs
\param[in] nanval value that replaces NaNs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_sum_by_key
*/
AFAPI af_err af_sum_by_key_nan(af_array *keys_out, af_array *vals_out,
const af_array keys, const af_array vals,
const int dim, const double nanval);
#endif
/**
C Interface to multiply array elements over a given dimension.
\param[out] out product
\param[in] in input array
\param[in] dim dimension along which the product occurs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_product
*/
AFAPI af_err af_product(af_array *out, const af_array in, const int dim);
#if AF_API_VERSION >= 39
/**
C Interface to multiply array elements over all dimensions.
Results in a single element `af::array`.
\param[out] out product
\param[in] in input array
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_product
*/
AFAPI af_err af_product_all_array(af_array *out, const af_array in);
#endif
#if AF_API_VERSION >= 31
/**
C Interface to multiply array elements over a given dimension, replacing
any NaNs with a specified value.
\param[out] out product
\param[in] in input array
\param[in] dim dimension along with the product occurs
\param[in] nanval value that replaces NaNs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_product
*/
AFAPI af_err af_product_nan(af_array *out, const af_array in, const int dim, const double nanval);
#endif
#if AF_API_VERSION >= 39
/**
C Interface to multiply array elements over all dimensions, replacing
any NaNs with a specified value.
\param[out] out product
\param[in] in input array
\param[in] nanval value that replaces NaNs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_product
*/
AFAPI af_err af_product_nan_all_array(af_array *out, const af_array in, const double nanval);
#endif
#if AF_API_VERSION >= 37
/**
C Interface to multiply array elements over a given dimension, according
to an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out product
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the product occurs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_product_by_key
*/
AFAPI af_err af_product_by_key(af_array *keys_out, af_array *vals_out,
const af_array keys, const af_array vals, const int dim);
/**
C Interface to multiply array elements over a given dimension, replacing
any NaNs with a specified value, according to an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out product
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the product occurs
\param[in] nanval value that replaces NaNs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_product_by_key
*/
AFAPI af_err af_product_by_key_nan(af_array *keys_out, af_array *vals_out,
const af_array keys, const af_array vals,
const int dim, const double nanval);
#endif
/**
C Interface to return the minimum along a given dimension.
\param[out] out minimum
\param[in] in input array
\param[in] dim dimension along which the minimum is found
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_min
*/
AFAPI af_err af_min(af_array *out, const af_array in, const int dim);
#if AF_API_VERSION >= 37
/**
C Interface to return the minimum along a given dimension, according to
an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out minimum
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the minimum is found
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_min_by_key
*/
AFAPI af_err af_min_by_key(af_array *keys_out, af_array *vals_out,
const af_array keys, const af_array vals,
const int dim);
#endif
/**
C Interface to return the maximum along a given dimension.
\param[out] out maximum
\param[in] in input array
\param[in] dim dimension along which the maximum is found
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_max
*/
AFAPI af_err af_max(af_array *out, const af_array in, const int dim);
#if AF_API_VERSION >= 37
/**
C Interface to return the maximum along a given dimension, according to
an array of keys.
\param[out] keys_out reduced keys
\param[out] vals_out maximum
\param[in] keys keys array
\param[in] vals input array
\param[in] dim dimension along which the maximum is found
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_max_by_key
*/
AFAPI af_err af_max_by_key(af_array *keys_out, af_array *vals_out,
const af_array keys, const af_array vals,
const int dim);
#endif
#if AF_API_VERSION >= 38
/**
C Interface to return the ragged maximum over a given dimension.
Input parameter `ragged_len` sets the number of elements to consider.
NaN values are ignored.
\param[out] val ragged maximum
\param[out] idx locations of the maximum ragged values
\param[in] in input array
\param[in] ragged_len array containing the number of elements to use
\param[in] dim dimension along which the maximum is found
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_max
*/
AFAPI af_err af_max_ragged(af_array *val, af_array *idx, const af_array in, const af_array ragged_len, const int dim);
#endif
/**
C Interface to check if all values along a given dimension are true.
NaN values are ignored.
\param[out] out array containing 1's if all true; 0's otherwise
\param[in] in input array
\param[in] dim dimention along which the check occurs
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup reduce_func_all_true
*/
AFAPI af_err af_all_true(af_array *out, const af_array in, const int dim);