argsort

Contents

argsort#

Compute the indices that would sort the elements of a tensor in either ascending or descending order

template<typename InputOperator>
__MATX_INLINE__ auto matx::argsort(const InputOperator &a, const SortDirection_t dir = SORT_DIR_ASC)#

Argsort rows of an operator

Generates indices that would sort the rows of an operator. Currently supported types are float, double, ints, and long ints (both signed and unsigned). For a 1D operator, a linear sort is performed. For 2D and above each row of the inner dimensions are batched and sorted separately.

Note

Temporary memory may be used during the sorting process, and about 4N will be allocated, where N is the length of the tensor.

Template Parameters:

InputOperator – Input type

Parameters:
  • a – Input operator

  • dir – Direction to sort (either SORT_DIR_ASC or SORT_DIR_DESC)

Returns:

Operator containing indices that would sort the tensor

Examples#

// Ascending argsort of 1D input
(tmpv = matx::argsort(this->t1, SORT_DIR_ASC)).run(this->exec);
// Descending argsort of 1D input
(tmpv = matx::argsort(this->t1, SORT_DIR_DESC)).run(this->exec);