pub struct Mat<T: 'static> { /* private fields */ }Expand description
Owning matrix structure stored in column major format.
A matrix can be thought of as a 2D array of values. These values are stored in memory so that the columns are contiguous.
Note
Note that 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 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.
Implementations
sourceimpl<T: 'static> Mat<T>
impl<T: 'static> Mat<T>
sourcepub unsafe fn from_raw_parts(
ptr: *mut T,
nrows: usize,
ncols: usize,
row_capacity: usize,
col_capacity: usize
) -> Self
pub unsafe fn from_raw_parts(
ptr: *mut T,
nrows: usize,
ncols: usize,
row_capacity: usize,
col_capacity: usize
) -> Self
Returns a matrix from preallocated pointer, dimensions, and capacities.
Safety
The inputs to this function must be acquired from the return value of some previous call
to Self::into_raw_parts.
sourcepub fn into_raw_parts(self) -> (*mut T, usize, usize, usize, usize)
pub fn into_raw_parts(self) -> (*mut T, usize, usize, usize, usize)
Consumes self and returns its raw parts in this order: pointer to data, number of rows,
number of columns, row capacity and column capacity.
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
Panics if the total capacity in bytes exceeds isize::MAX.
sourcepub fn with_dims(
f: impl FnMut(usize, usize) -> T,
nrows: usize,
ncols: usize
) -> Self
pub fn with_dims(
f: impl FnMut(usize, usize) -> T,
nrows: usize,
ncols: usize
) -> Self
Returns a new matrix with dimensions (nrows, ncols), filled with the provided function.
Panics
Panics if the total capacity in bytes exceeds isize::MAX.
sourcepub fn zeros(nrows: usize, ncols: usize) -> Selfwhere
T: ComplexField,
pub fn zeros(nrows: usize, ncols: usize) -> Selfwhere
T: ComplexField,
Returns a new matrix with dimensions (nrows, ncols), filled with zeros.
Panics
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
nrowsmust be less thanself.row_capacity().ncolsmust be less thanself.col_capacity().- The elements that were previously out of bounds but are now in bounds must be initialized.
sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
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
Panics if the new total capacity in bytes exceeds isize::MAX.
sourcepub fn resize_with(
&mut self,
f: impl FnMut(usize, usize) -> T,
new_nrows: usize,
new_ncols: usize
)
pub fn resize_with(
&mut self,
f: impl FnMut(usize, usize) -> T,
new_nrows: usize,
new_ncols: usize
)
Resizes the matrix in-place so that the new dimensions are (new_nrows, new_ncols).
Elements that are now out of bounds are dropped, while new elements are created with the
given function f, so that elements at position (i, j) are created by calling f(i, j).