pub trait TensorSortPrims<Alg: Algebra>: Sizedwhere
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§
Required Methods§
Sourcefn plan(
ctx: &mut Self::Context,
desc: &SortPrimsDescriptor,
shapes: &[&[usize]],
) -> Result<Self::Plan>
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].
Sourcefn 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 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 tovalues_outand permutation indices toindices_out. - For
Argsort: writes permutation indices toindices_out;values_outis left unmodified. - For
Topk: writes top-k values tovalues_outand their original indices toindices_out.
Sourcefn has_sort_support(desc: &SortPrimsDescriptor) -> bool
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§
Source§impl<S: Scalar + PartialOrd + 'static> TensorSortPrims<Standard<S>> for CpuBackend
impl<S: Scalar + PartialOrd + 'static> TensorSortPrims<Standard<S>> for CpuBackend
Source§impl<S: Scalar + PartialOrd> TensorSortPrims<Standard<S>> for CudaBackend
Available on non-crate feature cuda only.
impl<S: Scalar + PartialOrd> TensorSortPrims<Standard<S>> for CudaBackend
Available on non-crate feature
cuda only.