Skip to main content

TensorViewCanonicalization

Trait TensorViewCanonicalization 

Source
pub trait TensorViewCanonicalization<T: Clone + 'static, R: TensorRank> {
    // Required methods
    fn to_contiguous(
        &mut self,
        view: &TypedTensorView<'_, T, R>,
    ) -> Result<TypedTensor<T, R>>;
    fn copy_from_contiguous(
        &mut self,
        src: &TypedTensor<T, R>,
        dst: &mut TypedTensorViewMut<'_, T, R>,
    ) -> Result<()>;
}
Expand description

Backend-owned canonicalization for typed tensor views.

Implementations must preserve the input placement family. CPU backends canonicalize host views through explicit host copies and reject backend buffers with a diagnostic that asks the caller to download first. GPU backends canonicalize GPU-resident views on the same device and reject host buffers with an upload hint.

This trait is intentionally separate from BackendSession so generic typed methods do not change the object-safety contract of dyn BackendSession.

§Examples

use tenferro_tensor::{DynRank, TensorViewCanonicalization, TypedTensor};

fn compact_i32<B: TensorViewCanonicalization<i32, DynRank>>(
    backend: &mut B,
    tensor: &TypedTensor<i32>,
) -> tenferro_tensor::Result<TypedTensor<i32>> {
    backend.to_contiguous(&tensor.as_view())
}

Required Methods§

Source

fn to_contiguous( &mut self, view: &TypedTensorView<'_, T, R>, ) -> Result<TypedTensor<T, R>>

Source

fn copy_from_contiguous( &mut self, src: &TypedTensor<T, R>, dst: &mut TypedTensorViewMut<'_, T, R>, ) -> Result<()>

Implementors§