algorithm.h (2022-02-24 14:07:56 -0500, (build 8c2561559))
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#pragma once
11#include <af/defines.h>
12
13#ifdef __cplusplus
14namespace af
15{
16 class array;
17
29 AFAPI array sum(const array &in, const int dim = -1);
30
31#if AF_API_VERSION >= 31
43 AFAPI array sum(const array &in, const int dim, const double nanval);
44#endif
45
46#if AF_API_VERSION >= 37
61 AFAPI void sumByKey(array &keys_out, array &vals_out,
62 const array &keys, const array &vals,
63 const int dim=-1);
64
78 AFAPI void sumByKey(array &keys_out, array &vals_out,
79 const array &keys, const array &vals,
80 const int dim, const double nanval);
81#endif
82
94 AFAPI array product(const array &in, const int dim = -1);
95
96#if AF_API_VERSION >= 31
108 AFAPI array product(const array &in, const int dim, const double nanval);
109#endif
110
111#if AF_API_VERSION >= 37
126 AFAPI void productByKey(array &keys_out, array &vals_out,
127 const array &keys, const array &vals,
128 const int dim = -1);
129
146 AFAPI void productByKey(array &keys_out, array &vals_out,
147 const array &keys, const array &vals,
148 const int dim, const double nanval);
149#endif
150
163 AFAPI array min(const array &in, const int dim = -1);
164
165#if AF_API_VERSION >= 37
180 AFAPI void minByKey(array &keys_out, array &vals_out,
181 const array &keys, const array &vals,
182 const int dim = -1);
183#endif
184
197 AFAPI array max(const array &in, const int dim = -1);
198
199#if AF_API_VERSION >= 37
214 AFAPI void maxByKey(array &keys_out, array &vals_out,
215 const array &keys, const array &vals,
216 const int dim = -1);
217#endif
218
219#if AF_API_VERSION >= 38
234 AFAPI void max(array &val, array &idx, const array &in, const array &ragged_len, const int dim);
235#endif
236
249 AFAPI array allTrue(const array &in, const int dim = -1);
250
251#if AF_API_VERSION >= 37
266 AFAPI void allTrueByKey(array &keys_out, array &vals_out,
267 const array &keys, const array &vals,
268 const int dim = -1);
269#endif
270
283 AFAPI array anyTrue(const array &in, const int dim = -1);
284
285#if AF_API_VERSION >= 37
300 AFAPI void anyTrueByKey(array &keys_out, array &vals_out,
301 const array &keys, const array &vals,
302 const int dim = -1);
303#endif
304
317 AFAPI array count(const array &in, const int dim = -1);
318
319#if AF_API_VERSION >= 37
334 AFAPI void countByKey(array &keys_out, array &vals_out,
335 const array &keys, const array &vals,
336 const int dim = -1);
337#endif
338
347 template<typename T> T sum(const array &in);
348
349#if AF_API_VERSION >= 31
360 template<typename T> T sum(const array &in, double nanval);
361#endif
362
371 template<typename T> T product(const array &in);
372
373#if AF_API_VERSION >= 31
384 template<typename T> T product(const array &in, double nanval);
385#endif
386
387
398 template<typename T> T min(const array &in);
399
410 template<typename T> T max(const array &in);
411
422 template<typename T> T allTrue(const array &in);
423
434 template<typename T> T anyTrue(const array &in);
435
446 template<typename T> T count(const array &in);
447
462 AFAPI void min(array &val, array &idx, const array &in, const int dim = -1);
463
478 AFAPI void max(array &val, array &idx, const array &in, const int dim = -1);
479
491 template<typename T> void min(T *val, unsigned *idx, const array &in);
492
504 template<typename T> void max(T *val, unsigned *idx, const array &in);
505
515 AFAPI array accum(const array &in, const int dim = 0);
516
517#if AF_API_VERSION >=34
529 AFAPI array scan(const array &in, const int dim = 0,
530 binaryOp op = AF_BINARY_ADD, bool inclusive_scan = true);
531
544 AFAPI array scanByKey(const array &key, const array& in, const int dim = 0,
545 binaryOp op = AF_BINARY_ADD, bool inclusive_scan = true);
546#endif
547
556 AFAPI array where(const array &in);
557
567 AFAPI array diff1(const array &in, const int dim = 0);
568
578 AFAPI array diff2(const array &in, const int dim = 0);
579
590 AFAPI array sort(const array &in, const unsigned dim = 0,
591 const bool isAscending = true);
592
604 AFAPI void sort(array &out, array &indices, const array &in, const unsigned dim = 0,
605 const bool isAscending = true);
618 AFAPI void sort(array &out_keys, array &out_values, const array &keys,
619 const array &values, const unsigned dim = 0,
620 const bool isAscending = true);
621
631 AFAPI array setUnique(const array &in, const bool is_sorted=false);
632
643 AFAPI array setUnion(const array &first, const array &second,
644 const bool is_unique=false);
645
656 AFAPI array setIntersect(const array &first, const array &second,
657 const bool is_unique=false);
658}
659#endif
660
661#ifdef __cplusplus
662extern "C" {
663#endif
664
675 AFAPI af_err af_sum(af_array *out, const af_array in, const int dim);
676
677#if AF_API_VERSION >= 31
690 const int dim, const double nanval);
691#endif
692
693#if AF_API_VERSION >= 37
707 const af_array keys, const af_array vals, const int dim);
708
728 const af_array keys, const af_array vals,
729 const int dim, const double nanval);
730#endif
731
742 AFAPI af_err af_product(af_array *out, const af_array in, const int dim);
743
744#if AF_API_VERSION >= 31
757 AFAPI af_err af_product_nan(af_array *out, const af_array in, const int dim, const double nanval);
758#endif
759
760#if AF_API_VERSION >= 37
774 const af_array keys, const af_array vals, const int dim);
775
793 const af_array keys, const af_array vals,
794 const int dim, const double nanval);
795#endif
796
807 AFAPI af_err af_min(af_array *out, const af_array in, const int dim);
808
809#if AF_API_VERSION >= 37
823 const af_array keys, const af_array vals,
824 const int dim);
825#endif
826
837 AFAPI af_err af_max(af_array *out, const af_array in, const int dim);
838
839#if AF_API_VERSION >= 37
855 const af_array keys, const af_array vals,
856 const int dim);
857#endif
858
859#if AF_API_VERSION >= 38
875 AFAPI af_err af_max_ragged(af_array *val, af_array *idx, const af_array in, const af_array ragged_len, const int dim);
876#endif
877
888 AFAPI af_err af_all_true(af_array *out, const af_array in, const int dim);
889
890#if AF_API_VERSION >= 37
905 const af_array keys, const af_array vals,
906 const int dim);
907#endif
908
919 AFAPI af_err af_any_true(af_array *out, const af_array in, const int dim);
920
921#if AF_API_VERSION >= 37
936 const af_array keys, const af_array vals,
937 const int dim);
938#endif
939
950 AFAPI af_err af_count(af_array *out, const af_array in, const int dim);
951
952#if AF_API_VERSION >= 37
967 const af_array keys, const af_array vals,
968 const int dim);
969#endif
970
985 AFAPI af_err af_sum_all(double *real, double *imag, const af_array in);
986
987#if AF_API_VERSION >= 31
1004 const af_array in, const double nanval);
1005#endif
1006
1019 AFAPI af_err af_product_all(double *real, double *imag, const af_array in);
1020
1021#if AF_API_VERSION >= 31
1038 const af_array in, const double nanval);
1039#endif
1040
1053 AFAPI af_err af_min_all(double *real, double *imag, const af_array in);
1054
1067 AFAPI af_err af_max_all(double *real, double *imag, const af_array in);
1068
1081 AFAPI af_err af_all_true_all(double *real, double *imag, const af_array in);
1082
1095 AFAPI af_err af_any_true_all(double *real, double *imag, const af_array in);
1096
1109 AFAPI af_err af_count_all(double *real, double *imag, const af_array in);
1110
1123 const int dim);
1124
1137 const int dim);
1138
1152 AFAPI af_err af_imin_all(double *real, double *imag, unsigned *idx,
1153 const af_array in);
1154
1168 AFAPI af_err af_imax_all(double *real, double *imag, unsigned *idx, const af_array in);
1169
1180 AFAPI af_err af_accum(af_array *out, const af_array in, const int dim);
1181
1182#if AF_API_VERSION >=34
1195 AFAPI af_err af_scan(af_array *out, const af_array in, const int dim,
1196 af_binary_op op, bool inclusive_scan);
1197
1212 const af_array in, const int dim,
1213 af_binary_op op, bool inclusive_scan);
1214
1215#endif
1216
1227
1238 AFAPI af_err af_diff1(af_array *out, const af_array in, const int dim);
1239
1250 AFAPI af_err af_diff2(af_array *out, const af_array in, const int dim);
1251
1263 AFAPI af_err af_sort(af_array *out, const af_array in, const unsigned dim,
1264 const bool isAscending);
1265
1279 const unsigned dim, const bool isAscending);
1294 const af_array keys, const af_array values,
1295 const unsigned dim, const bool isAscending);
1296
1307 AFAPI af_err af_set_unique(af_array *out, const af_array in, const bool is_sorted);
1308
1321 const af_array second, const bool is_unique);
1322
1335 const af_array second, const bool is_unique);
1336
1337#ifdef __cplusplus
1338}
1339#endif
AFAPI af_err af_all_true_by_key(af_array *keys_out, af_array *vals_out, const af_array keys, const af_array vals, const int dim)
C Interface for checking all true values in an array according to key.
A multi dimensional data container.
Definition: array.h:37
af_binary_op
Definition: defines.h:429
@ AF_BINARY_ADD
Definition: defines.h:430
af_err
Definition: defines.h:71
void * af_array
Definition: defines.h:240
#define AFAPI
Definition: defines.h:38
AFAPI array imag(const array &in)
C++ Interface for getting imaginary part from complex array.
AFAPI array real(const array &in)
C++ Interface for getting real part from complex array.
AFAPI array diff1(const array &in, const int dim=0)
C++ Interface for calculating first order differences in an array.
AFAPI af_err af_diff1(af_array *out, const af_array in, const int dim)
C Interface for calculating first order differences in an array.
AFAPI array diff2(const array &in, const int dim=0)
C++ Interface for calculating second order differences in an array.
AFAPI af_err af_diff2(af_array *out, const af_array in, const int dim)
C Interface for calculating second order differences in an array.
AFAPI af_err af_all_true(af_array *out, const af_array in, const int dim)
C Interface for checking all true values in an array.
AFAPI af_err af_all_true_all(double *real, double *imag, const af_array in)
C Interface for checking if all values in an array are true.
AFAPI array allTrue(const array &in, const int dim=-1)
C++ Interface for checking all true values in an array.
AFAPI af_err af_any_true_all(double *real, double *imag, const af_array in)
C Interface for checking if any values in an array are true.
AFAPI af_err af_any_true(af_array *out, const af_array in, const int dim)
C Interface for checking any true values in an array.
AFAPI array anyTrue(const array &in, const int dim=-1)
C++ Interface for checking any true values in an array.
AFAPI af_err af_any_true_by_key(af_array *keys_out, af_array *vals_out, const af_array keys, const af_array vals, const int dim)
C Interface for checking any true values in an array according to key.
AFAPI void anyTrueByKey(array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1)
C++ Interface for checking any true values in an array according to a key.
AFAPI af_err af_count_by_key(af_array *keys_out, af_array *vals_out, const af_array keys, const af_array vals, const int dim)
C Interface for counting non-zero values in an array according to key.
AFAPI void countByKey(array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1)
C++ Interface for counting non-zero values in an array according to a key.
AFAPI af_err af_count_all(double *real, double *imag, const af_array in)
C Interface for counting total number of non-zero values in an array.
AFAPI array count(const array &in, const int dim=-1)
C++ Interface for counting non-zero values in an array.
AFAPI af_err af_count(af_array *out, const af_array in, const int dim)
C Interface for counting non-zero values in an array.
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)
C Interface for maximum values in an array according to key.
AFAPI void maxByKey(array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1)
C++ Interface for maximum values in an array according to a key.
AFAPI af_err af_max(af_array *out, const af_array in, const int dim)
C Interface for maximum values in an array.
AFAPI array max(const array &in, const int dim=-1)
C++ Interface for maximum values in an array.
AFAPI af_err af_max_ragged(af_array *val, af_array *idx, const af_array in, const af_array ragged_len, const int dim)
C Interface for finding ragged max values in an array Uses an additional input array to determine the...
AFAPI af_err af_max_all(double *real, double *imag, const af_array in)
C Interface for getting maximum value of an array.
AFAPI af_err af_imax_all(double *real, double *imag, unsigned *idx, const af_array in)
C Interface for getting maximum value and it's location from the entire array.
AFAPI af_err af_imax(af_array *out, af_array *idx, const af_array in, const int dim)
C Interface for getting maximum values and their locations in an array.
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)
C Interface for minimum values in an array according to key.
AFAPI void minByKey(array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1)
C++ Interface for minimum values in an array according to a key.
AFAPI af_err af_min(af_array *out, const af_array in, const int dim)
C Interface for minimum values in an array.
AFAPI array min(const array &in, const int dim=-1)
C++ Interface for minimum values in an array.
AFAPI af_err af_imin(af_array *out, af_array *idx, const af_array in, const int dim)
C Interface for getting minimum values and their locations in an array.
AFAPI af_err af_min_all(double *real, double *imag, const af_array in)
C Interface for getting minimum value of an array.
AFAPI af_err af_imin_all(double *real, double *imag, unsigned *idx, const af_array in)
C Interface for getting minimum value and its location from the entire array.
AFAPI void productByKey(array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1)
C++ Interface for product of elements in an array according to a 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 for product of elements in an array according to 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)
C Interface for product of elements in an array according to key while replacing nans.
AFAPI af_err af_product_nan(af_array *out, const af_array in, const int dim, const double nanval)
C Interface for product of elements in an array while replacing nans.
AFAPI af_err af_product(af_array *out, const af_array in, const int dim)
C Interface for product of elements in an array.
AFAPI array product(const array &in, const int dim=-1)
C++ Interface for product of elements in an array.
AFAPI af_err af_product_nan_all(double *real, double *imag, const af_array in, const double nanval)
C Interface for product of all elements in an array while replacing nans.
AFAPI af_err af_product_all(double *real, double *imag, const af_array in)
C Interface for product of all elements in an array.
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 for sum of elements in an array according to key.
AFAPI void sumByKey(array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1)
C++ Interface for sum of elements along given dimension 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)
C Interface for sum of elements in an array according to key while replacing nans.
AFAPI af_err af_sum_nan(af_array *out, const af_array in, const int dim, const double nanval)
C Interface for sum of elements in an array while replacing nans.
AFAPI af_err af_sum_nan_all(double *real, double *imag, const af_array in, const double nanval)
C Interface for sum of all elements in an array while replacing nans.
AFAPI array sum(const array &in, const int dim=-1)
C++ Interface for sum of elements in an array.
AFAPI af_err af_sum_all(double *real, double *imag, const af_array in)
C Interface for sum of all elements in an array.
AFAPI af_err af_sum(af_array *out, const af_array in, const int dim)
C Interface for sum of elements in an array.
AFAPI af_err af_accum(af_array *out, const af_array in, const int dim)
C Interface for computing the cumulative sum (inclusive) of an array.
AFAPI array accum(const array &in, const int dim=0)
C++ Interface for computing the cumulative sum (inclusive) of an array.
AFAPI af_err af_scan(af_array *out, const af_array in, const int dim, af_binary_op op, bool inclusive_scan)
C Interface generalized scan of an array.
AFAPI array scan(const array &in, const int dim=0, binaryOp op=AF_BINARY_ADD, bool inclusive_scan=true)
C++ Interface generalized scan of an array.
AFAPI array scanByKey(const array &key, const array &in, const int dim=0, binaryOp op=AF_BINARY_ADD, bool inclusive_scan=true)
C++ Interface generalized scan by key of an array.
AFAPI af_err af_scan_by_key(af_array *out, const af_array key, const af_array in, const int dim, af_binary_op op, bool inclusive_scan)
C Interface generalized scan by key of an array.
AFAPI array where(const array &in)
C++ Interface for finding the locations of non-zero values in an array.
AFAPI af_err af_where(af_array *idx, const af_array in)
C Interface for finding the locations of non-zero values in an array.
AFAPI af_err af_set_intersect(af_array *out, const af_array first, const af_array second, const bool is_unique)
C Interface for finding the intersection of two arrays.
AFAPI array setIntersect(const array &first, const array &second, const bool is_unique=false)
C++ Interface for finding the intersection of two arrays.
AFAPI array setUnion(const array &first, const array &second, const bool is_unique=false)
C++ Interface for finding the union of two arrays.
AFAPI af_err af_set_union(af_array *out, const af_array first, const af_array second, const bool is_unique)
C Interface for finding the union of two arrays.
AFAPI af_err af_set_unique(af_array *out, const af_array in, const bool is_sorted)
C Interface for getting unique values.
AFAPI array setUnique(const array &in, const bool is_sorted=false)
C++ Interface for getting unique values.
AFAPI af_err af_sort_index(af_array *out, af_array *indices, const af_array in, const unsigned dim, const bool isAscending)
C Interface for sorting an array and getting original indices.
AFAPI af_err af_sort_by_key(af_array *out_keys, af_array *out_values, const af_array keys, const af_array values, const unsigned dim, const bool isAscending)
C Interface for sorting an array based on keys.
AFAPI array sort(const array &in, const unsigned dim=0, const bool isAscending=true)
C++ Interface for sorting an array.
AFAPI af_err af_sort(af_array *out, const af_array in, const unsigned dim, const bool isAscending)
C Interface for sorting an array.
Definition: algorithm.h:15
AFAPI void allTrueByKey(array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1)
C++ Interface for checking all true values in an array according to a key.