Struct MatrixRefTensor

Source
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>,

Source

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>,

Source§

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

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>,

Source§

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

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

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

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

A hint for the data layout this MatrixView uses to store its data. Read more
Source§

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>

§

impl<T, S> Send for MatrixRefTensor<T, S>
where S: Send, T: Send,

§

impl<T, S> Sync for MatrixRefTensor<T, S>
where S: Sync, T: Sync,

§

impl<T, S> Unpin for MatrixRefTensor<T, S>
where S: Unpin, T: Unpin,

§

impl<T, S> UnwindSafe for MatrixRefTensor<T, S>
where S: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.