A high-performance general-purpose compute library

This function returns the top k values along a given dimension of the input array. More...

Functions

AFAPI void topk (array &values, array &indices, const array &in, const int k, const int dim=-1, const topkFunction order=AF_TOPK_MAX)
 C++ Interface for finding top k elements along a given dimension. More...
 
AFAPI af_err af_topk (af_array *values, af_array *indices, const af_array in, const int k, const int dim, const af_topk_function order)
 C Interface for finding top k elements along a given dimension. More...
 

Detailed Description

This function returns the top k values along a given dimension of the input array.

The indices along with their values are returned. If the input is a multi-dimensional array, the indices will be the index of the value in that dimension. Order of duplicate values are not preserved. This function is optimized for small values of k.

This function performs the operation across all dimensions of the input array.

Note
{Currently, topk elements can be found only along dimension 0.}

Function Documentation

◆ af_topk()

AFAPI af_err af_topk ( af_array values,
af_array indices,
const af_array  in,
const int  k,
const int  dim,
const af_topk_function  order 
)

C Interface for finding top k elements along a given dimension.

Parameters
[out]valuesThe values of the top k elements along the dim dimension
[out]indicesThe indices of the top k elements along the dim dimension
[in]inInput af::array with at least k elements along dim
[in]kThe number of elements to be retriefed along the dim dimension
[in]dimThe dimension along which top k elements are extracted. (Must be 0)
[in]orderIf Descending the highest values are returned. Otherwise the lowest values are returned
Note
{This function is optimized for small values of k.}
{The order of the returned keys may not be in the same order as the appear in the input array, for a stable topk, set the AF_TOPK_STABLE flag in the order param. These are equivalent to AF_TOPK_STABLE_MAX and AF_TOPK_STABLE_MIN}

◆ topk()

AFAPI void topk ( array values,
array indices,
const array in,
const int  k,
const int  dim = -1,
const topkFunction  order = AF_TOPK_MAX 
)

C++ Interface for finding top k elements along a given dimension.

Parameters
[out]valuesThe values of the top k elements along the dim dimension
[out]indicesThe indices of the top k elements along the dim dimension
[in]inInput af::array with at least k elements along dim
[in]kThe number of elements to be retriefed along the dim dimension
[in]dimThe dimension along which top k elements are extracted. (Must be 0)
[in]orderIf Descending the highest values are returned. Otherwise the lowest values are returned
Note
{This function is optimized for small values of k.}
{The order of the returned keys may not be in the same order as the appear in the input array, for a stable topk, set the AF_TOPK_STABLE flag in the order param. These are equivalent to AF_TOPK_STABLE_MAX and AF_TOPK_STABLE_MIN}