Trait dfdx::tensor_ops::ReshapeTo
source · 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§
Provided Methods§
sourcefn reshape<Dst: ConstShape>(self) -> Self::WithShape<Dst>where
Self::Shape: ConstShape,
fn reshape<Dst: ConstShape>(self) -> Self::WithShape<Dst>where Self::Shape: ConstShape,
Reshapes a tensor to a different compile time shape.
sourcefn try_reshape<Dst: ConstShape>(self) -> Result<Self::WithShape<Dst>, Self::Err>where
Self::Shape: ConstShape,
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.
sourcefn reshape_like<Dst: Shape>(self, dst: &Dst) -> Self::WithShape<Dst>
fn reshape_like<Dst: Shape>(self, dst: &Dst) -> Self::WithShape<Dst>
Reshapes a tensor to a different runtime shape.
sourcefn contiguous(self) -> Self::WithShape<Self::Shape>
fn contiguous(self) -> Self::WithShape<Self::Shape>
Ensures the tensor’s memory is contiguous.
If the memory is already contiguous no copying is performed.