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

source

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>

source§

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

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> Debug for MatrixRange<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 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>

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

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 stored in the matrix.
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 stored in the matrix.
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 MatrixRange<T, S>

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>

§

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

§

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

§

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

§

impl<T, S> UnwindSafe for MatrixRange<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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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