pub struct MatMut<'a, T> { /* private fields */ }
Expand description
Mutable matrix view with general row and column strides.
For usage examples, see MatRef
.
Implementations
sourceimpl<'a, T> MatMut<'a, T>
impl<'a, T> MatMut<'a, T>
sourcepub unsafe fn from_raw_parts(
ptr: *mut T,
nrows: usize,
ncols: usize,
row_stride: isize,
col_stride: isize
) -> Self
pub unsafe fn from_raw_parts(
ptr: *mut T,
nrows: usize,
ncols: usize,
row_stride: isize,
col_stride: isize
) -> Self
Returns a mutable matrix slice from the given arguments.
ptr
: pointer to the first element of the matrix.
nrows
: number of rows of the matrix.
ncols
: number of columns of the matrix.
row_stride
: offset between the first elements of two successive rows in the matrix.
col_stride
: offset between the first elements of two successive columns in the matrix.
Safety
ptr
must be non null and properly aligned for type T
.
For each i < nrows
and j < ncols
,
ptr.offset(i as isize * row_stride + j as isize * col_stride)
must point to a valid
initialized object of type T
, unless memory pointing to that address is never read.
Additionally, when (i, j) != (0, 0)
, this pointer is never equal to ptr
(no self
aliasing).
The referenced memory must not be accessed by another pointer which was not derived from
the return value, during the lifetime 'a
.
sourcepub fn as_ptr(self) -> *mut T
pub fn as_ptr(self) -> *mut T
Returns a mutable pointer to the first (top left) element of the matrix.
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.
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 ptr_at(self, i: usize, j: usize) -> *mut T
pub fn ptr_at(self, i: usize, j: usize) -> *mut T
Returns a mutable pointer to the element at position (i, j) in the matrix.
sourcepub unsafe fn ptr_in_bounds_at_unchecked(self, i: usize, j: usize) -> *mut T
pub unsafe fn ptr_in_bounds_at_unchecked(self, i: usize, j: usize) -> *mut T
Returns a mutable pointer to the element at position (i, j) in the matrix, assuming it falls within its bounds with no bound checks.
Safety
Requires that i < self.nrows()
and j < self.ncols()
.
Otherwise, the behavior is undefined.
sourcepub fn ptr_in_bounds_at(self, i: usize, j: usize) -> *mut T
pub fn ptr_in_bounds_at(self, i: usize, j: usize) -> *mut T
Returns a mutable pointer to the element at position (i, j) in the matrix, while asserting that it falls within its bounds.
Panics
Requires that i < self.nrows()
and j < self.ncols()
.
Otherwise, it panics.
sourcepub unsafe fn split_at_unchecked(
self,
i: usize,
j: usize
) -> (Self, Self, Self, Self)
pub unsafe fn split_at_unchecked(
self,
i: usize,
j: usize
) -> (Self, Self, Self, Self)
Splits the matrix into four corner parts in the following order: top left, top right, bottom left, bottom right.
Safety
Requires that i <= self.nrows()
and j <= self.ncols()
.
Otherwise, the behavior is undefined.
sourcepub fn split_at(self, i: usize, j: usize) -> (Self, Self, Self, Self)
pub fn split_at(self, i: usize, j: usize) -> (Self, Self, Self, Self)
Splits the matrix into four corner parts in the following order: top left, top right, bottom left, bottom right.
Panics
Requires that i <= self.nrows()
and j <= self.ncols()
.
Otherwise, it panics.
sourcepub unsafe fn get_unchecked(self, i: usize, j: usize) -> &'a mut T
pub unsafe fn get_unchecked(self, i: usize, j: usize) -> &'a mut T
Returns a mutable reference to the element at position (i, j), with no bound checks.
Safety
Requires that i < self.nrows()
and j < self.ncols()
.
Otherwise, the behavior is undefined.
sourcepub fn get(self, i: usize, j: usize) -> &'a mut T
pub fn get(self, i: usize, j: usize) -> &'a mut T
Returns a mutable reference to the element at position (i, j), or panics if the indices are out of bounds.
sourcepub unsafe fn row_unchecked(self, i: usize) -> RowMut<'a, T>
pub unsafe fn row_unchecked(self, i: usize) -> RowMut<'a, T>
Returns the i
-th row of the matrix, with no bound checks.
Safety
Requires that i < self.nrows()
.
Otherwise, the behavior is undefined.
sourcepub unsafe fn col_unchecked(self, j: usize) -> ColMut<'a, T>
pub unsafe fn col_unchecked(self, j: usize) -> ColMut<'a, T>
Returns the j
-th column of the matrix, with no bound checks.
Safety
Requires that j < self.ncols()
.
Otherwise, the behavior is undefined.
sourcepub fn reverse_rows(self) -> Self
pub fn reverse_rows(self) -> Self
Returns a matrix whose rows are the the rows of the input matrix in reverse order.
sourcepub fn reverse_cols(self) -> Self
pub fn reverse_cols(self) -> Self
Returns a matrix whose columns are the the columns of the input matrix in reverse order.
sourcepub fn reverse_rows_and_cols(self) -> Self
pub fn reverse_rows_and_cols(self) -> Self
Returns a matrix whose rows and columns are the the rows and columns of the input matrix in reverse order.
sourcepub unsafe fn diagonal_unchecked(self) -> ColMut<'a, T>
pub unsafe fn diagonal_unchecked(self) -> ColMut<'a, T>
Returns the diagonal of the matrix, as a column vector.
Safety
Requires that the matrix be square.
Otherwise, the behavior is undefined.
sourcepub fn diagonal(self) -> ColMut<'a, T>
pub fn diagonal(self) -> ColMut<'a, T>
Returns the diagonal of the matrix, as a column vector.
Panics
Requires that the matrix be square.
Otherwise, it panics.
sourcepub fn into_row_iter(self) -> RowIterMut<'a, T> ⓘ
pub fn into_row_iter(self) -> RowIterMut<'a, T> ⓘ
Returns an iterator over the rows of the matrix.
sourcepub fn into_col_iter(self) -> ColIterMut<'a, T> ⓘ
pub fn into_col_iter(self) -> ColIterMut<'a, T> ⓘ
Returns an iterator over the columns of the matrix.
sourcepub unsafe fn submatrix_unchecked(
self,
i: usize,
j: usize,
nrows: usize,
ncols: usize
) -> Self
pub unsafe fn submatrix_unchecked(
self,
i: usize,
j: usize,
nrows: usize,
ncols: usize
) -> Self
Returns a view over a submatrix of self
, starting at position (i, j)
with dimensions (nrows, ncols)
.
Safety
Requires that i <= self.nrows()
,
j <= self.ncols()
,
nrows <= self.nrows() - i
and ncols <= self.ncols() - j
.
Otherwise, the behavior is undefined.
sourcepub fn submatrix(self, i: usize, j: usize, nrows: usize, ncols: usize) -> Self
pub fn submatrix(self, i: usize, j: usize, nrows: usize, ncols: usize) -> Self
Returns a view over a submatrix of self
, starting at position (i, j)
with dimensions (nrows, ncols)
.
Panics
Requires that i <= self.nrows()
,
j <= self.ncols()
,
nrows <= self.nrows() - i
and ncols <= self.ncols() - j
.
Otherwise, it panics.