pub type Mat<E> = Matrix<DenseOwn<E>>;Expand description
Heap allocated resizable matrix, similar to a 2D Vec.
§Note
The memory layout of Mat is guaranteed to be column-major, meaning that it has a row stride
of 1, and an unspecified column stride that can be queried with Mat::col_stride.
This implies that while each individual column is stored contiguously in memory, the matrix as a whole may not necessarily be contiguous. The implementation may add padding at the end of each column when overaligning each column can provide a performance gain.
Let us consider a 3×4 matrix
0 │ 3 │ 6 │ 9
───┼───┼───┼───
1 │ 4 │ 7 │ 10
───┼───┼───┼───
2 │ 5 │ 8 │ 11The memory representation of the data held by such a matrix could look like the following:
0 1 2 X 3 4 5 X 6 7 8 X 9 10 11 Xwhere X represents padding elements.
Aliased Type§
pub struct Mat<E> { /* private fields */ }Implementations§
Source§impl<E: Entity> Mat<E>
impl<E: Entity> Mat<E>
Sourcepub fn with_capacity(row_capacity: usize, col_capacity: usize) -> Self
pub fn with_capacity(row_capacity: usize, col_capacity: usize) -> Self
Returns a new matrix with dimensions (0, 0), with enough capacity to hold a maximum of
row_capacity rows and col_capacity columns without reallocating. If either is 0,
the matrix will not allocate.
§Panics
The function panics if the total capacity in bytes exceeds isize::MAX.
Sourcepub fn from_fn(
nrows: usize,
ncols: usize,
f: impl FnMut(usize, usize) -> E,
) -> Self
pub fn from_fn( nrows: usize, ncols: usize, f: impl FnMut(usize, usize) -> E, ) -> Self
Returns a new matrix with dimensions (nrows, ncols), filled with the provided function.
§Panics
The function panics if the total capacity in bytes exceeds isize::MAX.
Sourcepub fn zeros(nrows: usize, ncols: usize) -> Selfwhere
E: ComplexField,
pub fn zeros(nrows: usize, ncols: usize) -> Selfwhere
E: ComplexField,
Returns a new matrix with dimensions (nrows, ncols), filled with zeros.
§Panics
The function panics if the total capacity in bytes exceeds isize::MAX.
Sourcepub fn identity(nrows: usize, ncols: usize) -> Selfwhere
E: ComplexField,
pub fn identity(nrows: usize, ncols: usize) -> Selfwhere
E: ComplexField,
Returns a new matrix with dimensions (nrows, ncols), filled with zeros, except the main
diagonal which is filled with ones.
§Panics
The function panics if the total capacity in bytes exceeds isize::MAX.
Sourcepub unsafe fn set_dims(&mut self, nrows: usize, ncols: usize)
pub unsafe fn set_dims(&mut self, nrows: usize, ncols: usize)
Set the dimensions of the matrix.
§Safety
The behavior is undefined if any of the following conditions are violated:
nrows < self.row_capacity().ncols < self.col_capacity().- The elements that were previously out of bounds but are now in bounds must be initialized.
Sourcepub fn as_ptr(&self) -> GroupFor<E, *const E::Unit>
pub fn as_ptr(&self) -> GroupFor<E, *const E::Unit>
Returns a pointer to the data of the matrix.
Sourcepub fn as_ptr_mut(&mut self) -> GroupFor<E, *mut E::Unit>
pub fn as_ptr_mut(&mut self) -> GroupFor<E, *mut E::Unit>
Returns a mutable pointer to the data of the matrix.
Sourcepub fn row_capacity(&self) -> usize
pub fn row_capacity(&self) -> usize
Returns the row capacity, that is, the number of rows that the matrix is able to hold without needing to reallocate, excluding column insertions.
Sourcepub fn col_capacity(&self) -> usize
pub fn col_capacity(&self) -> usize
Returns the column capacity, that is, the number of columns that the matrix is able to hold without needing to reallocate, excluding row insertions.
Sourcepub fn row_stride(&self) -> isize
pub fn row_stride(&self) -> isize
Returns the offset between the first elements of two successive rows in the matrix.
Always returns 1 since the matrix is column major.
Sourcepub fn col_stride(&self) -> isize
pub fn col_stride(&self) -> isize
Returns the offset between the first elements of two successive columns in the matrix.
Sourcepub fn reserve_exact(&mut self, row_capacity: usize, col_capacity: usize)
pub fn reserve_exact(&mut self, row_capacity: usize, col_capacity: usize)
Reserves the minimum capacity for row_capacity rows and col_capacity
columns without reallocating. Does nothing if the capacity is already sufficient.
§Panics
The function panics if the new total capacity in bytes exceeds isize::MAX.
Sourcepub fn resize_with(
&mut self,
new_nrows: usize,
new_ncols: usize,
f: impl FnMut(usize, usize) -> E,
)
pub fn resize_with( &mut self, new_nrows: usize, new_ncols: usize, f: impl FnMut(usize, usize) -> E, )
Resizes the matrix in-place so that the new dimensions are (new_nrows, new_ncols).
New elements are created with the given function f, so that elements at indices (i, j)
are created by calling f(i, j).
Sourcepub fn col_as_slice(&self, col: usize) -> GroupFor<E, &[E::Unit]>
pub fn col_as_slice(&self, col: usize) -> GroupFor<E, &[E::Unit]>
Returns a reference to a slice over the column at the given index.
Sourcepub fn col_as_slice_mut(&mut self, col: usize) -> GroupFor<E, &mut [E::Unit]>
pub fn col_as_slice_mut(&mut self, col: usize) -> GroupFor<E, &mut [E::Unit]>
Returns a mutable reference to a slice over the column at the given index.
Sourcepub fn col_ref(&self, col: usize) -> GroupFor<E, &[E::Unit]>
👎Deprecated: replaced by Mat::col_as_slice
pub fn col_ref(&self, col: usize) -> GroupFor<E, &[E::Unit]>
Mat::col_as_sliceReturns a reference to a slice over the column at the given index.
Sourcepub fn col_mut(&mut self, col: usize) -> GroupFor<E, &mut [E::Unit]>
👎Deprecated: replaced by Mat::col_as_slice_mut
pub fn col_mut(&mut self, col: usize) -> GroupFor<E, &mut [E::Unit]>
Mat::col_as_slice_mutReturns a mutable reference to a slice over the column at the given index.
Sourcepub unsafe fn get_unchecked<RowRange, ColRange>(
&self,
row: RowRange,
col: ColRange,
) -> <MatRef<'_, E> as MatIndex<RowRange, ColRange>>::Target
pub unsafe fn get_unchecked<RowRange, ColRange>( &self, row: RowRange, col: ColRange, ) -> <MatRef<'_, E> as MatIndex<RowRange, ColRange>>::Target
Returns references to the element at the given indices, or submatrices if either row or
col is a range.
§Note
The values pointed to by the references are expected to be initialized, even if the pointed-to value is not read, otherwise the behavior is undefined.
§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()).
Sourcepub fn get<RowRange, ColRange>(
&self,
row: RowRange,
col: ColRange,
) -> <MatRef<'_, E> as MatIndex<RowRange, ColRange>>::Target
pub fn get<RowRange, ColRange>( &self, row: RowRange, col: ColRange, ) -> <MatRef<'_, E> as MatIndex<RowRange, ColRange>>::Target
Returns references to the element at the given indices, or submatrices if either row or
col is a range, with bound checks.
§Note
The values pointed to by the references are expected to be initialized, even if the pointed-to value is not read, otherwise the behavior is undefined.
§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 unsafe fn get_mut_unchecked<RowRange, ColRange>(
&mut self,
row: RowRange,
col: ColRange,
) -> <MatMut<'_, E> as MatIndex<RowRange, ColRange>>::Target
pub unsafe fn get_mut_unchecked<RowRange, ColRange>( &mut self, row: RowRange, col: ColRange, ) -> <MatMut<'_, E> as MatIndex<RowRange, ColRange>>::Target
Returns mutable references to the element at the given indices, or submatrices if either
row or col is a range.
§Note
The values pointed to by the references are expected to be initialized, even if the pointed-to value is not read, otherwise the behavior is undefined.
§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()).
Sourcepub fn get_mut<RowRange, ColRange>(
&mut self,
row: RowRange,
col: ColRange,
) -> <MatMut<'_, E> as MatIndex<RowRange, ColRange>>::Target
pub fn get_mut<RowRange, ColRange>( &mut self, row: RowRange, col: ColRange, ) -> <MatMut<'_, E> as MatIndex<RowRange, ColRange>>::Target
Returns mutable references to the element at the given indices, or submatrices if either
row or col is a range, with bound checks.
§Note
The values pointed to by the references are expected to be initialized, even if the pointed-to value is not read, otherwise the behavior is undefined.
§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 unsafe fn read_unchecked(&self, row: usize, col: usize) -> E
pub unsafe fn read_unchecked(&self, row: usize, col: usize) -> E
Reads the value of the element at the given indices.
§Safety
The behavior is undefined if any of the following conditions are violated:
row < self.nrows().col < self.ncols().
Sourcepub fn read(&self, row: usize, col: usize) -> E
pub fn read(&self, row: usize, col: usize) -> E
Reads the value of the element at the given indices, with bound checks.
§Panics
The function panics if any of the following conditions are violated:
row < self.nrows().col < self.ncols().
Sourcepub unsafe fn write_unchecked(&mut self, row: usize, col: usize, value: E)
pub unsafe fn write_unchecked(&mut self, row: usize, col: usize, value: E)
Writes the value to the element at the given indices.
§Safety
The behavior is undefined if any of the following conditions are violated:
row < self.nrows().col < self.ncols().
Sourcepub fn write(&mut self, row: usize, col: usize, value: E)
pub fn write(&mut self, row: usize, col: usize, value: E)
Writes the value to the element at the given indices, with bound checks.
§Panics
The function panics if any of the following conditions are violated:
row < self.nrows().col < self.ncols().
Sourcepub fn fill_zero(&mut self)where
E: ComplexField,
pub fn fill_zero(&mut self)where
E: ComplexField,
Fills the elements of self with zeros.
Sourcepub fn conjugate(&self) -> MatRef<'_, E::Conj>where
E: Conjugate,
pub fn conjugate(&self) -> MatRef<'_, E::Conj>where
E: Conjugate,
Returns a view over the conjugate of self.
Sourcepub fn adjoint(&self) -> MatRef<'_, E::Conj>where
E: Conjugate,
pub fn adjoint(&self) -> MatRef<'_, E::Conj>where
E: Conjugate,
Returns a view over the conjugate transpose of self.
Sourcepub fn diagonal(&self) -> Matrix<DiagRef<'_, E>>
pub fn diagonal(&self) -> Matrix<DiagRef<'_, E>>
Returns a view over the diagonal of the matrix.
Sourcepub fn to_owned(&self) -> Mat<E::Canonical>where
E: Conjugate,
pub fn to_owned(&self) -> Mat<E::Canonical>where
E: Conjugate,
Returns an owning Mat of the data
Sourcepub fn has_nan(&self) -> boolwhere
E: ComplexField,
pub fn has_nan(&self) -> boolwhere
E: ComplexField,
Returns true if any of the elements is NaN, otherwise returns false.
Sourcepub fn is_all_finite(&self) -> boolwhere
E: ComplexField,
pub fn is_all_finite(&self) -> boolwhere
E: ComplexField,
Returns true if all of the elements are finite, otherwise returns false.
Sourcepub fn norm_max(&self) -> E::Realwhere
E: ComplexField,
pub fn norm_max(&self) -> E::Realwhere
E: ComplexField,
Returns the maximum norm of self.
Sourcepub fn norm_l2(&self) -> E::Realwhere
E: ComplexField,
pub fn norm_l2(&self) -> E::Realwhere
E: ComplexField,
Returns the L2 norm of self.
Sourcepub fn sum(&self) -> Ewhere
E: ComplexField,
pub fn sum(&self) -> Ewhere
E: ComplexField,
Returns the sum of self.
Sourcepub fn kron(&self, rhs: impl As2D<E>) -> Mat<E>where
E: ComplexField,
pub fn kron(&self, rhs: impl As2D<E>) -> Mat<E>where
E: ComplexField,
Kroneckor product of self and rhs.
This is an allocating operation; see kron for the
allocation-free version or more info in general.
Sourcepub fn col_chunks(
&self,
chunk_size: usize,
) -> impl '_ + DoubleEndedIterator<Item = MatRef<'_, E>>
pub fn col_chunks( &self, chunk_size: usize, ) -> impl '_ + DoubleEndedIterator<Item = MatRef<'_, E>>
Returns an iterator that provides successive chunks of the columns of a view over 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.
Sourcepub fn col_chunks_mut(
&mut self,
chunk_size: usize,
) -> impl '_ + DoubleEndedIterator<Item = MatMut<'_, E>>
pub fn col_chunks_mut( &mut self, chunk_size: usize, ) -> impl '_ + DoubleEndedIterator<Item = MatMut<'_, E>>
Returns an iterator that provides successive chunks of the columns of a mutable view over
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.
Sourcepub fn par_col_chunks(
&self,
chunk_size: usize,
) -> impl '_ + IndexedParallelIterator<Item = MatRef<'_, E>>
Available on crate feature rayon only.
pub fn par_col_chunks( &self, chunk_size: usize, ) -> impl '_ + IndexedParallelIterator<Item = MatRef<'_, E>>
rayon only.Returns a parallel iterator that provides successive chunks of the columns of a view over
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_chunks_mut(
&mut self,
chunk_size: usize,
) -> impl '_ + IndexedParallelIterator<Item = MatMut<'_, E>>
Available on crate feature rayon only.
pub fn par_col_chunks_mut( &mut self, chunk_size: usize, ) -> impl '_ + IndexedParallelIterator<Item = MatMut<'_, E>>
rayon only.Returns a parallel iterator that provides successive chunks of the columns of a mutable view
over 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 row_chunks(
&self,
chunk_size: usize,
) -> impl '_ + DoubleEndedIterator<Item = MatRef<'_, E>>
pub fn row_chunks( &self, chunk_size: usize, ) -> impl '_ + DoubleEndedIterator<Item = MatRef<'_, E>>
Returns an iterator that provides successive chunks of the rows of a view over 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.
Sourcepub fn row_chunks_mut(
&mut self,
chunk_size: usize,
) -> impl '_ + DoubleEndedIterator<Item = MatMut<'_, E>>
pub fn row_chunks_mut( &mut self, chunk_size: usize, ) -> impl '_ + DoubleEndedIterator<Item = MatMut<'_, E>>
Returns an iterator that provides successive chunks of the rows of a mutable view over
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.
Sourcepub fn par_row_chunks(
&self,
chunk_size: usize,
) -> impl '_ + IndexedParallelIterator<Item = MatRef<'_, E>>
Available on crate feature rayon only.
pub fn par_row_chunks( &self, chunk_size: usize, ) -> impl '_ + IndexedParallelIterator<Item = MatRef<'_, E>>
rayon only.Returns a parallel iterator that provides successive chunks of the rows of a view over 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_chunks_mut(
&mut self,
chunk_size: usize,
) -> impl '_ + IndexedParallelIterator<Item = MatMut<'_, E>>
Available on crate feature rayon only.
pub fn par_row_chunks_mut( &mut self, chunk_size: usize, ) -> impl '_ + IndexedParallelIterator<Item = MatMut<'_, E>>
rayon only.Returns a parallel iterator that provides successive chunks of the rows of a mutable view
over 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.
Trait Implementations§
Source§impl<E: Entity> AsMatMut<E> for &mut Mat<E>
impl<E: Entity> AsMatMut<E> for &mut Mat<E>
Source§fn as_mat_mut(&mut self) -> MatMut<'_, E>
fn as_mat_mut(&mut self) -> MatMut<'_, E>
Source§impl<E: Entity> AsMatMut<E> for Mat<E>
impl<E: Entity> AsMatMut<E> for Mat<E>
Source§fn as_mat_mut(&mut self) -> MatMut<'_, E>
fn as_mat_mut(&mut self) -> MatMut<'_, E>
Source§impl<E: Entity> AsMatRef<E> for &Mat<E>
impl<E: Entity> AsMatRef<E> for &Mat<E>
Source§fn as_mat_ref(&self) -> MatRef<'_, E>
fn as_mat_ref(&self) -> MatRef<'_, E>
Source§impl<E: Entity> AsMatRef<E> for Mat<E>
impl<E: Entity> AsMatRef<E> for Mat<E>
Source§fn as_mat_ref(&self) -> MatRef<'_, E>
fn as_mat_ref(&self) -> MatRef<'_, E>
Source§impl<E: Entity> DenseAccess<E> for Mat<E>
Available on crate feature std only.
impl<E: Entity> DenseAccess<E> for Mat<E>
std only.fn fetch_single(&self, row: usize, col: usize) -> E
Source§impl<'a, E> Deserialize<'a> for Mat<E>where
E: Deserialize<'a> + Entity,
Available on crate feature serde only.
impl<'a, E> Deserialize<'a> for Mat<E>where
E: Deserialize<'a> + Entity,
serde only.Source§fn deserialize<D>(d: D) -> Result<Self, <D as Deserializer<'a>>::Error>where
D: Deserializer<'a>,
fn deserialize<D>(d: D) -> Result<Self, <D as Deserializer<'a>>::Error>where
D: Deserializer<'a>,
Source§impl<E> Serialize for Mat<E>
Available on crate feature serde only.
impl<E> Serialize for Mat<E>
serde only.