/*!
\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                 | 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                 | 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                 | 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                 | 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                 | 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



@}
*/
