TensorSortPrims

Trait TensorSortPrims 

Source
pub trait TensorSortPrims<Alg: Algebra>: Sized
where Alg::Scalar: PartialOrd,
{ type Plan; type Context; // Required methods fn plan( ctx: &mut Self::Context, desc: &SortPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>; fn execute( ctx: &mut Self::Context, plan: &Self::Plan, input: &Tensor<Alg::Scalar>, values_out: &mut Tensor<Alg::Scalar>, indices_out: &mut Tensor<i64>, ) -> Result<()>; fn has_sort_support(desc: &SortPrimsDescriptor) -> bool; }
Expand description

Sort execution protocol family.

Provides sorting, argsort, and top-k operations on tensors. The indices output tensor uses i64 elements representing positions along the target axis (same convention as crate::TensorIndexingPrims).

Unlike semiring and scalar families, sort does not use alpha/beta scaling – operations are pure data rearrangement.

§Examples

use tenferro_algebra::Standard;
use tenferro_prims::{CpuBackend, CpuContext, SortPrimsDescriptor, TensorSortPrims};

let mut ctx = CpuContext::new(1);
let desc = SortPrimsDescriptor::Sort {
    axis: 0,
    descending: false,
    stable: true,
};
let _plan = <CpuBackend as TensorSortPrims<Standard<f64>>>::plan(
    &mut ctx,
    &desc,
    &[&[5]],
)
.unwrap();

Required Associated Types§

Source

type Plan

Backend-specific execution plan.

Source

type Context

Backend execution context.

Required Methods§

Source

fn plan( ctx: &mut Self::Context, desc: &SortPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a sort operation for the given input shape.

shapes contains: [input_shape].

Source

fn execute( ctx: &mut Self::Context, plan: &Self::Plan, input: &Tensor<Alg::Scalar>, values_out: &mut Tensor<Alg::Scalar>, indices_out: &mut Tensor<i64>, ) -> Result<()>

Execute a previously planned sort operation.

  • For Sort: writes sorted values to values_out and permutation indices to indices_out.
  • For Argsort: writes permutation indices to indices_out; values_out is left unmodified.
  • For Topk: writes top-k values to values_out and their original indices to indices_out.
Source

fn has_sort_support(desc: &SortPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§