Skip to main content

Backend

Trait Backend 

Source
pub trait Backend {
    type Output;

    // Required methods
    fn shape(self) -> Vec<usize>;
    fn reshape(self, shape: &[usize]) -> Result<Self::Output>;
    fn transpose(self, axes: &[usize]) -> Result<Self::Output>;
    fn reduce_axes(
        self,
        axes_operations: &mut [(usize, Operation)],
    ) -> Result<Self::Output>;
    fn add_axes(
        self,
        naxes: usize,
        pos2len: &[(usize, usize)],
    ) -> Result<Self::Output>;

    // Provided methods
    fn compose_axes(
        self,
        output_shape: &[usize],
        _group_lengths: &[usize],
    ) -> Result<Self::Output>
       where Self: Sized { ... }
    fn permute_and_compose(
        self,
        permutation: &[usize],
        output_shape: &[usize],
        _group_lengths: &[usize],
    ) -> Result<<Self::Output as Backend>::Output>
       where Self: Sized,
             Self::Output: Backend { ... }
}
Expand description

Tensor operations used by crate::einops!.

Transformations return Candle Result values so backend failures retain their original error and context.

Required Associated Types§

Required Methods§

Source

fn shape(self) -> Vec<usize>

Source

fn reshape(self, shape: &[usize]) -> Result<Self::Output>

Reshapes a tensor while preserving its storage and layout when the requested dimensions are already exact.

Call Tensor::contiguous explicitly when contiguous storage is required; an identity reshape no longer provides accidental materialization for non-contiguous inputs.

Source

fn transpose(self, axes: &[usize]) -> Result<Self::Output>

Source

fn reduce_axes( self, axes_operations: &mut [(usize, Operation)], ) -> Result<Self::Output>

Source

fn add_axes( self, naxes: usize, pos2len: &[(usize, usize)], ) -> Result<Self::Output>

Inserts new axes as broadcast views.

The returned tensor can be non-contiguous and can alias the input.

Provided Methods§

Source

fn compose_axes( self, output_shape: &[usize], _group_lengths: &[usize], ) -> Result<Self::Output>
where Self: Sized,

Composes adjacent logical axis groups after any preceding permutation.

The default retains the historical reshape sequence. Tensor backends may recover a storage-sharing layout before falling back to that copy.

Source

fn permute_and_compose( self, permutation: &[usize], output_shape: &[usize], _group_lengths: &[usize], ) -> Result<<Self::Output as Backend>::Output>
where Self: Sized, Self::Output: Backend,

Applies a permutation followed immediately by axis composition.

Backends may specialize this boundary. The default preserves the historical operation sequence for third-party implementations.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§