CUDA
C/C++    Fortran   

Index or count nonzero elements

array where (const array &input)
 indices where nonzero (zero-based indexing)
void where (array &row, array &column, const array &input)
 row and column indices of nonzero elements in input
unsigned count (const array &input)
 count nonzero elements in input

Function Documentation

array af::where ( const array &  input)

indices where nonzero (zero-based indexing)

       array a = randu(20e6);
       array ind = where(a > .5);

       array b = a(ind); // pull out non-zero elements
       array c = a(a > .5); // implicitly uses where()
Parameters:
[in]input
Returns:
[out] indices of nonzero elements
void af::where ( array &  row,
array &  column,
const array &  input 
)

row and column indices of nonzero elements in input

       array a = randu(1000,1000);
       array row, col;
       where(row, col, a > .5);

       array b = a(row,col); // pull out nonzero elements
Parameters:
[in]input
[out]row
[out]column
unsigned af::count ( const array &  input)

count nonzero elements in input

       float ha[] = { 0, 1, 0, 3, -3, 0.2, 0 };
       array a(7,ha);
       unsigned nnz = count(a);
       printf("nonzero: %d\n", nnz); // 'nonzero: 4'
Parameters:
[in]input
Returns:
The number of nonzero elements in input
Examples:
examples/benchmarks/pi.cpp.