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>,
impl<T, S, const D: usize> TensorReverse<T, S, D>where
S: TensorRef<T, D>,
Sourcepub fn from(source: S, dimensions: &[Dimension]) -> TensorReverse<T, S, D>
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.
Sourcepub fn source_ref(&self) -> &S
pub fn source_ref(&self) -> &S
Gives a reference to the TensorReverse’s source (in which the iteration order 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 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>
impl<T: Clone, S: Clone, const D: usize> Clone for TensorReverse<T, S, D>
Source§fn clone(&self) -> TensorReverse<T, S, D>
fn clone(&self) -> TensorReverse<T, S, D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§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.
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>
fn get_reference_mut(&mut self, indexes: [usize; D]) -> Option<&mut T>
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
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.
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.