pub type MatRef<'a, T, Rows = usize, Cols = usize, RStride = isize, CStride = isize> = Mat<Ref<'a, T, Rows, Cols, RStride, CStride>>;Expand description
immutable view over a matrix, similar to an immutable reference to a 2d strided slice
§Note
unlike a slice, the data pointed to by MatRef<'_, T> is allowed to be partially or fully
uninitialized under certain conditions. in this case, care must be taken to not perform any
operations that read the uninitialized values, either directly or indirectly through any of the
numerical library routines, unless it is explicitly permitted
Aliased Type§
#[repr(transparent)]pub struct MatRef<'a, T, Rows = usize, Cols = usize, RStride = isize, CStride = isize>(pub Ref<'a, T, Rows, Cols, RStride, CStride>);Tuple Fields§
§0: Ref<'a, T, Rows, Cols, RStride, CStride>Implementations§
Source§impl<'a, T> MatRef<'a, T>
impl<'a, T> MatRef<'a, T>
Sourcepub fn from_row_major_array<const ROWS: usize, const COLS: usize>(
array: &'a [[T; COLS]; ROWS],
) -> Self
pub fn from_row_major_array<const ROWS: usize, const COLS: usize>( array: &'a [[T; COLS]; ROWS], ) -> Self
equivalent to MatRef::from_row_major_slice(array.as_flattened(), ROWS, COLS)
Source§impl<'a, T, Rows: Shape, Cols: Shape> MatRef<'a, T, Rows, Cols>
impl<'a, T, Rows: Shape, Cols: Shape> MatRef<'a, T, Rows, Cols>
Sourcepub fn from_repeated_ref(value: &'a T, nrows: Rows, ncols: Cols) -> Self
pub fn from_repeated_ref(value: &'a T, nrows: Rows, ncols: Cols) -> Self
creates a MatRef from a view over a single element, repeated nrows×ncols times
Sourcepub fn from_column_major_slice(slice: &'a [T], nrows: Rows, ncols: Cols) -> Self
pub fn from_column_major_slice(slice: &'a [T], nrows: Rows, ncols: Cols) -> Self
creates a MatRef from slice views over the matrix data, and the matrix dimensions.
the data is interpreted in a column-major format, so that the first chunk of nrows
values from the slices goes in the first column of the matrix, the second chunk of nrows
values goes in the second column, and so on
§panics
the function panics if any of the following conditions are violated:
nrows * ncols == slice.len()
§example
use faer::{MatRef, mat};
let slice = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0_f64];
let view = MatRef::from_column_major_slice(&slice, 3, 2);
let expected = mat![[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]];
assert_eq!(expected, view);Sourcepub fn from_column_major_slice_with_stride(
slice: &'a [T],
nrows: Rows,
ncols: Cols,
col_stride: usize,
) -> Self
pub fn from_column_major_slice_with_stride( slice: &'a [T], nrows: Rows, ncols: Cols, col_stride: usize, ) -> Self
creates a MatRef from slice views over the matrix data, and the matrix dimensions.
the data is interpreted in a column-major format, where the beginnings of two consecutive
columns are separated by col_stride elements
Sourcepub fn from_row_major_slice(slice: &'a [T], nrows: Rows, ncols: Cols) -> Self
pub fn from_row_major_slice(slice: &'a [T], nrows: Rows, ncols: Cols) -> Self
creates a MatRef from slice views over the matrix data, and the matrix dimensions.
the data is interpreted in a row-major format, so that the first chunk of ncols
values from the slices goes in the first column of the matrix, the second chunk of ncols
values goes in the second column, and so on
§panics
the function panics if any of the following conditions are violated:
nrows * ncols == slice.len()
§example
use faer::{MatRef, mat};
let slice = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0_f64];
let view = MatRef::from_row_major_slice(&slice, 3, 2);
let expected = mat![[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];
assert_eq!(expected, view);Sourcepub fn from_row_major_slice_with_stride(
slice: &'a [T],
nrows: Rows,
ncols: Cols,
row_stride: usize,
) -> Self
pub fn from_row_major_slice_with_stride( slice: &'a [T], nrows: Rows, ncols: Cols, row_stride: usize, ) -> Self
creates a MatRef from slice views over the matrix data, and the matrix dimensions.
the data is interpreted in a row-major format, where the beginnings of two consecutive
rows are separated by row_stride elements
Source§impl<'a, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> MatRef<'a, T, Rows, Cols, RStride, CStride>
impl<'a, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> MatRef<'a, T, Rows, Cols, RStride, CStride>
Sourcepub const unsafe fn from_raw_parts(
ptr: *const T,
nrows: Rows,
ncols: Cols,
row_stride: RStride,
col_stride: CStride,
) -> Self
pub const unsafe fn from_raw_parts( ptr: *const T, nrows: Rows, ncols: Cols, row_stride: RStride, col_stride: CStride, ) -> Self
creates a MatRef from a pointer to the matrix data, dimensions, and strides
the row (resp. column) stride is the offset from the memory address of a given matrix
element at index (row: i, col: j), to the memory address of the matrix element at
index (row: i + 1, col: 0) (resp. (row: 0, col: i + 1)). this offset is specified in
number of elements, not in bytes
§safety
the behavior is undefined if any of the following conditions are violated:
- for each matrix unit, the entire memory region addressed by the matrix must be contained
within a single allocation, accessible in its entirety by the corresponding pointer in
ptr - for each matrix unit, the corresponding pointer must be properly aligned, even for a zero-sized matrix
- the values accessible by the matrix must be initialized at some point before they are read, or references to them are formed
- no mutable aliasing is allowed. in other words, none of the elements accessible by any
matrix unit may be accessed for writes by any other means for the duration of the lifetime
'a
§example
use faer::{MatRef, mat};
// row major matrix with 2 rows, 3 columns, with a column at the end that we want to skip.
// the row stride is the pointer offset from the address of 1.0 to the address of 4.0,
// which is 4
// the column stride is the pointer offset from the address of 1.0 to the address of 2.0,
// which is 1
let data = [[1.0, 2.0, 3.0, f64::NAN], [4.0, 5.0, 6.0, f64::NAN]];
let matrix = unsafe { MatRef::from_raw_parts(data.as_ptr() as *const f64, 2, 3, 4, 1) };
let expected = mat![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
assert_eq!(expected.as_ref(), matrix);Sourcepub fn shape(&self) -> (Rows, Cols)
pub fn shape(&self) -> (Rows, Cols)
returns the number of rows and columns of the matrix
Sourcepub fn row_stride(&self) -> RStride
pub fn row_stride(&self) -> RStride
returns the row stride of the matrix, specified in number of elements, not in bytes
Sourcepub fn col_stride(&self) -> CStride
pub fn col_stride(&self) -> CStride
returns the column stride of the matrix, specified in number of elements, not in bytes
Sourcepub fn ptr_at(&self, row: IdxInc<Rows>, col: IdxInc<Cols>) -> *const T
pub fn ptr_at(&self, row: IdxInc<Rows>, col: IdxInc<Cols>) -> *const T
returns a raw pointer to the element at the given index
Sourcepub unsafe fn ptr_inbounds_at(&self, row: Idx<Rows>, col: Idx<Cols>) -> *const T
pub unsafe fn ptr_inbounds_at(&self, row: Idx<Rows>, col: Idx<Cols>) -> *const T
returns a raw pointer to the element at the given index, assuming the provided index is within the matrix bounds
§safety
the behavior is undefined if any of the following conditions are violated:
row < self.nrows()col < self.ncols()
Sourcepub fn split_at(
self,
row: IdxInc<Rows>,
col: IdxInc<Cols>,
) -> (MatRef<'a, T, usize, usize, RStride, CStride>, MatRef<'a, T, usize, usize, RStride, CStride>, MatRef<'a, T, usize, usize, RStride, CStride>, MatRef<'a, T, usize, usize, RStride, CStride>)
pub fn split_at( self, row: IdxInc<Rows>, col: IdxInc<Cols>, ) -> (MatRef<'a, T, usize, usize, RStride, CStride>, MatRef<'a, T, usize, usize, RStride, CStride>, MatRef<'a, T, usize, usize, RStride, CStride>, MatRef<'a, T, usize, usize, RStride, CStride>)
splits the matrix horizontally and vertically at the given index into four corners and returns an array of each submatrix, in the following order:
- top left
- top right
- bottom left
- bottom right
§safety
the function panics if any of the following conditions are violated:
row <= self.nrows()col <= self.ncols()
Sourcepub fn split_at_row(
self,
row: IdxInc<Rows>,
) -> (MatRef<'a, T, usize, Cols, RStride, CStride>, MatRef<'a, T, usize, Cols, RStride, CStride>)
pub fn split_at_row( self, row: IdxInc<Rows>, ) -> (MatRef<'a, T, usize, Cols, RStride, CStride>, MatRef<'a, T, usize, Cols, RStride, CStride>)
splits the matrix horizontally at the given row into two parts and returns an array of each submatrix, in the following order:
- top
- bottom
§panics
the function panics if the following condition is violated:
row <= self.nrows()
Sourcepub fn split_at_col(
self,
col: IdxInc<Cols>,
) -> (MatRef<'a, T, Rows, usize, RStride, CStride>, MatRef<'a, T, Rows, usize, RStride, CStride>)
pub fn split_at_col( self, col: IdxInc<Cols>, ) -> (MatRef<'a, T, Rows, usize, RStride, CStride>, MatRef<'a, T, Rows, usize, RStride, CStride>)
splits the matrix vertically at the given column into two parts and returns an array of each submatrix, in the following order:
- left
- right
§panics
the function panics if the following condition is violated:
col <= self.ncols()
Sourcepub fn transpose(self) -> MatRef<'a, T, Cols, Rows, CStride, RStride>
pub fn transpose(self) -> MatRef<'a, T, Cols, Rows, CStride, RStride>
returns a view over the transpose of self
§example
use faer::mat;
let matrix = mat![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
let view = matrix.as_ref();
let transpose = view.transpose();
let expected = mat![[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]];
assert_eq!(expected.as_ref(), transpose);Sourcepub fn conjugate(self) -> MatRef<'a, T::Conj, Rows, Cols, RStride, CStride>where
T: Conjugate,
pub fn conjugate(self) -> MatRef<'a, T::Conj, Rows, Cols, RStride, CStride>where
T: Conjugate,
returns a view over the conjugate of self
Sourcepub fn canonical(self) -> MatRef<'a, T::Canonical, Rows, Cols, RStride, CStride>where
T: Conjugate,
pub fn canonical(self) -> MatRef<'a, T::Canonical, Rows, Cols, RStride, CStride>where
T: Conjugate,
returns an unconjugated view over self
Sourcepub fn adjoint(self) -> MatRef<'a, T::Conj, Cols, Rows, CStride, RStride>where
T: Conjugate,
pub fn adjoint(self) -> MatRef<'a, T::Conj, Cols, Rows, CStride, RStride>where
T: Conjugate,
returns a view over the conjugate transpose of self.
Sourcepub fn reverse_rows(self) -> MatRef<'a, T, Rows, Cols, RStride::Rev, CStride>
pub fn reverse_rows(self) -> MatRef<'a, T, Rows, Cols, RStride::Rev, CStride>
returns a view over the self, with the rows in reversed order
§example
use faer::mat;
let matrix = mat![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
let view = matrix.as_ref();
let reversed_rows = view.reverse_rows();
let expected = mat![[4.0, 5.0, 6.0], [1.0, 2.0, 3.0]];
assert_eq!(expected.as_ref(), reversed_rows);Sourcepub fn reverse_cols(self) -> MatRef<'a, T, Rows, Cols, RStride, CStride::Rev>
pub fn reverse_cols(self) -> MatRef<'a, T, Rows, Cols, RStride, CStride::Rev>
returns a view over the self, with the columns in reversed order
§example
use faer::mat;
let matrix = mat![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
let view = matrix.as_ref();
let reversed_cols = view.reverse_cols();
let expected = mat![[3.0, 2.0, 1.0], [6.0, 5.0, 4.0]];
assert_eq!(expected.as_ref(), reversed_cols);Sourcepub fn reverse_rows_and_cols(
self,
) -> MatRef<'a, T, Rows, Cols, RStride::Rev, CStride::Rev>
pub fn reverse_rows_and_cols( self, ) -> MatRef<'a, T, Rows, Cols, RStride::Rev, CStride::Rev>
returns a view over the self, with the rows and the columns in reversed order
§example
use faer::mat;
let matrix = mat![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
let view = matrix.as_ref();
let reversed = view.reverse_rows_and_cols();
let expected = mat![[6.0, 5.0, 4.0], [3.0, 2.0, 1.0]];
assert_eq!(expected.as_ref(), reversed);Sourcepub fn submatrix<V: Shape, H: Shape>(
self,
row_start: IdxInc<Rows>,
col_start: IdxInc<Cols>,
nrows: V,
ncols: H,
) -> MatRef<'a, T, V, H, RStride, CStride>
pub fn submatrix<V: Shape, H: Shape>( self, row_start: IdxInc<Rows>, col_start: IdxInc<Cols>, nrows: V, ncols: H, ) -> MatRef<'a, T, V, H, RStride, CStride>
returns a view over the submatrix starting at index (row_start, col_start), and with
dimensions (nrows, ncols)
§panics
the function panics if any of the following conditions are violated:
row_start <= self.nrows()col_start <= self.ncols()nrows <= self.nrows() - row_startncols <= self.ncols() - col_start
§example
use faer::mat;
let matrix = mat![
[1.0, 5.0, 9.0], //
[2.0, 6.0, 10.0],
[3.0, 7.0, 11.0],
[4.0, 8.0, 12.0f64],
];
let view = matrix.as_ref();
let submatrix = view.submatrix(
/* row_start: */ 2, /* col_start: */ 1, /* nrows: */ 2, /* ncols: */ 2,
);
let expected = mat![[7.0, 11.0], [8.0, 12.0f64]];
assert_eq!(expected.as_ref(), submatrix);Sourcepub fn subrows<V: Shape>(
self,
row_start: IdxInc<Rows>,
nrows: V,
) -> MatRef<'a, T, V, Cols, RStride, CStride>
pub fn subrows<V: Shape>( self, row_start: IdxInc<Rows>, nrows: V, ) -> MatRef<'a, T, V, Cols, RStride, CStride>
returns a view over the submatrix starting at row row_start, and with number of rows
nrows
§panics
the function panics if any of the following conditions are violated:
row_start <= self.nrows()nrows <= self.nrows() - row_start
§example
use faer::mat;
let matrix = mat![
[1.0, 5.0, 9.0], //
[2.0, 6.0, 10.0],
[3.0, 7.0, 11.0],
[4.0, 8.0, 12.0f64],
];
let view = matrix.as_ref();
let subrows = view.subrows(/* row_start: */ 1, /* nrows: */ 2);
let expected = mat![[2.0, 6.0, 10.0], [3.0, 7.0, 11.0],];
assert_eq!(expected.as_ref(), subrows);Sourcepub fn subcols<H: Shape>(
self,
col_start: IdxInc<Cols>,
ncols: H,
) -> MatRef<'a, T, Rows, H, RStride, CStride>
pub fn subcols<H: Shape>( self, col_start: IdxInc<Cols>, ncols: H, ) -> MatRef<'a, T, Rows, H, RStride, CStride>
returns a view over the submatrix starting at column col_start, and with number of
columns ncols
§panics
the function panics if any of the following conditions are violated:
col_start <= self.ncols()ncols <= self.ncols() - col_start
§example
use faer::mat;
let matrix = mat![
[1.0, 5.0, 9.0], //
[2.0, 6.0, 10.0],
[3.0, 7.0, 11.0],
[4.0, 8.0, 12.0f64],
];
let view = matrix.as_ref();
let subcols = view.subcols(/* col_start: */ 2, /* ncols: */ 1);
let expected = mat![[9.0], [10.0], [11.0], [12.0f64]];
assert_eq!(expected.as_ref(), subcols);Sourcepub fn as_shape<V: Shape, H: Shape>(
self,
nrows: V,
ncols: H,
) -> MatRef<'a, T, V, H, RStride, CStride>
pub fn as_shape<V: Shape, H: Shape>( self, nrows: V, ncols: H, ) -> MatRef<'a, T, V, H, RStride, CStride>
returns the input matrix with the given shape after checking that it matches the current shape
Sourcepub fn as_row_shape<V: Shape>(
self,
nrows: V,
) -> MatRef<'a, T, V, Cols, RStride, CStride>
pub fn as_row_shape<V: Shape>( self, nrows: V, ) -> MatRef<'a, T, V, Cols, RStride, CStride>
returns the input matrix with the given row shape after checking that it matches the current row shape
Sourcepub fn as_col_shape<H: Shape>(
self,
ncols: H,
) -> MatRef<'a, T, Rows, H, RStride, CStride>
pub fn as_col_shape<H: Shape>( self, ncols: H, ) -> MatRef<'a, T, Rows, H, RStride, CStride>
returns the input matrix with the given column shape after checking that it matches the current column shape
Sourcepub fn as_dyn_stride(self) -> MatRef<'a, T, Rows, Cols, isize, isize>
pub fn as_dyn_stride(self) -> MatRef<'a, T, Rows, Cols, isize, isize>
returns the input matrix with dynamic stride
Sourcepub fn as_dyn(self) -> MatRef<'a, T, usize, usize, RStride, CStride>
pub fn as_dyn(self) -> MatRef<'a, T, usize, usize, RStride, CStride>
returns the input matrix with dynamic shape
Sourcepub fn as_dyn_rows(self) -> MatRef<'a, T, usize, Cols, RStride, CStride>
pub fn as_dyn_rows(self) -> MatRef<'a, T, usize, Cols, RStride, CStride>
returns the input matrix with dynamic row shape
Sourcepub fn as_dyn_cols(self) -> MatRef<'a, T, Rows, usize, RStride, CStride>
pub fn as_dyn_cols(self) -> MatRef<'a, T, Rows, usize, RStride, CStride>
returns the input matrix with dynamic column shape
Sourcepub fn row(self, i: Idx<Rows>) -> RowRef<'a, T, Cols, CStride>
pub fn row(self, i: Idx<Rows>) -> RowRef<'a, T, Cols, CStride>
returns a view over the row at the given index
§panics
the function panics if any of the following conditions are violated:
row_idx < self.nrows()
Sourcepub fn col(self, j: Idx<Cols>) -> ColRef<'a, T, Rows, RStride>
pub fn col(self, j: Idx<Cols>) -> ColRef<'a, T, Rows, RStride>
returns a view over the column at the given index
§panics
the function panics if any of the following conditions are violated:
col_idx < self.ncols()
Sourcepub fn col_iter(
self,
) -> impl 'a + ExactSizeIterator + DoubleEndedIterator<Item = ColRef<'a, T, Rows, RStride>>where
Rows: 'a,
Cols: 'a,
pub fn col_iter(
self,
) -> impl 'a + ExactSizeIterator + DoubleEndedIterator<Item = ColRef<'a, T, Rows, RStride>>where
Rows: 'a,
Cols: 'a,
returns an iterator over the columns of the matrix
Sourcepub fn row_iter(
self,
) -> impl 'a + ExactSizeIterator + DoubleEndedIterator<Item = RowRef<'a, T, Cols, CStride>>where
Rows: 'a,
Cols: 'a,
pub fn row_iter(
self,
) -> impl 'a + ExactSizeIterator + DoubleEndedIterator<Item = RowRef<'a, T, Cols, CStride>>where
Rows: 'a,
Cols: 'a,
returns an iterator over the rows of the matrix
Sourcepub fn par_col_iter(
self,
) -> impl 'a + IndexedParallelIterator<Item = ColRef<'a, T, Rows, RStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
pub fn par_col_iter(
self,
) -> impl 'a + IndexedParallelIterator<Item = ColRef<'a, T, Rows, RStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
returns a parallel iterator over the columns of the matrix
Sourcepub fn par_row_iter(
self,
) -> impl 'a + IndexedParallelIterator<Item = RowRef<'a, T, Cols, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
pub fn par_row_iter(
self,
) -> impl 'a + IndexedParallelIterator<Item = RowRef<'a, T, Cols, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
returns a parallel iterator over the rows of the matrix
Sourcepub fn par_col_chunks(
self,
chunk_size: usize,
) -> impl 'a + IndexedParallelIterator<Item = MatRef<'a, T, Rows, usize, RStride, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
pub fn par_col_chunks(
self,
chunk_size: usize,
) -> impl 'a + IndexedParallelIterator<Item = MatRef<'a, T, Rows, usize, RStride, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
returns a parallel iterator that provides successive chunks of the columns of this
matrix, with each having at most chunk_size columns
if the number of columns is a multiple of chunk_size, then all chunks have
chunk_size columns
only available with the rayon feature
Sourcepub fn par_col_partition(
self,
count: usize,
) -> impl 'a + IndexedParallelIterator<Item = MatRef<'a, T, Rows, usize, RStride, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
pub fn par_col_partition(
self,
count: usize,
) -> impl 'a + IndexedParallelIterator<Item = MatRef<'a, T, Rows, usize, RStride, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
returns a parallel iterator that provides exactly count successive chunks of the columns
of this matrix
only available with the rayon feature
Sourcepub fn par_row_chunks(
self,
chunk_size: usize,
) -> impl 'a + IndexedParallelIterator<Item = MatRef<'a, T, usize, Cols, RStride, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
pub fn par_row_chunks(
self,
chunk_size: usize,
) -> impl 'a + IndexedParallelIterator<Item = MatRef<'a, T, usize, Cols, RStride, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
returns a parallel iterator that provides successive chunks of the rows of this matrix,
with each having at most chunk_size rows
if the number of rows is a multiple of chunk_size, then all chunks have chunk_size
rows
only available with the rayon feature
Sourcepub fn par_row_partition(
self,
count: usize,
) -> impl 'a + IndexedParallelIterator<Item = MatRef<'a, T, usize, Cols, RStride, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
pub fn par_row_partition(
self,
count: usize,
) -> impl 'a + IndexedParallelIterator<Item = MatRef<'a, T, usize, Cols, RStride, CStride>>where
T: Sync,
Rows: 'a,
Cols: 'a,
returns a parallel iterator that provides exactly count successive chunks of the rows
of this matrix
only available with the rayon feature
Sourcepub fn split_first_row(
self,
) -> Option<(RowRef<'a, T, Cols, CStride>, MatRef<'a, T, usize, Cols, RStride, CStride>)>
pub fn split_first_row( self, ) -> Option<(RowRef<'a, T, Cols, CStride>, MatRef<'a, T, usize, Cols, RStride, CStride>)>
returns a reference to the first row and a view over the remaining ones if the matrix has
at least one row, otherwise None
Sourcepub fn split_first_col(
self,
) -> Option<(ColRef<'a, T, Rows, RStride>, MatRef<'a, T, Rows, usize, RStride, CStride>)>
pub fn split_first_col( self, ) -> Option<(ColRef<'a, T, Rows, RStride>, MatRef<'a, T, Rows, usize, RStride, CStride>)>
returns a reference to the first column and a view over the remaining ones if the matrix has
at least one column, otherwise None
Sourcepub fn split_last_row(
self,
) -> Option<(RowRef<'a, T, Cols, CStride>, MatRef<'a, T, usize, Cols, RStride, CStride>)>
pub fn split_last_row( self, ) -> Option<(RowRef<'a, T, Cols, CStride>, MatRef<'a, T, usize, Cols, RStride, CStride>)>
returns a reference to the last row and a view over the remaining ones if the matrix has
at least one row, otherwise None
Sourcepub fn split_last_col(
self,
) -> Option<(ColRef<'a, T, Rows, RStride>, MatRef<'a, T, Rows, usize, RStride, CStride>)>
pub fn split_last_col( self, ) -> Option<(ColRef<'a, T, Rows, RStride>, MatRef<'a, T, Rows, usize, RStride, CStride>)>
returns a reference to the last column and a view over the remaining ones if the matrix has
at least one column, otherwise None
Sourcepub fn try_as_row_major(
self,
) -> Option<MatRef<'a, T, Rows, Cols, RStride, ContiguousFwd>>
pub fn try_as_row_major( self, ) -> Option<MatRef<'a, T, Rows, Cols, RStride, ContiguousFwd>>
returns a view over the matrix with a static column stride equal to +1, or None
otherwise
Sourcepub fn try_as_col_major(
self,
) -> Option<MatRef<'a, T, Rows, Cols, ContiguousFwd, CStride>>
pub fn try_as_col_major( self, ) -> Option<MatRef<'a, T, Rows, Cols, ContiguousFwd, CStride>>
returns a view over the matrix with a static row stride equal to +1, or None otherwise
Sourcepub fn get<RowRange, ColRange>(
self,
row: RowRange,
col: ColRange,
) -> <MatRef<'a, T, Rows, Cols, RStride, CStride> as MatIndex<RowRange, ColRange>>::Target
pub fn get<RowRange, ColRange>( self, row: RowRange, col: ColRange, ) -> <MatRef<'a, T, Rows, Cols, RStride, CStride> as MatIndex<RowRange, ColRange>>::Target
returns references to the element at the given index, or submatrices if either row
or col is a range, with bound checks
§panics
the function panics if any of the following conditions are violated:
rowmust be contained in[0, self.nrows())colmust be contained in[0, self.ncols())
Sourcepub fn get_r<RowRange>(
self,
row: RowRange,
) -> <MatRef<'a, T, Rows, Cols, RStride, CStride> as MatIndex<RowRange, RangeFull>>::Target
pub fn get_r<RowRange>( self, row: RowRange, ) -> <MatRef<'a, T, Rows, Cols, RStride, CStride> as MatIndex<RowRange, RangeFull>>::Target
equivalent to self.get(row, ..)
Sourcepub fn get_c<ColRange>(
self,
col: ColRange,
) -> <MatRef<'a, T, Rows, Cols, RStride, CStride> as MatIndex<RangeFull, ColRange>>::Target
pub fn get_c<ColRange>( self, col: ColRange, ) -> <MatRef<'a, T, Rows, Cols, RStride, CStride> as MatIndex<RangeFull, ColRange>>::Target
equivalent to self.get(.., col)
Sourcepub unsafe fn get_unchecked<RowRange, ColRange>(
self,
row: RowRange,
col: ColRange,
) -> <MatRef<'a, T, Rows, Cols, RStride, CStride> as MatIndex<RowRange, ColRange>>::Target
pub unsafe fn get_unchecked<RowRange, ColRange>( self, row: RowRange, col: ColRange, ) -> <MatRef<'a, T, Rows, Cols, RStride, CStride> as MatIndex<RowRange, ColRange>>::Target
returns references to the element at the given index, or submatrices if either row
or col is a range, without bound checks
§safety
the behavior is undefined if any of the following conditions are violated:
rowmust be contained in[0, self.nrows())colmust be contained in[0, self.ncols())
Source§impl<'a, T, Dim: Shape, RStride: Stride, CStride: Stride> MatRef<'a, T, Dim, Dim, RStride, CStride>
impl<'a, T, Dim: Shape, RStride: Stride, CStride: Stride> MatRef<'a, T, Dim, Dim, RStride, CStride>
Source§impl<'a, T, Rows: Shape, Cols: Shape> MatRef<'a, T, Rows, Cols>where
T: RealField,
impl<'a, T, Rows: Shape, Cols: Shape> MatRef<'a, T, Rows, Cols>where
T: RealField,
Sourcepub fn max(self) -> Option<T>
pub fn max(self) -> Option<T>
Returns the maximum element in the matrix
§Returns
Option<T>- The maximum element in the matrix, orNoneif the matrix is empty
§Examples
use faer::{Mat, mat};
let m = mat![[1.0, 5.0, 3.0], [4.0, 2.0, 9.0], [7.0, 8.0, 6.0],];
assert_eq!(m.max(), Some(9.0));
let empty: Mat<f64> = Mat::new();
assert_eq!(empty.max(), None);Sourcepub fn min(self) -> Option<T>
pub fn min(self) -> Option<T>
Returns the minimum element in the matrix
§Returns
Option<T>- The minimum element in the matrix, orNoneif the matrix is empty
§Examples
use faer::{Mat, mat};
let m = mat![[1.0, 5.0, 3.0], [4.0, 2.0, 9.0], [7.0, 8.0, 6.0],];
assert_eq!(m.min(), Some(1.0));
let empty: Mat<f64> = Mat::new();
assert_eq!(empty.min(), None);Trait Implementations§
Source§impl<T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> AsMatRef for MatRef<'_, T, Rows, Cols, RStride, CStride>
impl<T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> AsMatRef for MatRef<'_, T, Rows, Cols, RStride, CStride>
Source§impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> BiLinOp<T> for MatRef<'_, ViewT>
impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> BiLinOp<T> for MatRef<'_, ViewT>
Source§fn transpose_apply_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq
fn transpose_apply_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq
self to a matrix with rhs_ncols columnsSource§impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> BiPrecond<T> for MatRef<'_, ViewT>
impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> BiPrecond<T> for MatRef<'_, ViewT>
Source§fn transpose_apply_in_place_scratch(
&self,
rhs_ncols: usize,
par: Par,
) -> StackReq
fn transpose_apply_in_place_scratch( &self, rhs_ncols: usize, par: Par, ) -> StackReq
self to a matrix with rhs_ncols columns in placeSource§impl<'a, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> IntoView for &'a MatRef<'_, T, Rows, Cols, RStride, CStride>
impl<'a, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> IntoView for &'a MatRef<'_, T, Rows, Cols, RStride, CStride>
Source§impl<'a, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> IntoView for &'a mut MatRef<'_, T, Rows, Cols, RStride, CStride>
impl<'a, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> IntoView for &'a mut MatRef<'_, T, Rows, Cols, RStride, CStride>
Source§impl<'a, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> IntoView for MatRef<'a, T, Rows, Cols, RStride, CStride>
impl<'a, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> IntoView for MatRef<'a, T, Rows, Cols, RStride, CStride>
Source§impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> LinOp<T> for MatRef<'_, ViewT>
impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> LinOp<T> for MatRef<'_, ViewT>
Source§fn apply_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq
fn apply_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq
self or the conjugate o
self to a matrix with rhs_ncols columnsSource§impl<'a, 'M, 'N, T, Rs: Stride, Cs: Stride> MatIndex<<Dim<'M> as ShapeIdx>::Idx<usize>, <Dim<'N> as ShapeIdx>::Idx<usize>> for MatRef<'a, T, Dim<'M>, Dim<'N>, Rs, Cs>
impl<'a, 'M, 'N, T, Rs: Stride, Cs: Stride> MatIndex<<Dim<'M> as ShapeIdx>::Idx<usize>, <Dim<'N> as ShapeIdx>::Idx<usize>> for MatRef<'a, T, Dim<'M>, Dim<'N>, Rs, Cs>
Source§impl<'a, 'M, T, Rs: Stride, Cs: Stride> MatIndex<<Dim<'M> as ShapeIdx>::Idx<usize>, <usize as ShapeIdx>::Idx<usize>> for MatRef<'a, T, Dim<'M>, usize, Rs, Cs>
impl<'a, 'M, T, Rs: Stride, Cs: Stride> MatIndex<<Dim<'M> as ShapeIdx>::Idx<usize>, <usize as ShapeIdx>::Idx<usize>> for MatRef<'a, T, Dim<'M>, usize, Rs, Cs>
Source§impl<'a, 'N, C: Shape, T, Rs: Stride, Cs: Stride, ColRange: IntoRange<IdxInc<C>, Len<C>: 'a>> MatIndex<<Dim<'N> as ShapeIdx>::Idx<usize>, ColRange> for MatRef<'a, T, Dim<'N>, C, Rs, Cs>
impl<'a, 'N, C: Shape, T, Rs: Stride, Cs: Stride, ColRange: IntoRange<IdxInc<C>, Len<C>: 'a>> MatIndex<<Dim<'N> as ShapeIdx>::Idx<usize>, ColRange> for MatRef<'a, T, Dim<'N>, C, Rs, Cs>
Source§impl<'a, 'N, T, Rs: Stride, Cs: Stride> MatIndex<<usize as ShapeIdx>::Idx<usize>, <Dim<'N> as ShapeIdx>::Idx<usize>> for MatRef<'a, T, usize, Dim<'N>, Rs, Cs>
impl<'a, 'N, T, Rs: Stride, Cs: Stride> MatIndex<<usize as ShapeIdx>::Idx<usize>, <Dim<'N> as ShapeIdx>::Idx<usize>> for MatRef<'a, T, usize, Dim<'N>, Rs, Cs>
Source§impl<'a, T, Rs: Stride, Cs: Stride> MatIndex<<usize as ShapeIdx>::Idx<usize>, <usize as ShapeIdx>::Idx<usize>> for MatRef<'a, T, usize, usize, Rs, Cs>
impl<'a, T, Rs: Stride, Cs: Stride> MatIndex<<usize as ShapeIdx>::Idx<usize>, <usize as ShapeIdx>::Idx<usize>> for MatRef<'a, T, usize, usize, Rs, Cs>
Source§impl<'a, C: Shape, T, Rs: Stride, Cs: Stride, ColRange: IntoRange<IdxInc<C>, Len<C>: 'a>> MatIndex<<usize as ShapeIdx>::Idx<usize>, ColRange> for MatRef<'a, T, usize, C, Rs, Cs>
impl<'a, C: Shape, T, Rs: Stride, Cs: Stride, ColRange: IntoRange<IdxInc<C>, Len<C>: 'a>> MatIndex<<usize as ShapeIdx>::Idx<usize>, ColRange> for MatRef<'a, T, usize, C, Rs, Cs>
Source§impl<'a, 'N, R: Shape, T, Rs: Stride, Cs: Stride, RowRange: IntoRange<IdxInc<R>, Len<R>: 'a>> MatIndex<RowRange, <Dim<'N> as ShapeIdx>::Idx<usize>> for MatRef<'a, T, R, Dim<'N>, Rs, Cs>
impl<'a, 'N, R: Shape, T, Rs: Stride, Cs: Stride, RowRange: IntoRange<IdxInc<R>, Len<R>: 'a>> MatIndex<RowRange, <Dim<'N> as ShapeIdx>::Idx<usize>> for MatRef<'a, T, R, Dim<'N>, Rs, Cs>
Source§impl<'a, R: Shape, T, Rs: Stride, Cs: Stride, RowRange: IntoRange<IdxInc<R>, Len<R>: 'a>> MatIndex<RowRange, <usize as ShapeIdx>::Idx<usize>> for MatRef<'a, T, R, usize, Rs, Cs>
impl<'a, R: Shape, T, Rs: Stride, Cs: Stride, RowRange: IntoRange<IdxInc<R>, Len<R>: 'a>> MatIndex<RowRange, <usize as ShapeIdx>::Idx<usize>> for MatRef<'a, T, R, usize, Rs, Cs>
Source§impl<'a, R: Shape, C: Shape, T, Rs: Stride, Cs: Stride, RowRange: IntoRange<IdxInc<R>, Len<R>: 'a>, ColRange: IntoRange<IdxInc<C>, Len<C>: 'a>> MatIndex<RowRange, ColRange> for MatRef<'a, T, R, C, Rs, Cs>
impl<'a, R: Shape, C: Shape, T, Rs: Stride, Cs: Stride, RowRange: IntoRange<IdxInc<R>, Len<R>: 'a>, ColRange: IntoRange<IdxInc<C>, Len<C>: 'a>> MatIndex<RowRange, ColRange> for MatRef<'a, T, R, C, Rs, Cs>
Source§type Target = Mat<Ref<'a, T, <RowRange as IntoRange<<R as ShapeIdx>::IdxInc<usize>>>::Len<R>, <ColRange as IntoRange<<C as ShapeIdx>::IdxInc<usize>>>::Len<C>, Rs, Cs>>
type Target = Mat<Ref<'a, T, <RowRange as IntoRange<<R as ShapeIdx>::IdxInc<usize>>>::Len<R>, <ColRange as IntoRange<<C as ShapeIdx>::IdxInc<usize>>>::Len<C>, Rs, Cs>>
Source§unsafe fn get_unchecked(
this: Self,
row: RowRange,
col: ColRange,
) -> Self::Target
unsafe fn get_unchecked( this: Self, row: RowRange, col: ColRange, ) -> Self::Target
this using row and col without bound checksSource§impl<'b, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> MatIndex for MatRef<'b, T, Rows, Cols, RStride, CStride>
impl<'b, T, Rows: Shape, Cols: Shape, RStride: Stride, CStride: Stride> MatIndex for MatRef<'b, T, Rows, Cols, RStride, CStride>
type Kind = Mat
Source§type LayoutTransform = MatLayoutTransform
type LayoutTransform = MatLayoutTransform
type Slice = SliceRef<'b, T>
Source§unsafe fn get_slice_unchecked<'a>(
this: &'a mut Self,
idx: Self::Index,
n_elems: usize,
) -> <Self::Slice as SliceFamily<'a, Self::Item>>::Slice
unsafe fn get_slice_unchecked<'a>( this: &'a mut Self, idx: Self::Index, n_elems: usize, ) -> <Self::Slice as SliceFamily<'a, Self::Item>>::Slice
n_elemsSource§unsafe fn from_dyn_idx(idx: <Self::Dyn as MatIndex>::Index) -> Self::Index
unsafe fn from_dyn_idx(idx: <Self::Dyn as MatIndex>::Index) -> Self::Index
Source§unsafe fn get_unchecked(this: &mut Self, (i, j): Self::Index) -> Self::Item
unsafe fn get_unchecked(this: &mut Self, (i, j): Self::Index) -> Self::Item
Source§unsafe fn next_unchecked<'a>(
slice: &mut <Self::Slice as SliceFamily<'a, Self::Item>>::Slice,
) -> Self::Item
unsafe fn next_unchecked<'a>( slice: &mut <Self::Slice as SliceFamily<'a, Self::Item>>::Slice, ) -> Self::Item
Source§fn is_contiguous(this: &Self) -> bool
fn is_contiguous(this: &Self) -> bool
Source§fn preferred_layout(this: &Self) -> Self::LayoutTransform
fn preferred_layout(this: &Self) -> Self::LayoutTransform
Source§fn with_layout(this: Self, layout: Self::LayoutTransform) -> Self::Dyn
fn with_layout(this: Self, layout: Self::LayoutTransform) -> Self::Dyn
Source§impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> Precond<T> for MatRef<'_, ViewT>
impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> Precond<T> for MatRef<'_, ViewT>
Source§fn apply_in_place_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq
fn apply_in_place_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq
self or the conjugate of
self to a matrix with rhs_ncols columns in place