Implementing kernel
C++ engine symbols that back this Python API.Sort input along dim and return the sorted values.
The sort is stable: equal keys keep their input order. Only the values
come back — argsort gives the permutation that produces them,
with the same descending flag. (The reference framework returns a
(values, indices) pair here.)
Parameters
Returns
Tensorinput's values ordered along dim, same shape and dtype.
Notes
NaN sorts as the largest value: last ascending, first descending.
lucid.gather(input, dim, lucid.argsort(input, dim)) equals
lucid.sort(input, dim). Gradients flow back to the positions the
values came from.
Examples
>>> import lucid
>>> x = lucid.tensor([3, 1, 2])
>>> lucid.sort(x, dim=0)
Tensor([1, 2, 3])
>>> lucid.sort(x, dim=0, descending=True)
Tensor([3, 2, 1])