Struct easy_ml::tensors::views::TensorRename
source · 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>,
impl<T, S, const D: usize> TensorRename<T, S, D>where
S: TensorRef<T, D>,
sourcepub fn from(source: S, dimensions: [Dimension; D]) -> TensorRename<T, S, D>
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
sourcepub fn source_ref(&self) -> &S
pub fn source_ref(&self) -> &S
Gives a reference to the TensorRename’s source (in which the dimension names may be different).
sourcepub fn source_ref_mut(&mut self) -> &mut S
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).
Trait Implementations§
source§impl<T: Clone, S: Clone, const D: usize> Clone for TensorRename<T, S, D>
impl<T: Clone, S: Clone, const D: usize> Clone for TensorRename<T, S, D>
source§fn clone(&self) -> TensorRename<T, S, D>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<T, S, const D: usize> TensorMut<T, D> for TensorRename<T, S, D>where
S: TensorMut<T, D>,
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>
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
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>,
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>
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]
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
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