Struct MatrixRange

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

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.

Source

pub fn source(self) -> S

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

Source

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>

Source§

fn clone(&self) -> MatrixRange<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 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 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 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§

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.