algorithm.h (2020-07-07 17:43:34 +0530, (build 218dd2c99))
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  * https://arrayfire.com/licenses/BSD-3-Clause
8  ********************************************************/
9 
10 #pragma once
11 #include <af/defines.h>
12 
13 #ifdef __cplusplus
14 namespace af
15 {
16  class array;
17 
29  AFAPI array sum(const array &in, const int dim = -1);
30 
31 #if AF_API_VERSION >= 31
32 
43  AFAPI array sum(const array &in, const int dim, const double nanval);
44 #endif
45 
46 #if AF_API_VERSION >= 37
47 
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
97 
108  AFAPI array product(const array &in, const int dim, const double nanval);
109 #endif
110 
111 #if AF_API_VERSION >= 37
112 
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
166 
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
200 
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 
231  AFAPI array allTrue(const array &in, const int dim = -1);
232 
233 #if AF_API_VERSION >= 37
234 
248  AFAPI void allTrueByKey(array &keys_out, array &vals_out,
249  const array &keys, const array &vals,
250  const int dim = -1);
251 #endif
252 
265  AFAPI array anyTrue(const array &in, const int dim = -1);
266 
267 #if AF_API_VERSION >= 37
268 
282  AFAPI void anyTrueByKey(array &keys_out, array &vals_out,
283  const array &keys, const array &vals,
284  const int dim = -1);
285 #endif
286 
299  AFAPI array count(const array &in, const int dim = -1);
300 
301 #if AF_API_VERSION >= 37
302 
316  AFAPI void countByKey(array &keys_out, array &vals_out,
317  const array &keys, const array &vals,
318  const int dim = -1);
319 #endif
320 
329  template<typename T> T sum(const array &in);
330 
331 #if AF_API_VERSION >= 31
332 
342  template<typename T> T sum(const array &in, double nanval);
343 #endif
344 
353  template<typename T> T product(const array &in);
354 
355 #if AF_API_VERSION >= 31
356 
366  template<typename T> T product(const array &in, double nanval);
367 #endif
368 
369 
380  template<typename T> T min(const array &in);
381 
392  template<typename T> T max(const array &in);
393 
404  template<typename T> T allTrue(const array &in);
405 
416  template<typename T> T anyTrue(const array &in);
417 
428  template<typename T> T count(const array &in);
429 
444  AFAPI void min(array &val, array &idx, const array &in, const int dim = -1);
445 
460  AFAPI void max(array &val, array &idx, const array &in, const int dim = -1);
461 
473  template<typename T> void min(T *val, unsigned *idx, const array &in);
474 
486  template<typename T> void max(T *val, unsigned *idx, const array &in);
487 
497  AFAPI array accum(const array &in, const int dim = 0);
498 
499 #if AF_API_VERSION >=34
500 
511  AFAPI array scan(const array &in, const int dim = 0,
512  binaryOp op = AF_BINARY_ADD, bool inclusive_scan = true);
513 
526  AFAPI array scanByKey(const array &key, const array& in, const int dim = 0,
527  binaryOp op = AF_BINARY_ADD, bool inclusive_scan = true);
528 #endif
529 
538  AFAPI array where(const array &in);
539 
549  AFAPI array diff1(const array &in, const int dim = 0);
550 
560  AFAPI array diff2(const array &in, const int dim = 0);
561 
572  AFAPI array sort(const array &in, const unsigned dim = 0,
573  const bool isAscending = true);
574 
586  AFAPI void sort(array &out, array &indices, const array &in, const unsigned dim = 0,
587  const bool isAscending = true);
600  AFAPI void sort(array &out_keys, array &out_values, const array &keys,
601  const array &values, const unsigned dim = 0,
602  const bool isAscending = true);
603 
613  AFAPI array setUnique(const array &in, const bool is_sorted=false);
614 
625  AFAPI array setUnion(const array &first, const array &second,
626  const bool is_unique=false);
627 
638  AFAPI array setIntersect(const array &first, const array &second,
639  const bool is_unique=false);
640 }
641 #endif
642 
643 #ifdef __cplusplus
644 extern "C" {
645 #endif
646 
657  AFAPI af_err af_sum(af_array *out, const af_array in, const int dim);
658 
659 #if AF_API_VERSION >= 31
660 
672  const int dim, const double nanval);
673 #endif
674 
675 #if AF_API_VERSION >= 37
676 
689  const af_array keys, const af_array vals, const int dim);
690 
710  const af_array keys, const af_array vals,
711  const int dim, const double nanval);
712 #endif
713 
724  AFAPI af_err af_product(af_array *out, const af_array in, const int dim);
725 
726 #if AF_API_VERSION >= 31
727 
739  AFAPI af_err af_product_nan(af_array *out, const af_array in, const int dim, const double nanval);
740 #endif
741 
742 #if AF_API_VERSION >= 37
743 
756  const af_array keys, const af_array vals, const int dim);
757 
775  const af_array keys, const af_array vals,
776  const int dim, const double nanval);
777 #endif
778 
789  AFAPI af_err af_min(af_array *out, const af_array in, const int dim);
790 
791 #if AF_API_VERSION >= 37
792 
805  const af_array keys, const af_array vals,
806  const int dim);
807 #endif
808 
819  AFAPI af_err af_max(af_array *out, const af_array in, const int dim);
820 
821 #if AF_API_VERSION >= 37
822 
837  const af_array keys, const af_array vals,
838  const int dim);
839 #endif
840 
851  AFAPI af_err af_all_true(af_array *out, const af_array in, const int dim);
852 
853 #if AF_API_VERSION >= 37
854 
868  const af_array keys, const af_array vals,
869  const int dim);
870 #endif
871 
882  AFAPI af_err af_any_true(af_array *out, const af_array in, const int dim);
883 
884 #if AF_API_VERSION >= 37
885 
899  const af_array keys, const af_array vals,
900  const int dim);
901 #endif
902 
913  AFAPI af_err af_count(af_array *out, const af_array in, const int dim);
914 
915 #if AF_API_VERSION >= 37
916 
930  const af_array keys, const af_array vals,
931  const int dim);
932 #endif
933 
948  AFAPI af_err af_sum_all(double *real, double *imag, const af_array in);
949 
950 #if AF_API_VERSION >= 31
951 
966  AFAPI af_err af_sum_nan_all(double *real, double *imag,
967  const af_array in, const double nanval);
968 #endif
969 
982  AFAPI af_err af_product_all(double *real, double *imag, const af_array in);
983 
984 #if AF_API_VERSION >= 31
985 
1001  const af_array in, const double nanval);
1002 #endif
1003 
1016  AFAPI af_err af_min_all(double *real, double *imag, const af_array in);
1017 
1030  AFAPI af_err af_max_all(double *real, double *imag, const af_array in);
1031 
1044  AFAPI af_err af_all_true_all(double *real, double *imag, const af_array in);
1045 
1058  AFAPI af_err af_any_true_all(double *real, double *imag, const af_array in);
1059 
1072  AFAPI af_err af_count_all(double *real, double *imag, const af_array in);
1073 
1086  const int dim);
1087 
1100  const int dim);
1101 
1115  AFAPI af_err af_imin_all(double *real, double *imag, unsigned *idx,
1116  const af_array in);
1117 
1131  AFAPI af_err af_imax_all(double *real, double *imag, unsigned *idx, const af_array in);
1132 
1143  AFAPI af_err af_accum(af_array *out, const af_array in, const int dim);
1144 
1145 #if AF_API_VERSION >=34
1146 
1158  AFAPI af_err af_scan(af_array *out, const af_array in, const int dim,
1159  af_binary_op op, bool inclusive_scan);
1160 
1175  const af_array in, const int dim,
1176  af_binary_op op, bool inclusive_scan);
1177 
1178 #endif
1179 
1190 
1201  AFAPI af_err af_diff1(af_array *out, const af_array in, const int dim);
1202 
1213  AFAPI af_err af_diff2(af_array *out, const af_array in, const int dim);
1214 
1226  AFAPI af_err af_sort(af_array *out, const af_array in, const unsigned dim,
1227  const bool isAscending);
1228 
1242  const unsigned dim, const bool isAscending);
1256  AFAPI af_err af_sort_by_key(af_array *out_keys, af_array *out_values,
1257  const af_array keys, const af_array values,
1258  const unsigned dim, const bool isAscending);
1259 
1270  AFAPI af_err af_set_unique(af_array *out, const af_array in, const bool is_sorted);
1271 
1284  const af_array second, const bool is_unique);
1285 
1298  const af_array second, const bool is_unique);
1299 
1300 #ifdef __cplusplus
1301 }
1302 #endif
af::accum
AFAPI array accum(const array &in, const int dim=0)
C++ Interface for computing the cumulative sum (inclusive) of an array.
af_product_all
AFAPI af_err af_product_all(double *real, double *imag, const af_array in)
C Interface for product of all elements in an array.
af_sort
AFAPI af_err af_sort(af_array *out, const af_array in, const unsigned dim, const bool isAscending)
C Interface for sorting an array.
AF_BINARY_ADD
@ AF_BINARY_ADD
Definition: defines.h:430
af::countByKey
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.
af::sumByKey
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.
af_imin_all
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.
af_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 for sum of elements in an array according to key.
af_binary_op
af_binary_op
Definition: defines.h:429
af::setUnique
AFAPI array setUnique(const array &in, const bool is_sorted=false)
C++ Interface for getting unique values.
af::product
AFAPI array product(const array &in, const int dim=-1)
C++ Interface for product of elements in an array.
af::anyTrue
AFAPI array anyTrue(const array &in, const int dim=-1)
C++ Interface for checking any true values in an array.
af::sort
AFAPI array sort(const array &in, const unsigned dim=0, const bool isAscending=true)
C++ Interface for sorting an array.
AFAPI
#define AFAPI
Definition: defines.h:38
af::array
A multi dimensional data container.
Definition: array.h:35
af::maxByKey
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.
af::scan
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.
af
Definition: algorithm.h:15
af_sum_by_key_nan
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.
af_any_true_by_key
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.
af::max
AFAPI array max(const array &in, const int dim=-1)
C++ Interface for maximum values in an array.
af::diff1
AFAPI array diff1(const array &in, const int dim=0)
C++ Interface for calculating first order differences in an array.
af_all_true
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.
af_imax
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.
af_set_unique
AFAPI af_err af_set_unique(af_array *out, const af_array in, const bool is_sorted)
C Interface for getting unique values.
af_sum
AFAPI af_err af_sum(af_array *out, const af_array in, const int dim)
C Interface for sum of elements in an array.
af_diff1
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.
af_array
void * af_array
Definition: defines.h:240
af_sum_all
AFAPI af_err af_sum_all(double *real, double *imag, const af_array in)
C Interface for sum of all elements in an array.
af_count_by_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.
af::diff2
AFAPI array diff2(const array &in, const int dim=0)
C++ Interface for calculating second order differences in an array.
af_sort_by_key
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.
af_scan
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.
af::allTrueByKey
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.
af_max_all
AFAPI af_err af_max_all(double *real, double *imag, const af_array in)
C Interface for getting maximum value of an array.
af::count
AFAPI array count(const array &in, const int dim=-1)
C++ Interface for counting non-zero values in an array.
af_min
AFAPI af_err af_min(af_array *out, const af_array in, const int dim)
C Interface for minimum values in an array.
af_min_all
AFAPI af_err af_min_all(double *real, double *imag, const af_array in)
C Interface for getting minimum value of an array.
af::real
AFAPI array real(const array &in)
C++ Interface for getting real part from complex array.
af::setUnion
AFAPI array setUnion(const array &first, const array &second, const bool is_unique=false)
C++ Interface for finding the union of two arrays.
af_count_all
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.
af::scanByKey
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.
af_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 for product of elements in an array according to key.
af_set_union
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.
af_scan_by_key
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.
af_any_true_all
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.
af_diff2
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.
af_accum
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.
af_all_true_by_key
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.
af::where
AFAPI array where(const array &in)
C++ Interface for finding the locations of non-zero values in an array.
af_sum_nan
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.
af_where
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.
af_set_intersect
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.
af_count
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.
af_max
AFAPI af_err af_max(af_array *out, const af_array in, const int dim)
C Interface for maximum values in an array.
af_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)
C Interface for maximum values in an array according to key.
af::imag
AFAPI array imag(const array &in)
C++ Interface for getting imaginary part from complex array.
af_product_nan
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.
af::sum
AFAPI array sum(const array &in, const int dim=-1)
C++ Interface for sum of elements in an array.
af_all_true_all
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.
af_product_by_key_nan
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.
af::allTrue
AFAPI array allTrue(const array &in, const int dim=-1)
C++ Interface for checking all true values in an array.
af::setIntersect
AFAPI array setIntersect(const array &first, const array &second, const bool is_unique=false)
C++ Interface for finding the intersection of two arrays.
af_sort_index
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.
af_imin
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.
af_product
AFAPI af_err af_product(af_array *out, const af_array in, const int dim)
C Interface for product of elements in an array.
af::minByKey
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.
af::min
AFAPI array min(const array &in, const int dim=-1)
C++ Interface for minimum values in an array.
af::productByKey
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.
af_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)
C Interface for minimum values in an array according to key.
af_err
af_err
Definition: defines.h:71
af::anyTrueByKey
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.
defines.h
af_sum_nan_all
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.
af_imax_all
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.
af_product_nan_all
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.
af_any_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.