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§
Required Methods§
Sourcefn plan(
ctx: &mut Self::Context,
desc: &MetadataCastPrimsDescriptor,
shapes: &[&[usize]],
) -> Result<Self::Plan>
fn plan( ctx: &mut Self::Context, desc: &MetadataCastPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>
Plan a metadata-to-scalar bridge operation.
Sourcefn execute(
ctx: &mut Self::Context,
plan: &Self::Plan,
alpha: S,
inputs: &[MetadataScalarTensorRef<'_, S>],
beta: S,
output: &mut Tensor<S>,
) -> Result<()>
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.
Sourcefn has_metadata_cast_support(desc: MetadataCastPrimsDescriptor) -> bool
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§
Source§impl<S> TensorMetadataCastPrims<S> for CpuBackend
impl<S> TensorMetadataCastPrims<S> for CpuBackend
type Plan = MetadataCastPrimsDescriptor
type Context = CpuContext
Source§impl<S: Scalar + NumCast> TensorMetadataCastPrims<S> for CudaBackend
Available on non-crate feature cuda only.
impl<S: Scalar + NumCast> TensorMetadataCastPrims<S> for CudaBackend
Available on non-crate feature
cuda only.