Struct easy_ml::tensors::indexing::TensorTranspose
source · pub struct TensorTranspose<T, S, const D: usize> { /* private fields */ }
Expand description
A TensorTranspose makes the data in the tensor it is created from appear to be in a different order, swapping the lengths of each named dimension to match the new order but leaving the dimension name order unchanged.
use easy_ml::tensors::Tensor;
use easy_ml::tensors::indexing::TensorTranspose;
use easy_ml::tensors::views::TensorView;
let tensor = Tensor::from([("batch", 2), ("rows", 3), ("columns", 2)], vec![
1, 2,
3, 4,
5, 6,
7, 8,
9, 0,
1, 2
]);
let transposed = TensorView::from(TensorTranspose::from(&tensor, ["batch", "columns", "rows"]));
assert_eq!(
transposed,
Tensor::from([("batch", 2), ("rows", 2), ("columns", 3)], vec![
1, 3, 5,
2, 4, 6,
7, 9, 1,
8, 0, 2
])
);
let also_transposed = tensor.transpose_view(["batch", "columns", "rows"]);
Implementations§
source§impl<T, S, const D: usize> TensorTranspose<T, S, D>where
S: TensorRef<T, D>,
impl<T, S, const D: usize> TensorTranspose<T, S, D>where
S: TensorRef<T, D>,
sourcepub fn from(source: S, dimensions: [Dimension; D]) -> TensorTranspose<T, S, D>
pub fn from(source: S, dimensions: [Dimension; D]) -> TensorTranspose<T, S, D>
Creates a TensorTranspose which makes the data appear in the order of the supplied dimensions. The order of the dimension names is unchanged, although their lengths may swap.
§Panics
If the set of dimensions in the tensor does not match the set of dimensions provided. The order need not match.
sourcepub fn try_from(
source: S,
dimensions: [Dimension; D]
) -> Result<TensorTranspose<T, S, D>, InvalidDimensionsError<D>>
pub fn try_from( source: S, dimensions: [Dimension; D] ) -> Result<TensorTranspose<T, S, D>, InvalidDimensionsError<D>>
Creates a TensorTranspose which makes the data to appear in the order of the supplied dimensions. The order of the dimension names is unchanged, although their lengths may swap.
Returns Err if the set of dimensions supplied do not match the set of dimensions in this tensor’s shape.
sourcepub fn shape(&self) -> [(Dimension, usize); D]
pub fn shape(&self) -> [(Dimension, usize); D]
The shape of this TensorTranspose appears to rearrange the data to the order of supplied dimensions. The actual data in the underlying tensor and the order of the dimension names on this TensorTranspose remains unchanged, although the lengths of the dimensions in this shape of may swap compared to the source’s shape.
pub fn source(self) -> S
pub fn source_ref(&self) -> &S
Trait Implementations§
source§impl<T: Clone, S: Clone, const D: usize> Clone for TensorTranspose<T, S, D>
impl<T: Clone, S: Clone, const D: usize> Clone for TensorTranspose<T, S, D>
source§fn clone(&self) -> TensorTranspose<T, S, D>
fn clone(&self) -> TensorTranspose<T, S, D>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T, S, const D: usize> Display for TensorTranspose<T, S, D>
impl<T, S, const D: usize> Display for TensorTranspose<T, S, D>
Any tensor transpose of a Displayable type implements Display
You can control the precision of the formatting using format arguments, i.e.
format!("{:.3}", tensor)
source§impl<T, S, const D: usize> TensorMut<T, D> for TensorTranspose<T, S, D>where
S: TensorMut<T, D>,
impl<T, S, const D: usize> TensorMut<T, D> for TensorTranspose<T, S, D>where
S: TensorMut<T, D>,
A TensorTranspose implements TensorMut, with the dimension order and indexing matching that of the TensorTranspose shape.
source§fn get_reference_mut(&mut self, indexes: [usize; D]) -> Option<&mut T>
fn get_reference_mut(&mut self, indexes: [usize; D]) -> Option<&mut T>
source§unsafe fn get_reference_unchecked_mut(&mut self, indexes: [usize; D]) -> &mut T
unsafe fn get_reference_unchecked_mut(&mut self, indexes: [usize; D]) -> &mut T
source§impl<T, S, const D: usize> TensorRef<T, D> for TensorTranspose<T, S, D>where
S: TensorRef<T, D>,
impl<T, S, const D: usize> TensorRef<T, D> for TensorTranspose<T, S, D>where
S: TensorRef<T, D>,
A TensorTranspose implements TensorRef, with the dimension order and indexing matching that of the TensorTranspose shape.