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>

source

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>

source

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>

source§

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)

Performs copy-assignment from source. Read more
source§

impl<T: Debug, S: Debug, N: Debug> Debug for TensorRefMatrix<T, S, N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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>

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

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>

source§

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]

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

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>

The way the data in this tensor is laid out in memory. In particular, Linear has several requirements on what is returned that must be upheld by implementations of this trait. Read more

Auto Trait Implementations§

§

impl<T, S, N> Freeze for TensorRefMatrix<T, S, N>
where N: Freeze, S: Freeze,

§

impl<T, S, N> RefUnwindSafe for TensorRefMatrix<T, S, N>

§

impl<T, S, N> Send for TensorRefMatrix<T, S, N>
where N: Send, S: Send, T: Send,

§

impl<T, S, N> Sync for TensorRefMatrix<T, S, N>
where N: Sync, S: Sync, T: Sync,

§

impl<T, S, N> Unpin for TensorRefMatrix<T, S, N>
where N: Unpin, S: Unpin, T: Unpin,

§

impl<T, S, N> UnwindSafe for TensorRefMatrix<T, S, N>
where N: UnwindSafe, 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.