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

A combination of new dimension names and a tensor.

The provided dimension names override the dimension names in the view_shape of the TensorRef exposed.

use easy_ml::tensors::Tensor;
use easy_ml::tensors::views::{TensorRename, TensorView};
let a_b = Tensor::from([("a", 2), ("b", 2)], (0..4).collect());
let b_c = TensorView::from(TensorRename::from(&a_b, ["b", "c"]));
let also_b_c = a_b.rename_view(["b", "c"]);
assert_ne!(a_b, b_c);
assert_eq!(b_c, also_b_c);

Implementations§

source§

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

source

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

Creates a TensorRename from a source and a list of dimension names to override the view_shape with.

Panics
  • If a dimension name is not unique
source

pub fn source(self) -> S

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

source

pub fn source_ref(&self) -> &S

Gives a reference to the TensorRename’s source (in which the dimension names may be different).

source

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

Gives a mutable reference to the TensorRename’s source (in which the dimension names may be different).

source

pub fn get_names(&self) -> &[Dimension; D]

Gets the dimension names this TensorRename is overriding the source it was created from with.

source

pub fn set_names(&mut self, dimensions: [Dimension; D])

Sets the dimension names this TensorRename is overriding the source it was created from with.

Panics
  • If a dimension name is not unique

Trait Implementations§

source§

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

source§

fn clone(&self) -> TensorRename<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 TensorRename<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 TensorRename<T, S, D>where
    S: TensorMut<T, D>,

A TensorRename implements TensorMut, with the dimension names the TensorRename was created with overriding 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 TensorRename<T, S, D>where
    S: TensorRef<T, D>,

A TensorRename implements TensorRef, with the dimension names the TensorRename was created with overriding 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> RefUnwindSafe for TensorRename<T, S, D>where
    S: RefUnwindSafe,
    T: RefUnwindSafe,

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
    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, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.