Skip to main content

SortKind

Enum SortKind 

Source
#[non_exhaustive]
#[repr(u16)]
pub enum SortKind {
Show 15 variants Sort = 0, SortBackward = 1, Argsort = 2, Msort = 3, MsortBackward = 4, Topk = 5, TopkBackward = 6, Kthvalue = 7, KthvalueBackward = 8, Unique = 9, UniqueConsecutive = 10, Histogram = 11, Histogramdd = 12, Bincount = 13, Searchsorted = 14,
}
Expand description

Sorting / order-statistics op discriminant — Category O from the comprehensive plan (Phase 9).

Stored as u16 in crate::KernelSku::op when category == OpCategory::Sorting. Phase 9 wires the block-bitonic trailblazer family (row_len ≤ 1024, k ≤ 64):

Dtype coverage:

  • sort / argsort / msort FW: f32, f64, i32, i64.
  • sort / msort BW: f32, f64 (FP grads only).
  • topk FW + BW: f32, f64.
  • kthvalue: composes topk; same dtype set.
  • unique / unique_consecutive: f32, f64, i32.
  • histogram: f32, f64 input → i32 counts.
  • bincount: i32, i64 input → i32 counts.
  • searchsorted: f32, f64, i32, i64.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Sort = 0

sort(x, dim, descending) — returns sorted values + sorted indices. PyTorch torch.sort.

§

SortBackward = 1

Gradient of Self::Sort — scatter dy back to the original positions via the saved indices.

§

Argsort = 2

argsort(x, dim, descending) — returns sorted indices only. PyTorch torch.argsort.

§

Msort = 3

msort(x) — stable sort along the last dimension. Tie-break on original index preserves input order. PyTorch torch.msort.

§

MsortBackward = 4

Gradient of Self::Msort — same scatter as Self::SortBackward.

§

Topk = 5

topk(x, k, dim, largest) — top-k (or bottom-k) values + their indices. PyTorch torch.topk. Trailblazer caps k ≤ 64.

§

TopkBackward = 6

Gradient of Self::Topk — scatter the k-wide dy back to a zero-init row_len-wide dx via saved indices.

§

Kthvalue = 7

kthvalue(x, k, dim) — the k-th smallest value + its index. Composed at the Rust plan layer atop Self::Topk with the “bottom-k” order.

§

KthvalueBackward = 8

Gradient of Self::Kthvalue — scatter the scalar dy back to the single source position.

§

Unique = 9

unique(x, sorted=True) — returns the unique values in x. At the Rust plan layer this chains Self::Sort + the consecutive dedup. Set-valued — no BW.

§

UniqueConsecutive = 10

unique_consecutive(x) — emits one cell per run-start (input must be sorted, or only consecutive-equal cells should be collapsed). Set-valued — no BW.

§

Histogram = 11

histogram(x, bins, range) — 1-D uniform-bin histogram. PyTorch torch.histogram. FW only.

§

Histogramdd = 12

histogramdd(x, bins, range) — N-D histogram. Reserved discriminant; rank > 1 trailblazer follow-up.

§

Bincount = 13

bincount(x, minlength) — count occurrences of each integer in x. PyTorch torch.bincount. FW only.

§

Searchsorted = 14

searchsorted(sorted_seq, values, right) — per-query lower/upper bound binary search. PyTorch torch.searchsorted. FW only.

Trait Implementations§

Source§

impl Clone for SortKind

Source§

fn clone(&self) -> SortKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SortKind

Source§

impl Debug for SortKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for SortKind

Source§

impl Hash for SortKind

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SortKind

Source§

fn eq(&self, other: &SortKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SortKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.