Struct TensorReverse

Source
pub struct TensorReverse<T, S, const D: usize> { /* private fields */ }
Expand description

A view over a tensor where some or all of the dimensions are iterated in reverse order.

use easy_ml::tensors::Tensor;
use easy_ml::tensors::views::{TensorView, TensorReverse};
let ab = Tensor::from([("a", 2), ("b", 3)], (0..6).collect());
let reversed = ab.reverse(&["a"]);
let also_reversed = TensorView::from(TensorReverse::from(&ab, &["a"]));
assert_eq!(reversed, also_reversed);
assert_eq!(
    reversed,
    Tensor::from(
        [("a", 2), ("b", 3)],
        vec![
            3, 4, 5,
            0, 1, 2,
        ]
    )
);

Implementations§

Source§

impl<T, S, const D: usize> TensorReverse<T, S, D>
where S: TensorRef<T, D>,

Source

pub fn from(source: S, dimensions: &[Dimension]) -> TensorReverse<T, S, D>

Creates a TensorReverse from a source and a list of dimension names to reverse the order of iteration for. The list cannot be more than the number of dimensions in the source but it does not need to contain every dimension in the source. Any dimensions in the source but not in the list of dimension names to reverse will continue to iterate in their normal order.

§Panics
  • If a dimension name is not in the source’s shape or is repeated.
Source

pub fn source(self) -> S

Consumes the TensorReverse, yielding the source it was created from.

Source

pub fn source_ref(&self) -> &S

Gives a reference to the TensorReverse’s source (in which the iteration order may be different).

Source

pub fn source_ref_mut(&mut self) -> &mut S

Gives a mutable reference to the TensorReverse’s source (in which the iteration order may be different).

Trait Implementations§

Source§

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

Source§

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

Returns a duplicate 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 TensorReverse<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> TensorMut<T, D> for TensorReverse<T, S, D>
where S: TensorMut<T, D>,

A TensorReverse implements TensorMut, with the dimension names the TensorReverse was created with iterating in reverse order compared to the dimension names in the original source.

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 TensorReverse<T, S, D>
where S: TensorRef<T, D>,

A TensorReverse implements TensorRef, with the dimension names the TensorReverse was created with iterating in reverse order compared to the dimension names in the original source.

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 TensorReverse<T, S, D>
where S: Freeze,

§

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

§

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

§

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

§

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

§

impl<T, S, const D: usize> UnwindSafe for TensorReverse<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.