Skip to main content

TensorManipulationExt

Trait TensorManipulationExt 

Source
pub trait TensorManipulationExt<T: TensorElement> {
    // Required methods
    fn squeeze_all(&self) -> Result<Tensor<T>>;
    fn squeeze_dims(&self, dims: &[i32]) -> Result<Tensor<T>>;
    fn unsqueeze_dims(&self, dims: &[i32]) -> Result<Tensor<T>>;
    fn add_batch_dim(&self) -> Result<Tensor<T>>;
    fn remove_batch_dim(&self) -> Result<Tensor<T>>;
    fn atleast_nd(&self, n: usize) -> Result<Tensor<T>>;
    fn to_channel_last(&self) -> Result<Tensor<T>>;
    fn to_channel_first(&self) -> Result<Tensor<T>>;
    fn swap_dims(&self, dim0: i32, dim1: i32) -> Result<Tensor<T>>;
    fn move_dim(&self, src: i32, dst: i32) -> Result<Tensor<T>>;
    fn expand_to(&self, target_shape: &[usize]) -> Result<Tensor<T>>;
    fn repeat_along(&self, dim: i32, repeats: usize) -> Result<Tensor<T>>;
}
Expand description

Extension trait for advanced tensor manipulation

Required Methods§

Source

fn squeeze_all(&self) -> Result<Tensor<T>>

Squeeze all dimensions of size 1

Source

fn squeeze_dims(&self, dims: &[i32]) -> Result<Tensor<T>>

Squeeze specific dimensions

Source

fn unsqueeze_dims(&self, dims: &[i32]) -> Result<Tensor<T>>

Unsqueeze at multiple positions

Source

fn add_batch_dim(&self) -> Result<Tensor<T>>

Add a batch dimension at the front

Source

fn remove_batch_dim(&self) -> Result<Tensor<T>>

Remove the batch dimension (first dimension)

Source

fn atleast_nd(&self, n: usize) -> Result<Tensor<T>>

Ensure tensor has at least N dimensions (add trailing dimensions)

Source

fn to_channel_last(&self) -> Result<Tensor<T>>

Transpose to channel-last format (NCHW -> NHWC)

Source

fn to_channel_first(&self) -> Result<Tensor<T>>

Transpose to channel-first format (NHWC -> NCHW)

Source

fn swap_dims(&self, dim0: i32, dim1: i32) -> Result<Tensor<T>>

Swap two dimensions

Source

fn move_dim(&self, src: i32, dst: i32) -> Result<Tensor<T>>

Move a dimension to a new position

Source

fn expand_to(&self, target_shape: &[usize]) -> Result<Tensor<T>>

Expand singleton dimensions to match target shape

Source

fn repeat_along(&self, dim: i32, repeats: usize) -> Result<Tensor<T>>

Repeat tensor along new dimension

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§