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>,
impl<T, S> MatrixMask<T, S>where
S: MatrixRef<T>,
Sourcepub fn from<R>(source: S, rows: R, columns: R) -> MatrixMask<T, S>where
R: Into<IndexRange>,
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);
Sourcepub fn source_ref(&self) -> &S
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>
impl<T: Clone, S: Clone> Clone for MatrixMask<T, S>
Source§fn clone(&self) -> MatrixMask<T, S>
fn clone(&self) -> MatrixMask<T, S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T, S> MatrixMut<T> for MatrixMask<T, S>where
S: MatrixMut<T>,
A MatrixMask of a MatrixMut type implements MatrixMut.
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>
fn try_get_reference_mut(&mut self, row: Row, column: Column) -> Option<&mut T>
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
Source§impl<T, S> MatrixRef<T> for MatrixMask<T, S>where
S: MatrixRef<T>,
A MatrixMask of a MatrixRef type implements MatrixRef.
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>
fn try_get_reference(&self, row: Row, column: Column) -> Option<&T>
Source§fn view_rows(&self) -> Row
fn view_rows(&self) -> Row
Source§fn view_columns(&self) -> Column
fn view_columns(&self) -> Column
Source§unsafe fn get_reference_unchecked(&self, row: Row, column: Column) -> &T
unsafe fn get_reference_unchecked(&self, row: Row, column: Column) -> &T
Source§fn data_layout(&self) -> DataLayout
fn data_layout(&self) -> DataLayout
impl<T, S> NoInteriorMutability for MatrixMask<T, S>where
S: NoInteriorMutability,
A MatrixMask of a NoInteriorMutability type implements NoInteriorMutability.