pub trait ReshapeTo: HasErr + HasShape {
    // Required method
    fn try_reshape_like<Dst: Shape>(
        self,
        dst: &Dst
    ) -> Result<Self::WithShape<Dst>, Self::Err>;

    // Provided methods
    fn reshape<Dst: ConstShape>(self) -> Self::WithShape<Dst>
       where Self::Shape: ConstShape { ... }
    fn try_reshape<Dst: ConstShape>(
        self
    ) -> Result<Self::WithShape<Dst>, Self::Err>
       where Self::Shape: ConstShape { ... }
    fn reshape_like<Dst: Shape>(self, dst: &Dst) -> Self::WithShape<Dst> { ... }
    fn contiguous(self) -> Self::WithShape<Self::Shape> { ... }
    fn try_contiguous(self) -> Result<Self::WithShape<Self::Shape>, Self::Err> { ... }
}
Expand description

Changes the shape of a tensor without re-ordering axes. If the tensor is contiguous already, then no data movement will occur. If the tensor is not contiguous, the result of this will be contiguous.

Compile time reshapes:

let t: Tensor<Rank2<2, 4>, f32, _> = dev.zeros();
let t: Tensor<Rank1<8>, f32, _> = t.reshape();

Compile time failure:

let t: Tensor<Rank2<2, 4>, f32, _> = dev.zeros();
let t: Tensor<Rank1<7>, f32, _> = t.reshape();

Runtime reshapes:

let t: Tensor<Rank2<2, 4>, f32, _> = dev.zeros();
let t: Tensor<(usize, ), f32, _> = t.reshape_like(&(8, ));

Required Methods§

source

fn try_reshape_like<Dst: Shape>( self, dst: &Dst ) -> Result<Self::WithShape<Dst>, Self::Err>

Reshapes a tensor to a different runtime shape.

Provided Methods§

source

fn reshape<Dst: ConstShape>(self) -> Self::WithShape<Dst>where Self::Shape: ConstShape,

Reshapes a tensor to a different compile time shape.

source

fn try_reshape<Dst: ConstShape>(self) -> Result<Self::WithShape<Dst>, Self::Err>where Self::Shape: ConstShape,

Reshapes a tensor to a different compile time shape.

source

fn reshape_like<Dst: Shape>(self, dst: &Dst) -> Self::WithShape<Dst>

Reshapes a tensor to a different runtime shape.

source

fn contiguous(self) -> Self::WithShape<Self::Shape>

Ensures the tensor’s memory is contiguous.

If the memory is already contiguous no copying is performed.

source

fn try_contiguous(self) -> Result<Self::WithShape<Self::Shape>, Self::Err>

Implementors§

source§

impl<S: Shape, E: Dtype, D: ReshapeKernel<E>, T: Tape<E, D>> ReshapeTo for Tensor<S, E, D, T>