sort#

Sort elements of a tensor in either ascending or descending order

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

Sort rows of an operator

Sort rows of an operator using a radix sort. 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. There is currently a restriction that the tensor must have contiguous data in both rows and columns, but this restriction may be removed in the future.

Note

Temporary memory is used during the sorting process, and about 2N 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 for sorted tensor

Examples#

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