Struct easy_ml::interop::TensorRefMatrix
source · pub struct TensorRefMatrix<T, S, N> { /* private fields */ }
Expand description
A wrapper around a Matrix type that implements TensorRef and can thus be used in a TensorView
use easy_ml::matrices::Matrix;
use easy_ml::tensors::views::TensorView;
use easy_ml::interop::TensorRefMatrix;
let matrix = Matrix::from(vec![
vec![ 1, 3, 5, 7 ],
vec![ 2, 4, 6, 8 ]
]);
// We can always unwrap here because we know a 2x4 matrix is a valid input
let tensor_view = TensorView::from(TensorRefMatrix::from(&matrix).unwrap());
assert_eq!(
matrix.row_iter(1).eq(tensor_view.select([("row", 1)]).iter()),
true
);
Implementations§
source§impl<T, S> TensorRefMatrix<T, S, RowAndColumn>where
S: MatrixRef<T> + NoInteriorMutability,
impl<T, S> TensorRefMatrix<T, S, RowAndColumn>where
S: MatrixRef<T> + NoInteriorMutability,
sourcepub fn from(
source: S
) -> Result<TensorRefMatrix<T, S, RowAndColumn>, InvalidShapeError<2>>
pub fn from( source: S ) -> Result<TensorRefMatrix<T, S, RowAndColumn>, InvalidShapeError<2>>
Creates a TensorRefMatrix wrapping a MatrixRef type and defaulting the dimension names to “row” and “column” respectively.
Result::Err is returned if the matrix dimension lengths are not at least 1x1.
source§impl<T, S, N> TensorRefMatrix<T, S, N>
impl<T, S, N> TensorRefMatrix<T, S, N>
sourcepub fn with_names(
source: S,
names: N
) -> Result<TensorRefMatrix<T, S, N>, InvalidShapeError<2>>
pub fn with_names( source: S, names: N ) -> Result<TensorRefMatrix<T, S, N>, InvalidShapeError<2>>
Creates a TensorRefMatrix wrapping a MatrixRef type and provided dimension names.
Result::Err is returned if the provided dimension names are not unique, or the matrix dimension lengths are not at least 1x1.
use easy_ml::matrices::Matrix;
use easy_ml::tensors::views::TensorRef;
use easy_ml::interop::TensorRefMatrix;
assert_eq!(
// We can always unwrap here because we know the input is 1x1 and "x" and "y" are unique
// dimension names
TensorRefMatrix::with_names(Matrix::from_scalar(1.0), ["x", "y"]).unwrap().view_shape(),
[("x", 1), ("y", 1)]
);
Trait Implementations§
source§impl<T: Clone, S: Clone, N: Clone> Clone for TensorRefMatrix<T, S, N>
impl<T: Clone, S: Clone, N: Clone> Clone for TensorRefMatrix<T, S, N>
source§fn clone(&self) -> TensorRefMatrix<T, S, N>
fn clone(&self) -> TensorRefMatrix<T, S, N>
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, N> TensorMut<T, 2> for TensorRefMatrix<T, S, N>
impl<T, S, N> TensorMut<T, 2> for TensorRefMatrix<T, S, N>
source§fn get_reference_mut(&mut self, indexes: [usize; 2]) -> Option<&mut T>
fn get_reference_mut(&mut self, indexes: [usize; 2]) -> 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; 2]) -> &mut T
unsafe fn get_reference_unchecked_mut(&mut self, indexes: [usize; 2]) -> &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, N> TensorRef<T, 2> for TensorRefMatrix<T, S, N>
impl<T, S, N> TensorRef<T, 2> for TensorRefMatrix<T, S, N>
source§fn get_reference(&self, indexes: [usize; 2]) -> Option<&T>
fn get_reference(&self, indexes: [usize; 2]) -> 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); 2]
fn view_shape(&self) -> [(Dimension, usize); 2]
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; 2]) -> &T
unsafe fn get_reference_unchecked(&self, indexes: [usize; 2]) -> &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) -> TDataLayout<2>
fn data_layout(&self) -> TDataLayout<2>
Auto Trait Implementations§
impl<T, S, N> Freeze for TensorRefMatrix<T, S, N>
impl<T, S, N> RefUnwindSafe for TensorRefMatrix<T, S, N>
impl<T, S, N> Send for TensorRefMatrix<T, S, N>
impl<T, S, N> Sync for TensorRefMatrix<T, S, N>
impl<T, S, N> Unpin for TensorRefMatrix<T, S, N>
impl<T, S, N> UnwindSafe for TensorRefMatrix<T, S, N>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more