Skip to content
fn

sort_op

→TensorImplPtr
int sort_op(const int & a, int axis)

Python wrappers

Public Python APIs implemented by this engine symbol.

Sort a tensor along a single axis in ascending order.

Returns the sorted values; the permutation indices are computed internally and consumed by the backward pass but are not exposed here. See argsort_op for the indices alone, or topk_op for a (values, indices) pair.

Math

Let σ\sigma be the permutation that sorts a along axis. Then

\frac{\partial L}{\partial a_i} = \left(\frac{\partial L}{\partial y}\right)_{\sigma^{-1}(i)}.$$

Parameters

aTensorImplPtr
Input tensor.
axisint
Axis along which to sort.

Returns

TensorImplPtr

Sorted tensor of the same shape and dtype as a.

Notes

Differentiable for F32 / F64 inputs only via IndexScatterBackward, which scatters the incoming gradient back to the original positions. Integer dtypes return a detached output.