pub struct MatrixRange<T, S> { /* private fields */ }
Expand description
A 2 dimensional range over a matrix, hiding the values outside the range from view.
The entire source is still owned by the MatrixRange however, so this does not permit creating multiple mutable ranges into a single matrix even if they wouldn’t overlap.
For non overlapping mutable ranges into a single matrix see
partition
.
See also: MatrixMask
Implementations§
Source§impl<T, S> MatrixRange<T, S>where
S: MatrixRef<T>,
impl<T, S> MatrixRange<T, S>where
S: MatrixRef<T>,
Sourcepub fn from<R>(source: S, rows: R, columns: R) -> MatrixRange<T, S>where
R: Into<IndexRange>,
pub fn from<R>(source: S, rows: R, columns: R) -> MatrixRange<T, S>where
R: Into<IndexRange>,
Creates a new MatrixRange giving a view of only the data within the row and column IndexRanges.
§Examples
Creating a view and manipulating a matrix from it.
use easy_ml::matrices::Matrix;
use easy_ml::matrices::views::{MatrixView, MatrixRange};
let mut matrix = Matrix::from(vec![
vec![ 2, 3, 4 ],
vec![ 5, 1, 8 ]]);
{
let mut view = MatrixView::from(MatrixRange::from(&mut matrix, 0..1, 1..3));
assert_eq!(vec![3, 4], view.row_major_iter().collect::<Vec<_>>());
view.map_mut(|x| x + 10);
}
assert_eq!(matrix, Matrix::from(vec![
vec![ 2, 13, 14 ],
vec![ 5, 1, 8 ]]));
Various ways to construct a MatrixRange
use easy_ml::matrices::Matrix;
use easy_ml::matrices::views::{IndexRange, MatrixRange};
let matrix = Matrix::from(vec![vec![1]]);
let index_range = MatrixRange::from(&matrix, IndexRange::new(0, 4), IndexRange::new(1, 3));
let tuple = MatrixRange::from(&matrix, (0, 4), (1, 3));
let array = MatrixRange::from(&matrix, [0, 4], [1, 3]);
// Note std::ops::Range is start..end not start and length!
let range = MatrixRange::from(&matrix, 0..4, 1..4);
NOTE: In previous versions (<=1.8.1), this erroneously did not clip the IndexRange input to not exceed the rows and columns of the source, which led to the possibility to create MatrixRanges that reported a greater number of rows and columns in their shape than their actual data. This function will now correctly clip any ranges that exceed their sources.
Sourcepub fn source_ref(&self) -> &S
pub fn source_ref(&self) -> &S
Gives a reference to the MatrixRange’s source (in which the data is not clipped).
Trait Implementations§
Source§impl<T: Clone, S: Clone> Clone for MatrixRange<T, S>
impl<T: Clone, S: Clone> Clone for MatrixRange<T, S>
Source§fn clone(&self) -> MatrixRange<T, S>
fn clone(&self) -> MatrixRange<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 MatrixRange<T, S>where
S: MatrixMut<T>,
A MatrixRange of a MatrixMut type implements MatrixMut.
impl<T, S> MatrixMut<T> for MatrixRange<T, S>where
S: MatrixMut<T>,
A MatrixRange 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 MatrixRange<T, S>where
S: MatrixRef<T>,
A MatrixRange of a MatrixRef type implements MatrixRef.
impl<T, S> MatrixRef<T> for MatrixRange<T, S>where
S: MatrixRef<T>,
A MatrixRange 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 MatrixRange<T, S>where
S: NoInteriorMutability,
A MatrixRange of a NoInteriorMutability type implements NoInteriorMutability.