- Main Page
- Tutorials
- Functions
- Release Notes
- Examples

Functions
count
Complete List of ArrayFire Functions ArrayFire Functions by Category » Vector Algorithms » | Reduction operations

Count the number of non-zero elements in the input. More...

## Functions
AFAPI array | count (const array &in, const int dim=-1)
| C++ Interface for counting non-zero values in an array. More...
template<typename T >
T | count (const array &in)
| C++ Interface for counting total number of non-zero values in an array. More...
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. More...
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. More...

## Detailed Description

Count the number of non-zero elements in the input.

This function performs the operation across all batches present in the input simultaneously.

## Function Documentation

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.

Parameters

  [out] | out | will contain the number of non-zero values in `in` along `dim`
  [in] | in | is the input array
  [in] | dim | The dimension along which the non-zero values are counted

Returns
  AF_SUCCESS if the execution completes properly

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.

Parameters

  [out] | real | will contain the number of non-zero values in `in`.
  [out] | imag | is always set to 0.
  [in] | in | is the input array

Returns
  AF_SUCCESS if the execution completes properly

Note
  `imag` is always set to 0.

AFAPI array af::count | ( | const array & | in,
|  | const int | dim = `-1`
| ) |  |

C++ Interface for counting non-zero values in an array.

Parameters

  [in] | in | is the input array
  [in] | dim | The dimension along which the the number of non-zero values are counted

Returns
  the number of non-zero values along dimension `dim`

Note
  `dim` is -1 by default. -1 denotes the first non-singleton dimension.
  NaN values are treated as non zero.

Examples:
  pi.cpp.

T af::count | ( | const array & | in | ) |

C++ Interface for counting total number of non-zero values in an array.

Parameters

  [in] | in | is the input array

Returns
  the number of non-zero values in `in`

Note
  NaN values are treated as non zero