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>,

source

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.

source

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.

source

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.

source

pub fn source(self) -> S

source

pub fn source_ref(&self) -> &S

Trait Implementations§

source§

impl<T: Clone, S: Clone, const D: usize> Clone for TensorTranspose<T, S, D>

source§

fn clone(&self) -> TensorTranspose<T, S, D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug, S: Debug, const D: usize> Debug for TensorTranspose<T, S, D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T, S, const D: usize> Display for TensorTranspose<T, S, D>
where T: Display, S: TensorRef<T, 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§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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>

Gets a mutable reference to the value at the index, if the index is in range. Otherwise returns None.
source§

unsafe fn get_reference_unchecked_mut(&mut self, indexes: [usize; D]) -> &mut T

Gets a mutable reference to the value at the index without doing any bounds checking. For a safe alternative see get_reference_mut. Read more
source§

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.

source§

fn get_reference(&self, indexes: [usize; D]) -> Option<&T>

Gets a reference to the value at the index if the index is in range. Otherwise returns None.
source§

fn view_shape(&self) -> [(Dimension, usize); D]

The shape this tensor has. See dimensions for an overview. The product of the lengths in the pairs define how many elements are in the tensor (or the portion of it that is visible).
source§

unsafe fn get_reference_unchecked(&self, indexes: [usize; D]) -> &T

Gets a reference to the value at the index without doing any bounds checking. For a safe alternative see get_reference. Read more
source§

fn data_layout(&self) -> DataLayout<D>

The way the data in this tensor is laid out in memory. In particular, Linear has several requirements on what is returned that must be upheld by implementations of this trait. Read more

Auto Trait Implementations§

§

impl<T, S, const D: usize> Freeze for TensorTranspose<T, S, D>
where S: Freeze,

§

impl<T, S, const D: usize> RefUnwindSafe for TensorTranspose<T, S, D>

§

impl<T, S, const D: usize> Send for TensorTranspose<T, S, D>
where S: Send, T: Send,

§

impl<T, S, const D: usize> Sync for TensorTranspose<T, S, D>
where S: Sync, T: Sync,

§

impl<T, S, const D: usize> Unpin for TensorTranspose<T, S, D>
where S: Unpin, T: Unpin,

§

impl<T, S, const D: usize> UnwindSafe for TensorTranspose<T, S, D>
where S: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.