pub struct MatrixRefTensor<T, S> { /* private fields */ }
Expand description
A wrapper around a Tensor<_, 2> type that implements MatrixRef and can thus be used in a MatrixView
use easy_ml::tensors::Tensor;
use easy_ml::matrices::views::MatrixView;
use easy_ml::interop::MatrixRefTensor;
let tensor = Tensor::from([("row", 2), ("column", 4)], vec![
1, 3, 5, 7,
2, 4, 6, 8
]);
let matrix_view = MatrixView::from(MatrixRefTensor::from(&tensor));
assert_eq!(
matrix_view.row_iter(1).eq(tensor.select([("row", 1)]).iter()),
true
);
Implementations§
Source§impl<T, S> MatrixRefTensor<T, S>where
S: TensorRef<T, 2>,
impl<T, S> MatrixRefTensor<T, S>where
S: TensorRef<T, 2>,
Sourcepub fn from(source: S) -> MatrixRefTensor<T, S>
pub fn from(source: S) -> MatrixRefTensor<T, S>
Creates a MatrixRefTensor wrapping a TensorRef type and stripping the dimension names.
The first dimension in the TensorRef type becomes the rows, and the second dimension the columns. If your tensor is the other way around, reorder it first.
Trait Implementations§
Source§impl<T, S> MatrixMut<T> for MatrixRefTensor<T, S>where
S: TensorMut<T, 2>,
impl<T, S> MatrixMut<T> for MatrixRefTensor<T, S>where
S: TensorMut<T, 2>,
Source§fn try_get_reference_mut(&mut self, row: Row, column: Column) -> Option<&mut T>
fn try_get_reference_mut(&mut self, row: Row, column: Column) -> 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,
row: Row,
column: Column,
) -> &mut T
unsafe fn get_reference_unchecked_mut( &mut self, row: Row, column: Column, ) -> &mut T
Gets a mutable reference to the value at the index without doing any bounds checking.
For a safe alternative see try_get_reference_mut. Read more
Source§impl<T, S> MatrixRef<T> for MatrixRefTensor<T, S>where
S: TensorRef<T, 2>,
impl<T, S> MatrixRef<T> for MatrixRefTensor<T, S>where
S: TensorRef<T, 2>,
Source§fn try_get_reference(&self, row: Row, column: Column) -> Option<&T>
fn try_get_reference(&self, row: Row, column: Column) -> Option<&T>
Gets a reference to the value at the index if the index is in range. Otherwise returns None.
Source§fn view_rows(&self) -> Row
fn view_rows(&self) -> Row
The number of rows that this reference can view. This may be less than the actual number of
rows of data stored in the matrix implementation, and could be 0.
Source§fn view_columns(&self) -> Column
fn view_columns(&self) -> Column
The number of columns that this reference can view. This may be less than the actual number
of columns of data stored in the matrix implementation, and could be 0.
Source§unsafe fn get_reference_unchecked(&self, row: Row, column: Column) -> &T
unsafe fn get_reference_unchecked(&self, row: Row, column: Column) -> &T
Gets a reference to the value at the index without doing any bounds checking. For a safe
alternative see try_get_reference. Read more
Source§fn data_layout(&self) -> MDataLayout
fn data_layout(&self) -> MDataLayout
A hint for the data layout this MatrixView uses to store its data. Read more
impl<T, S> NoInteriorMutability for MatrixRefTensor<T, S>where
S: TensorRef<T, 2>,
Auto Trait Implementations§
impl<T, S> Freeze for MatrixRefTensor<T, S>where
S: Freeze,
impl<T, S> RefUnwindSafe for MatrixRefTensor<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for MatrixRefTensor<T, S>
impl<T, S> Sync for MatrixRefTensor<T, S>
impl<T, S> Unpin for MatrixRefTensor<T, S>
impl<T, S> UnwindSafe for MatrixRefTensor<T, S>where
S: UnwindSafe,
T: UnwindSafe,
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