pub struct TensorReshape<T, S, const D: usize, const D2: usize> { /* private fields */ }Expand description
A new shape to override indexing an existing tensor. The dimensionality and individual dimension lengths can be changed, but the total number of elements in the new shape must match the existing tensor’s shape.
Elements are still in the same order (in memory) as the source tensor, none of the data is moved around - though iteration might be in a different order with the new shape.
If you just need to rename dimensions without changing them, see TensorRename
This types’ generics can be read as a TensorReshape is generic over some element of type T from an existing source of type S of dimensionality D, and this tensor has dimensionality D2, which might be different to D, but will have the same total number of elements.
use easy_ml::tensors::Tensor;
use easy_ml::tensors::views::{TensorReshape, TensorView};
let tensor = Tensor::from([("a", 2), ("b", 2)], (0..4).collect());
let flat = TensorView::from(TensorReshape::from(tensor, [("i", 4)])); // or use tensor.reshape_view_owned
assert_eq!(flat, Tensor::from([("i", 4)], (0..4).collect()));Implementations§
Source§impl<T, S, const D: usize, const D2: usize> TensorReshape<T, S, D, D2>where
S: TensorRef<T, D>,
impl<T, S, const D: usize, const D2: usize> TensorReshape<T, S, D, D2>where
S: TensorRef<T, D>,
Sourcepub fn from(
source: S,
shape: [(Dimension, usize); D2],
) -> TensorReshape<T, S, D, D2>
pub fn from( source: S, shape: [(Dimension, usize); D2], ) -> TensorReshape<T, S, D, D2>
Creates a TensorReshape from a source and a new shape to override the view_shape with. The new shape must correspond to the same number of total elements, but it need not match on dimensionality or individual dimension lengths.
If you just need to rename dimensions without changing them, see TensorRename If you don’t need to change the dimensionality, see from
§Panics
- If the new shape has a different number of elements to the existing shape in the source
- If the new shape has duplicate dimension names
Sourcepub fn source_ref(&self) -> &S
pub fn source_ref(&self) -> &S
Gives a reference to the TensorReshape’s source (in which the data has its original shape).
Source§impl<T, S, const D: usize> TensorReshape<T, S, D, D>where
S: TensorRef<T, D>,
impl<T, S, const D: usize> TensorReshape<T, S, D, D>where
S: TensorRef<T, D>,
Sourcepub fn from_existing_dimensions(
source: S,
lengths: [usize; D],
) -> TensorReshape<T, S, D, D>
pub fn from_existing_dimensions( source: S, lengths: [usize; D], ) -> TensorReshape<T, S, D, D>
Creates a TensorReshape from a source and new dimension lengths with the same dimensionality as the source to override the view_shape with. The new shape must correspond to the same number of total elements, but it need not match on individual dimension lengths.
If you just need to rename dimensions without changing them, see TensorRename If you need to change the dimensionality, see from
§Panics
- If the new shape has a different number of elements to the existing shape in the source
Trait Implementations§
Source§impl<T: Clone, S: Clone, const D: usize, const D2: usize> Clone for TensorReshape<T, S, D, D2>
impl<T: Clone, S: Clone, const D: usize, const D2: usize> Clone for TensorReshape<T, S, D, D2>
Source§fn clone(&self) -> TensorReshape<T, S, D, D2>
fn clone(&self) -> TensorReshape<T, S, D, D2>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug, S: Debug, const D: usize, const D2: usize> Debug for TensorReshape<T, S, D, D2>
impl<T: Debug, S: Debug, const D: usize, const D2: usize> Debug for TensorReshape<T, S, D, D2>
Source§impl<T, S, const D: usize, const D2: usize> TensorMut<T, D2> for TensorReshape<T, S, D, D2>where
S: TensorMut<T, D>,
A TensorReshape implements TensorMut, with the data in the same order as the original source.
impl<T, S, const D: usize, const D2: usize> TensorMut<T, D2> for TensorReshape<T, S, D, D2>where
S: TensorMut<T, D>,
A TensorReshape implements TensorMut, with the data in the same order as the original source.
Source§fn get_reference_mut(&mut self, indexes: [usize; D2]) -> Option<&mut T>
fn get_reference_mut(&mut self, indexes: [usize; D2]) -> Option<&mut T>
Source§unsafe fn get_reference_unchecked_mut(&mut self, indexes: [usize; D2]) -> &mut T
unsafe fn get_reference_unchecked_mut(&mut self, indexes: [usize; D2]) -> &mut T
Source§impl<T, S, const D: usize, const D2: usize> TensorRef<T, D2> for TensorReshape<T, S, D, D2>where
S: TensorRef<T, D>,
A TensorReshape implements TensorRef, with the data in the same order as the original source.
impl<T, S, const D: usize, const D2: usize> TensorRef<T, D2> for TensorReshape<T, S, D, D2>where
S: TensorRef<T, D>,
A TensorReshape implements TensorRef, with the data in the same order as the original source.