Skip to main content

MatrixMut

Trait MatrixMut 

Source
pub unsafe trait MatrixMut: Matrix {
Show 13 methods // Required method fn as_nonnull_mut(&mut self) -> NonNull<Self::Element>; // Provided methods unsafe fn row_unchecked_mut(&mut self, row: usize) -> &mut [Self::Element] { ... } fn as_mut_ptr(&mut self) -> *mut Self::Element { ... } fn as_mut_slice(&mut self) -> &mut [Self::Element] { ... } fn row_mut(&mut self, row: usize) -> &mut [Self::Element] { ... } fn get_row_mut(&mut self, row: usize) -> Option<&mut [Self::Element]> { ... } fn rows_mut(&mut self) -> RowsMut<'_, Self::Element> ⓘ { ... } unsafe fn element_unchecked_mut( &mut self, row: usize, col: usize, ) -> &mut Self::Element { ... } fn get_element_mut( &mut self, row: usize, col: usize, ) -> Option<&mut Self::Element> { ... } fn element_mut(&mut self, row: usize, col: usize) -> &mut Self::Element { ... } fn as_view_mut(&mut self) -> Mut<'_, Self::Element> { ... } fn par_rows_mut( &mut self, ) -> impl IndexedParallelIterator<Item = &mut [Self::Element]> where Self::Element: Send { ... } fn par_window_iter_mut( &mut self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = Mut<'_, Self::Element>> where Self::Element: Send { ... }
}
Expand description

Tools for treating contiguous regions of mutable memory as a dense, row-major matrix.

See also: Owned, Ref, Mut.

§Safety

In addition to the requirements of Matrix, implementations must ensure that for any mutable borrow matrix: &mut Self, it is valid to construct:

let data = matrix.as_nonnull_mut();
let layout = matrix.layout();

unsafe {
   std::slice::from_raw_parts_mut(data.as_ptr(), layout.num_elements())
}

The resulting slice must have exclusive access to the described elements for its entire lifetime. No other reference may be used to access those elements during that lifetime.

Implementations may change their pointer or layout through exclusive access, such as when resizing or reallocating. They must not do so while any reference derived from the previous pointer and layout remains live.

For a given state of matrix, the pointers from matrix.as_nonnull_mut() and matrix.as_nonnull() must have the same address. However, the pointer obtained from matrix.as_nonnull_mut() must have provenance permitting mutable access to the span described by matrix.layout().

Required Methods§

Source

fn as_nonnull_mut(&mut self) -> NonNull<Self::Element>

Return the base pointer for the matrix.

Calling this method must not change the matrix’s pointer, layout, or contents.

The returned pointer must have provenance permitting mutable access to the span described by Matrix::layout and for a given matrix state, must have the same address as Matrix::as_nonnull.

Provided Methods§

Source

unsafe fn row_unchecked_mut(&mut self, row: usize) -> &mut [Self::Element]

Returns the requested row without bounds checking.

§Safety

The following conditions must hold to avoid undefined behavior:

  • row < self.nrows().
Source

fn as_mut_ptr(&mut self) -> *mut Self::Element

Return a pointer to the base of the matrix.

Source

fn as_mut_slice(&mut self) -> &mut [Self::Element]

Return the underlying data as a mutable slice.

Source

fn row_mut(&mut self, row: usize) -> &mut [Self::Element]

Return row row as a mutable slice.

§Panics

Panics if row >= self.nrows().

Source

fn get_row_mut(&mut self, row: usize) -> Option<&mut [Self::Element]>

Return row row if row < self.nrows(). Otherwise, return None.

Source

fn rows_mut(&mut self) -> RowsMut<'_, Self::Element> ⓘ

Return a mutable iterator over all rows in the matrix.

Rows are yielded sequentially beginning with row 0.

Source

unsafe fn element_unchecked_mut( &mut self, row: usize, col: usize, ) -> &mut Self::Element

Returns a mutable reference to an element without bounds checking.

§Safety

The following conditions must hold to avoid undefined behavior:

  • row < self.nrows().
  • col < self.ncols().
Source

fn get_element_mut( &mut self, row: usize, col: usize, ) -> Option<&mut Self::Element>

Return the value at the specified row and col.

If either index is out-of-bounds, return None.

Source

fn element_mut(&mut self, row: usize, col: usize) -> &mut Self::Element

Return the value at the specified row and col.

§Panics

Panics if either row or col is out-of-bounds.

Source

fn as_view_mut(&mut self) -> Mut<'_, Self::Element>

Return a view over the matrix.

Source

fn par_rows_mut( &mut self, ) -> impl IndexedParallelIterator<Item = &mut [Self::Element]>
where Self::Element: Send,

Return a parallel iterator over the rows of the matrix.

§Panics

Panics if self.ncols() == 0 && self.nrows() != 0.

Source

fn par_window_iter_mut( &mut self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = Mut<'_, Self::Element>>
where Self::Element: Send,

Return a parallel iterator that divides the matrix into mutable sub-matrices with (up to) batchsize rows with self.ncols() columns.

This allows workers in parallel algorithms to work on dense subsets of the whole matrix for better locality.

It is possible for yielded sub-matrices to have fewer than batchsize rows if the number of rows in the parent matrix is not evenly divisible by batchsize.

§Panics

Panics if batchsize = 0 or self.ncols() == 0 && self.nrows() != 0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> MatrixMut for Mut<'_, T>

Source§

impl<T> MatrixMut for Owned<T>