Struct easy_ml::matrices::views::MatrixRange
source · pub struct MatrixRange<T, S> { /* private fields */ }
Expand description
A 2 dimensional range over a matrix, hiding the rest of the matrix data 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
.
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.
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>,
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>,
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.
Auto Trait Implementations§
impl<T, S> Freeze for MatrixRange<T, S>where
S: Freeze,
impl<T, S> RefUnwindSafe for MatrixRange<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for MatrixRange<T, S>
impl<T, S> Sync for MatrixRange<T, S>
impl<T, S> Unpin for MatrixRange<T, S>
impl<T, S> UnwindSafe for MatrixRange<T, S>where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)