TensorScalarPrims

Trait TensorScalarPrims 

Source
pub trait TensorScalarPrims<Alg: Algebra> {
    type Plan;
    type Context;

    // Required methods
    fn plan(
        ctx: &mut Self::Context,
        desc: &ScalarPrimsDescriptor,
        shapes: &[&[usize]],
    ) -> Result<Self::Plan>;
    fn execute(
        ctx: &mut Self::Context,
        plan: &Self::Plan,
        alpha: Alg::Scalar,
        inputs: &[&Tensor<Alg::Scalar>],
        beta: Alg::Scalar,
        output: &mut Tensor<Alg::Scalar>,
    ) -> Result<()>;
    fn has_scalar_support(desc: ScalarPrimsDescriptor) -> bool;
}
Expand description

Scalar pointwise and reduction protocol family.

§Examples

use tenferro_algebra::Standard;
use tenferro_prims::{CpuBackend, CpuContext, ScalarPrimsDescriptor, ScalarUnaryOp, TensorScalarPrims};

let mut ctx = CpuContext::new(1);
let desc = ScalarPrimsDescriptor::PointwiseUnary {
    op: ScalarUnaryOp::Reciprocal,
};
let _plan = <CpuBackend as TensorScalarPrims<Standard<f64>>>::plan(
    &mut ctx,
    &desc,
    &[&[2, 2], &[2, 2]],
)
.unwrap();

Required Associated Types§

Required Methods§

Source

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

Plan a scalar-family operation for the given input/output shapes.

Backends may reject descriptors that are reserved in the public vocabulary but not yet wired to the current execution substrate.

Source

fn execute( ctx: &mut Self::Context, plan: &Self::Plan, alpha: Alg::Scalar, inputs: &[&Tensor<Alg::Scalar>], beta: Alg::Scalar, output: &mut Tensor<Alg::Scalar>, ) -> Result<()>

Execute a previously planned scalar-family operation.

The execution contract matches the rest of tenferro prims: output <- alpha * op(inputs) + beta * output.

Source

fn has_scalar_support(desc: ScalarPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.

This query is about the backend family surface, not whether a specific shape instance is valid.

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§