Skip to main content

KthvaluePlan

Struct KthvaluePlan 

Source
pub struct KthvaluePlan<T: Element> { /* private fields */ }
Expand description

kthvalue plan.

Returns the k-th smallest value and its index along the last axis (PyTorch torch.kthvalue; 0-indexed k here, vs PyTorch’s 1-indexed). Composed at the plan layer as a bottom-(k+1) TopkPlan, reading cell (k) of the result.

When to use: order-statistic queries (median, quantile pickup in fixed K range). Pair with KthvalueBackwardPlan.

Dtypes: {f32, f64}.

Shape limits: input [batch, row_len]; outputs [batch]; row_len ≤ 1024; k < 64 (composes a bottom-(k+1) topk).

Workspace: zero in Workspace; plan internally allocates a scratch [batch, k+1] topk-result buffer per launch.

Precision guarantee: deterministic, bit-stable (inherits topk’s fixed-network guarantee).

Implementations§

Source§

impl<T: Element> KthvaluePlan<T>

Source

pub fn select( _stream: &Stream, desc: &KthvalueDescriptor, _pref: PlanPreference, ) -> Result<Self>

Pick a kernel for desc.

Source

pub fn can_implement(&self, args: &KthvalueArgs<'_, T>) -> Result<()>

Validate args.

Source

pub fn workspace_size(&self) -> usize

Workspace size in bytes. Internal device buffers are allocated fresh at run() time.

Source

pub fn sku(&self) -> KernelSku

Identity of the kernel this plan picked.

Source

pub fn precision_guarantee(&self) -> PrecisionGuarantee

Numerical guarantees for this plan’s kernel.

Source

pub fn run( &self, stream: &Stream, _workspace: Workspace<'_>, args: KthvalueArgs<'_, T>, ) -> Result<()>

Launch. Composes a bottom-(k+1) topk; reads the last cell as the k-th smallest. Allocates two intermediate device buffers and round-trips the bottom-(k+1) cells through host memory to extract the (k)-th slot per row (the data is small — batch * (k+1) cells with k+1 ≤ 64).

Auto Trait Implementations§

§

impl<T> Freeze for KthvaluePlan<T>

§

impl<T> RefUnwindSafe for KthvaluePlan<T>
where T: RefUnwindSafe,

§

impl<T> Send for KthvaluePlan<T>
where T: Send,

§

impl<T> Sync for KthvaluePlan<T>
where T: Sync,

§

impl<T> Unpin for KthvaluePlan<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for KthvaluePlan<T>

§

impl<T> UnwindSafe for KthvaluePlan<T>
where T: UnwindSafe,

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> 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, 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.