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§
fn shape(self) -> Vec<usize>
Sourcefn reshape(self, shape: &[usize]) -> Result<Self::Output>
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.
fn transpose(self, axes: &[usize]) -> Result<Self::Output>
fn reduce_axes( self, axes_operations: &mut [(usize, Operation)], ) -> Result<Self::Output>
Provided Methods§
Sourcefn compose_axes(
self,
output_shape: &[usize],
_group_lengths: &[usize],
) -> Result<Self::Output>where
Self: Sized,
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.
Sourcefn permute_and_compose(
self,
permutation: &[usize],
output_shape: &[usize],
_group_lengths: &[usize],
) -> Result<<Self::Output as Backend>::Output>
fn permute_and_compose( self, permutation: &[usize], output_shape: &[usize], _group_lengths: &[usize], ) -> Result<<Self::Output as Backend>::Output>
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".