Struct MatrixMask

Source
pub struct MatrixMask<T, S> { /* private fields */ }
Expand description

A 2 dimensional mask over a matrix, hiding the values inside the range from view.

The entire source is still owned by the MatrixMask however, so this does not permit creating multiple mutable masks into a single matrix even if they wouldn’t overlap.

See also: MatrixRange

Implementations§

Source§

impl<T, S> MatrixMask<T, S>
where S: MatrixRef<T>,

Source

pub fn from<R>(source: S, rows: R, columns: R) -> MatrixMask<T, S>
where R: Into<IndexRange>,

Creates a new MatrixMask giving a view of only the data outside the row and column IndexRanges. If the index range given for rows or columns exceeds the size of the matrix, they will be clipped to fit the actual size without an error.

§Examples

Creating a view and manipulating a matrix from it.

use easy_ml::matrices::Matrix;
use easy_ml::matrices::views::{MatrixView, MatrixMask};
let mut matrix = Matrix::from(vec![
    vec![ 2, 3, 4 ],
    vec![ 5, 1, 8 ]]);
{
    let mut view = MatrixView::from(MatrixMask::from(&mut matrix, 0..1, 2..3));
    assert_eq!(vec![5, 1], view.row_major_iter().collect::<Vec<_>>());
    view.map_mut(|x| x + 10);
}
assert_eq!(matrix, Matrix::from(vec![
    vec![ 2,   3,  4 ],
    vec![ 15, 11,  8 ]]));

Various ways to construct a MatrixMask

use easy_ml::matrices::Matrix;
use easy_ml::matrices::views::{IndexRange, MatrixMask};
let matrix = Matrix::from(vec![vec![1]]);
let index_range = MatrixMask::from(&matrix, IndexRange::new(0, 4), IndexRange::new(1, 3));
let tuple = MatrixMask::from(&matrix, (0, 4), (1, 3));
let array = MatrixMask::from(&matrix, [0, 4], [1, 3]);
// Note std::ops::Range is start..end not start and length!
let range = MatrixMask::from(&matrix, 0..4, 1..4);
Source

pub fn source(self) -> S

Consumes the MatrixMask, yielding the source it was created from.

Source

pub fn source_ref(&self) -> &S

Gives a reference to the MatrixMask’s source (in which the data is not masked).

Trait Implementations§

Source§

impl<T: Clone, S: Clone> Clone for MatrixMask<T, S>

Source§

fn clone(&self) -> MatrixMask<T, S>

Returns a duplicate 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> Debug for MatrixMask<T, S>

Source§

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

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

impl<T, S> MatrixMut<T> for MatrixMask<T, S>
where S: MatrixMut<T>,

A MatrixMask of a MatrixMut type implements MatrixMut.

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 MatrixMask<T, S>
where S: MatrixRef<T>,

A MatrixMask of a MatrixRef type implements MatrixRef.

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) -> DataLayout

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

impl<T, S> NoInteriorMutability for MatrixMask<T, S>

A MatrixMask of a NoInteriorMutability type implements NoInteriorMutability.

Auto Trait Implementations§

§

impl<T, S> Freeze for MatrixMask<T, S>
where S: Freeze,

§

impl<T, S> RefUnwindSafe for MatrixMask<T, S>

§

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

§

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

§

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

§

impl<T, S> UnwindSafe for MatrixMask<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.