pub struct MatrixView<T, S> { /* private fields */ }
Expand description

A view into some or all of a matrix.

A MatrixView has a similar relationship to a Matrix as a &str has to a String, or an array slice to an array. A MatrixView cannot resize its source, and may span only a portion of the source Matrix in each dimension.

However a MatrixView is generic not only over the type of the data in the Matrix, but also over the way the Matrix is ‘sliced’ and the two are orthogonal to each other.

MatrixView closely mirrors the API of Matrix, minus resizing methods which are not available. Methods that create a new matrix do not return a MatrixView, they return a Matrix.

Implementations

MatrixView methods which require only read access via a MatrixRef source.

Creates a MatrixView from a source of some type.

The lifetime of the source determines the lifetime of the MatrixView created. If the MatrixView is created from a reference to a Matrix, then the MatrixView cannot live longer than the Matrix referenced.

Consumes the matrix view, yielding the source it was created from.

Gives a reference to the matrix view’s source. This should typically not be needed since Easy ML APIs which take MatrixRefs as inputs like iterators are already wrapped for you as methods on MatrixView.

Gives a mutable reference to the matrix view’s source. This should typically not be needed since Easy ML APIs which take MatrixRefs as inputs like iterators are already wrapped for you as methods on MatrixView.

Returns the dimensionality of this matrix view in Row, Column format

Gets the number of rows visible to this matrix view.

Gets the number of columns visible to this matrix view.

Gets the data layout this MatrixView’s source uses to store its data.

See Matrix layout and iterator performance

Gets a reference to the value at this row and column. Rows and Columns are 0 indexed.

Panics

Panics if the index is out of range.

Gets a reference to the value at the row and column if the index is in range. Otherwise returns None.

Gets a reference to the value at the index without doing any bounds checking. For a safe alternative see try_get_reference.

Safety

Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used. Valid indexes are defined as in MatrixRef.

Returns an iterator over references to a column vector in this matrix view. Columns are 0 indexed.

Panics

Panics if the column is not visible to this view.

Returns an iterator over references to a row vector in this matrix view. Rows are 0 indexed.

Panics

Panics if the row is not visible to this view.

Returns a column major iterator over references to all values in this matrix view, proceeding through each column in order.

Returns a row major iterator over references to all values in this matrix view, proceeding through each row in order.

Returns an iterator over references to the main diagonal in this matrix view.

MatrixView methods which require only read access via a MatrixRef source and a clonable type.

Gets a copy of the value at this row and column. Rows and Columns are 0 indexed.

Panics

Panics if the index is out of range.

Returns an iterator over a column vector in this matrix view. Columns are 0 indexed.

If you have a matrix such as:

[
   1, 2, 3
   4, 5, 6
   7, 8, 9
]

then a column of 0, 1, and 2 will yield [1, 4, 7], [2, 5, 8] and [3, 6, 9] respectively. If you do not need to copy the elements use column_reference_iter instead.

Panics

Panics if the column does not exist in this matrix.

Returns an iterator over a row vector in this matrix view. Rows are 0 indexed.

If you have a matrix such as:

[
   1, 2, 3
   4, 5, 6
   7, 8, 9
]

then a row of 0, 1, and 2 will yield [1, 2, 3], [4, 5, 6] and [7, 8, 9] respectively. If you do not need to copy the elements use row_reference_iter instead.

Panics

Panics if the row does not exist in this matrix.

Returns a column major iterator over all values in this matrix view, proceeding through each column in order.

If you have a matrix such as:

[
   1, 2
   3, 4
]

then the iterator will yield [1, 3, 2, 4]. If you do not need to copy the elements use column_major_reference_iter instead.

Returns a row major iterator over all values in this matrix view, proceeding through each row in order.

If you have a matrix such as:

[
   1, 2
   3, 4
]

then the iterator will yield [1, 2, 3, 4]. If you do not need to copy the elements use row_major_reference_iter instead.

Returns a iterator over the main diagonal of this matrix view.

If you have a matrix such as:

[
   1, 2
   3, 4
]

then the iterator will yield [1, 4]. If you do not need to copy the elements use diagonal_reference_iter instead.

Examples

Computing a trace

use easy_ml::matrices::Matrix;
use easy_ml::matrices::views::MatrixView;
let view = MatrixView::from(Matrix::from(vec![
    vec![ 1, 2, 3 ],
    vec![ 4, 5, 6 ],
    vec![ 7, 8, 9 ],
]));
let trace: i32 = view.diagonal_iter().sum();
assert_eq!(trace, 1 + 5 + 9);

Creates and returns a new matrix with all values from the original with the function applied to each.

Exmples
use easy_ml::matrices::Matrix;
use easy_ml::matrices::views::MatrixView;
let x = MatrixView::from(Matrix::from(vec![
   vec![ 0.0, 1.2 ],
   vec![ 5.8, 6.9 ]]));
let y = x.map(|element| element > 2.0);
let result = Matrix::from(vec![
   vec![ false, false ],
   vec![ true, true ]]);
assert_eq!(&y, &result);

Creates and returns a new matrix with all values from the original and the index of each value mapped by a function. This can be used to perform elementwise operations that are not defined on the Matrix type itself.

MatrixView methods which require mutable access via a MatrixMut source.

Gets a mutable reference to the value at this row and column. Rows and Columns are 0 indexed.

Panics

Panics if the index is out of range.

Sets a new value to this row and column. Rows and Columns are 0 indexed.

Panics

Panics if the index is out of range.

Gets a mutable reference to the value at the row and column if the index is in range. Otherwise returns None.

Gets a mutable reference to the value at the index without doing any bounds checking. For a safe alternative see try_get_reference_mut.

Safety

Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used. Valid indexes are defined as in MatrixRef.

MatrixView methods which require mutable access via a MatrixMut source and no interior mutability.

Returns an iterator over mutable references to a column vector in this matrix view. Columns are 0 indexed.

Panics

Panics if the column is not visible to this view.

Returns an iterator over mutable references to a row vector in this matrix view. Rows are 0 indexed.

Panics

Panics if the row is not visible to this view.

Returns a column major iterator over mutable references to all values in this matrix view, proceeding through each column in order.

Returns a row major iterator over mutable references to all values in this matrix view, proceeding through each row in order.

Returns an iterator over mutable references to the main diagonal in this matrix view.

MatrixView methods which require mutable access via a MatrixMut source and a clonable type.

Applies a function to all values in the matrix view, modifying the source in place.

Examples
use easy_ml::matrices::Matrix;
use easy_ml::matrices::views::MatrixView;
let mut matrix = Matrix::from(vec![
   vec![ 0.0, 1.2 ],
   vec![ 5.8, 6.9 ]]);
{
   let mut view = MatrixView::from(&mut matrix);
   view.map_mut(|x| x + 1.0);
}
let result = Matrix::from(vec![
   vec![ 1.0, 2.2 ],
   vec![ 6.8, 7.9 ]]);
assert_eq!(result, matrix);

Applies a function to all values and each value’s index in the matrix view, modifying the source in place.

Trait Implementations

Elementwise addition for a referenced matrix view and a referenced matrix

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for a matrix view and a referenced matrix

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for a referenced matrix and a referenced matrix view

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for a matrix and a referenced matrix view

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for two referenced matrix views

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for two matrix views with one referenced

The resulting type after applying the + operator.

Performs the + operation. Read more

Operation for a matrix view and scalar by reference. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the + operator.

Performs the + operation. Read more

Operation for a matrix viiew by value and scalar by reference. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for a referenced matrix view and a matrix

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for a matrix view and a matrix

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for a referenced matrix and a matrix view

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for a matrix and a matrix view

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for two matrix views with one referenced

The resulting type after applying the + operator.

Performs the + operation. Read more

Elementwise addition for two matrix views

The resulting type after applying the + operator.

Performs the + operation. Read more

Operation for a matrix view by reference and scalar by value. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the + operator.

Performs the + operation. Read more

Operation for a matrix view and scalar by value. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Any matrix view of a Displayable type implements Display

Formats the value using the given formatter. Read more

Operation for a matrix view and scalar by reference. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the / operator.

Performs the / operation. Read more

Operation for a matrix viiew by value and scalar by reference. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the / operator.

Performs the / operation. Read more

Operation for a matrix view by reference and scalar by value. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the / operator.

Performs the / operation. Read more

Operation for a matrix view and scalar by value. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the / operator.

Performs the / operation. Read more

Matrix multiplication for a referenced matrix view and a referenced matrix

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for a matrix view and a referenced matrix

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for a referenced matrix and a referenced matrix view

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for a matrix and a referenced matrix view

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for two referenced matrix views

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for two matrix views with one referenced

The resulting type after applying the * operator.

Performs the * operation. Read more

Operation for a matrix view and scalar by reference. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the * operator.

Performs the * operation. Read more

Operation for a matrix viiew by value and scalar by reference. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for a referenced matrix view and a matrix

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for a matrix view and a matrix

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for a referenced matrix and a matrix view

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for a matrix and a matrix view

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for two matrix views with one referenced

The resulting type after applying the * operator.

Performs the * operation. Read more

Matrix multiplication for two matrix views

The resulting type after applying the * operator.

Performs the * operation. Read more

Operation for a matrix view by reference and scalar by value. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the * operator.

Performs the * operation. Read more

Operation for a matrix view and scalar by value. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the * operator.

Performs the * operation. Read more

Elementwise negation for a referenced matrix view.

The resulting type after applying the - operator.

Performs the unary - operation. Read more

Elementwise negation for a matrix view.

The resulting type after applying the - operator.

Performs the unary - operation. Read more

A MatrixView and a Matrix can be compared for equality. PartialEq is implemented as they are equal if and only if all their elements are equal and they have the same size.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

A Matrix and a MatrixView can be compared for equality. PartialEq is implemented as they are equal if and only if all their elements are equal and they have the same size.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

PartialEq is implemented as two matrix views are equal if and only if all their elements are equal and they have the same size. Differences in their source types are ignored.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Elementwise subtraction for a referenced matrix view and a referenced matrix

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for a matrix view and a referenced matrix

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for a referenced matrix and a referenced matrix view

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for a matrix and a referenced matrix view

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for two referenced matrix views

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise addition for two matrix views with one referenced

The resulting type after applying the - operator.

Performs the - operation. Read more

Operation for a matrix view and scalar by reference. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the - operator.

Performs the - operation. Read more

Operation for a matrix viiew by value and scalar by reference. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for a referenced matrix view and a matrix

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for a matrix view and a matrix

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for a referenced matrix and a matrix view

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for a matrix and a matrix view

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for two matrix views with one referenced

The resulting type after applying the - operator.

Performs the - operation. Read more

Elementwise subtraction for two matrix views

The resulting type after applying the - operator.

Performs the - operation. Read more

Operation for a matrix view by reference and scalar by value. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the - operator.

Performs the - operation. Read more

Operation for a matrix view and scalar by value. The scalar is applied to all elements, this is a shorthand for map().

The resulting type after applying the - operator.

Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.