algorithm.h
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
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 
57  AFAPI array product(const array &in, const int dim = -1);
58 
59 #if AF_API_VERSION >= 31
60 
71  AFAPI array product(const array &in, const int dim, const double nanval);
72 #endif
73 
86  AFAPI array min(const array &in, const int dim = -1);
87 
100  AFAPI array max(const array &in, const int dim = -1);
101 
114  AFAPI array allTrue(const array &in, const int dim = -1);
115 
128  AFAPI array anyTrue(const array &in, const int dim = -1);
129 
142  AFAPI array count(const array &in, const int dim = -1);
143 
152  template<typename T> T sum(const array &in);
153 
154 #if AF_API_VERSION >= 31
155 
164  template<typename T> T sum(const array &in, double nanval);
165 #endif
166 
175  template<typename T> T product(const array &in);
176 
177 #if AF_API_VERSION >= 31
178 
187  template<typename T> T product(const array &in, double nanval);
188 #endif
189 
200  template<typename T> T min(const array &in);
201 
212  template<typename T> T max(const array &in);
213 
224  template<typename T> T allTrue(const array &in);
225 
236  template<typename T> T anyTrue(const array &in);
237 
248  template<typename T> T count(const array &in);
249 
264  AFAPI void min(array &val, array &idx, const array &in, const int dim = -1);
265 
280  AFAPI void max(array &val, array &idx, const array &in, const int dim = -1);
281 
293  template<typename T> void min(T *val, unsigned *idx, const array &in);
294 
306  template<typename T> void max(T *val, unsigned *idx, const array &in);
307 
317  AFAPI array accum(const array &in, const int dim = 0);
318 
327  AFAPI array where(const array &in);
328 
338  AFAPI array diff1(const array &in, const int dim = 0);
339 
349  AFAPI array diff2(const array &in, const int dim = 0);
350 
361  AFAPI array sort(const array &in, const unsigned dim = 0, const bool isAscending = true);
362 
374  AFAPI void sort(array &out, array &indices, const array &in, const unsigned dim = 0,
375  const bool isAscending = true);
388  AFAPI void sort(array &out_keys, array &out_values, const array &keys, const array &values,
389  const unsigned dim = 0, const bool isAscending = true);
390 
400  AFAPI array setUnique(const array &in, const bool is_sorted=false);
401 
412  AFAPI array setUnion(const array &first, const array &second, const bool is_unique=false);
413 
424  AFAPI array setIntersect(const array &first, const array &second, const bool is_unique=false);
425 }
426 #endif
427 
428 #ifdef __cplusplus
429 extern "C" {
430 #endif
431 
442  AFAPI af_err af_sum(af_array *out, const af_array in, const int dim);
443 
444 #if AF_API_VERSION >= 31
445 
456  AFAPI af_err af_sum_nan(af_array *out, const af_array in, const int dim, const double nanval);
457 #endif
458 
469  AFAPI af_err af_product(af_array *out, const af_array in, const int dim);
470 
471 #if AF_API_VERSION >= 31
472 
483  AFAPI af_err af_product_nan(af_array *out, const af_array in, const int dim, const double nanval);
484 #endif
485 
496  AFAPI af_err af_min(af_array *out, const af_array in, const int dim);
497 
508  AFAPI af_err af_max(af_array *out, const af_array in, const int dim);
509 
520  AFAPI af_err af_all_true(af_array *out, const af_array in, const int dim);
521 
532  AFAPI af_err af_any_true(af_array *out, const af_array in, const int dim);
533 
544  AFAPI af_err af_count(af_array *out, const af_array in, const int dim);
545 
558  AFAPI af_err af_sum_all(double *real, double *imag, const af_array in);
559 
560 #if AF_API_VERSION >= 31
561 
574  AFAPI af_err af_sum_nan_all(double *real, double *imag, const af_array in, const double nanval);
575 #endif
576 
589  AFAPI af_err af_product_all(double *real, double *imag, const af_array in);
590 
591 #if AF_API_VERSION >= 31
592 
605  AFAPI af_err af_product_nan_all(double *real, double *imag, const af_array in, const double nanval);
606 #endif
607 
620  AFAPI af_err af_min_all(double *real, double *imag, const af_array in);
621 
634  AFAPI af_err af_max_all(double *real, double *imag, const af_array in);
635 
648  AFAPI af_err af_all_true_all(double *real, double *imag, const af_array in);
649 
662  AFAPI af_err af_any_true_all(double *real, double *imag, const af_array in);
663 
676  AFAPI af_err af_count_all(double *real, double *imag, const af_array in);
677 
689  AFAPI af_err af_imin(af_array *out, af_array *idx, const af_array in, const int dim);
690 
702  AFAPI af_err af_imax(af_array *out, af_array *idx, const af_array in, const int dim);
703 
717  AFAPI af_err af_imin_all(double *real, double *imag, unsigned *idx, const af_array in);
718 
732  AFAPI af_err af_imax_all(double *real, double *imag, unsigned *idx, const af_array in);
733 
744  AFAPI af_err af_accum(af_array *out, const af_array in, const int dim);
745 
755  AFAPI af_err af_where(af_array *idx, const af_array in);
756 
767  AFAPI af_err af_diff1(af_array *out, const af_array in, const int dim);
768 
779  AFAPI af_err af_diff2(af_array *out, const af_array in, const int dim);
780 
792  AFAPI af_err af_sort(af_array *out, const af_array in, const unsigned dim, const bool isAscending);
793 
806  AFAPI af_err af_sort_index(af_array *out, af_array *indices, const af_array in,
807  const unsigned dim, const bool isAscending);
821  AFAPI af_err af_sort_by_key(af_array *out_keys, af_array *out_values,
822  const af_array keys, const af_array values,
823  const unsigned dim, const bool isAscending);
824 
835  AFAPI af_err af_set_unique(af_array *out, const af_array in, const bool is_sorted);
836 
848  AFAPI af_err af_set_union(af_array *out, const af_array first, const af_array second, const bool is_unique);
849 
861  AFAPI af_err af_set_intersect(af_array *out, const af_array first, const af_array second, const bool is_unique);
862 
863 #ifdef __cplusplus
864 }
865 #endif
Definition: algorithm.h:14
AFAPI array where(const array &in)
C++ Interface for finding the locations of non-zero values in 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 af_err af_set_union(af_array *out, const af_array first, const af_array second, const bool is_unique)
C Interface for performing union of two arrays.
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 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_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_product_all(double *real, double *imag, const af_array in)
C Interface for product of all elements 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_unique(af_array *out, const af_array in, const bool is_sorted)
C Interface for getting unique values.
AFAPI array sum(const array &in, const int dim=-1)
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 exclusive sum (cumulative sum) 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&#39;s location from the entire array.
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 array allTrue(const array &in, const int dim=-1)
C++ Interface for checking all true values in an array.
A multi dimensional data container.
Definition: array.h:27
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(af_array *out, const af_array in, const int dim)
C Interface for maximum values 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_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_err
Definition: defines.h:63
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 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_any_true(af_array *out, const af_array in, const int dim)
C Interface for checking any true 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_diff2(af_array *out, const af_array in, const int dim)
C Interface for calculating second order differences in an array.
AFAPI array imag(const array &in)
C++ Interface for getting imaginary part from complex array.
AFAPI array product(const array &in, const int dim=-1)
C++ Interface for product of elements 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 performing intersect of two arrays.
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 af_err af_min(af_array *out, const af_array in, const int dim)
C Interface for minimum values in an array.
AFAPI array real(const array &in)
C++ Interface for getting real part from complex 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.
#define AFAPI
Definition: defines.h:31
AFAPI array setIntersect(const array &first, const array &second, const bool is_unique=false)
C++ Interface for performing intersect of two arrays.
AFAPI array anyTrue(const array &in, const int dim=-1)
C++ Interface for checking any true values in an array.
AFAPI array setUnique(const array &in, const bool is_sorted=false)
C++ Interface for getting unique values.
AFAPI array accum(const array &in, const int dim=0)
C++ Interface exclusive sum (cumulative sum) of an array.
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_sort(af_array *out, const af_array in, const unsigned dim, const bool isAscending)
C Interface for sorting an array.
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.
void * af_array
Definition: defines.h:222
AFAPI array min(const array &in, const int dim=-1)
C++ Interface for minimum values 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_sum_all(double *real, double *imag, const af_array in)
C Interface for sum of all elements in an array.
AFAPI array sort(const array &in, const unsigned dim=0, const bool isAscending=true)
C++ Interface for sorting 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 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 array count(const array &in, const int dim=-1)
C++ Interface for counting non-zero values in an array.
AFAPI array setUnion(const array &first, const array &second, const bool is_unique=false)
C++ Interface for performing union of two arrays.
AFAPI array diff1(const array &in, const int dim=0)
C++ Interface for calculating first 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_max_all(double *real, double *imag, const af_array in)
C Interface for getting maximum value of an array.
AFAPI array diff2(const array &in, const int dim=0)
C++ Interface for calculating second order differences in an array.