TensorMetadataCastPrims

Trait TensorMetadataCastPrims 

Source
pub trait TensorMetadataCastPrims<S: Scalar> {
    type Plan;
    type Context;

    // Required methods
    fn plan(
        ctx: &mut Self::Context,
        desc: &MetadataCastPrimsDescriptor,
        shapes: &[&[usize]],
    ) -> Result<Self::Plan>;
    fn execute(
        ctx: &mut Self::Context,
        plan: &Self::Plan,
        alpha: S,
        inputs: &[MetadataScalarTensorRef<'_, S>],
        beta: S,
        output: &mut Tensor<S>,
    ) -> Result<()>;
    fn has_metadata_cast_support(desc: MetadataCastPrimsDescriptor) -> bool;
}
Expand description

Metadata-to-scalar bridge protocol.

This family bridges integer/bool metadata tensors into scalar tensors so higher-level crates can reuse scalar where and similar dense eager paths.

§Examples

use tenferro_algebra::Standard;
use tenferro_prims::{
    CpuBackend, CpuContext, MetadataCastPrimsDescriptor, MetadataDType,
    TensorMetadataCastPrims,
};

let mut ctx = CpuContext::new(1);
let desc = MetadataCastPrimsDescriptor::PointwiseCast {
    input_dtype: MetadataDType::I32,
};
let _plan = <CpuBackend as TensorMetadataCastPrims<f32>>::plan(
    &mut ctx,
    &desc,
    &[&[2], &[2]],
)
.unwrap();

Required Associated Types§

Source

type Plan

Backend plan type.

Source

type Context

Backend execution context.

Required Methods§

Source

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

Plan a metadata-to-scalar bridge operation.

Source

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

Execute a previously planned metadata-to-scalar bridge operation.

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

Source

fn has_metadata_cast_support(desc: MetadataCastPrimsDescriptor) -> 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§