pub struct MatrixBase<T>where
T: DenseData,{ /* private fields */ }Expand description
A view over dense chunk of memory, interpreting that memory as a 2-dimensional matrix laid out in row-major order.
When this class view immutable memory, it is Copy.
Implementations§
Source§impl<T> MatrixBase<Box<[T]>>
impl<T> MatrixBase<Box<[T]>>
Source§impl<T> MatrixBase<T>where
T: DenseData,
impl<T> MatrixBase<T>where
T: DenseData,
Sourcepub fn try_from(
data: T,
nrows: usize,
ncols: usize,
) -> Result<Self, TryFromError<T>>
pub fn try_from( data: T, nrows: usize, ncols: usize, ) -> Result<Self, TryFromError<T>>
Try to construct a MatrixBase over the provided base. If the size of the base
is incorrect, return a TryFromError containing the base.
The length of the base must be equal to nrows * ncols.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T::Elem]where
T: MutDenseData,
pub fn as_mut_slice(&mut self) -> &mut [T::Elem]where
T: MutDenseData,
Return the underlying data as a mutable slice.
Sourcepub fn row_vector(data: T) -> Self
pub fn row_vector(data: T) -> Self
Construct a new MatrixBase over the raw data.
The returned MatrixBase will only have a single row with contents equal to data.
Sourcepub fn get_row(&self, row: usize) -> Option<&[T::Elem]>
pub fn get_row(&self, row: usize) -> Option<&[T::Elem]>
Return row row if row < self.nrows(). Otherwise, return None.
Sourcepub unsafe fn get_row_unchecked(&self, row: usize) -> &[T::Elem]
pub unsafe fn get_row_unchecked(&self, row: usize) -> &[T::Elem]
Returns the requested row without boundschecking.
§Safety
The following conditions must hold to avoid undefined behavior:
row < self.nrows().
Sourcepub fn row_mut(&mut self, row: usize) -> &mut [T::Elem]where
T: MutDenseData,
pub fn row_mut(&mut self, row: usize) -> &mut [T::Elem]where
T: MutDenseData,
Sourcepub unsafe fn get_row_unchecked_mut(&mut self, row: usize) -> &mut [T::Elem]where
T: MutDenseData,
pub unsafe fn get_row_unchecked_mut(&mut self, row: usize) -> &mut [T::Elem]where
T: MutDenseData,
Returns the requested row without boundschecking.
§Safety
The following conditions must hold to avoid undefined behavior:
row < self.nrows().
Sourcepub fn row_iter(&self) -> impl ExactSizeIterator<Item = &[T::Elem]>
pub fn row_iter(&self) -> impl ExactSizeIterator<Item = &[T::Elem]>
Return a iterator over all rows in the matrix.
Rows are yielded sequentially beginning with row 0.
Sourcepub fn row_iter_mut(&mut self) -> impl ExactSizeIterator<Item = &mut [T::Elem]>where
T: MutDenseData,
pub fn row_iter_mut(&mut self) -> impl ExactSizeIterator<Item = &mut [T::Elem]>where
T: MutDenseData,
Return a mutable iterator over all rows in the matrix.
Rows are yielded sequentially beginning with row 0.
Sourcepub fn window_iter(
&self,
batchsize: usize,
) -> impl Iterator<Item = MatrixView<'_, T::Elem>>
pub fn window_iter( &self, batchsize: usize, ) -> impl Iterator<Item = MatrixView<'_, T::Elem>>
Return an iterator that divides the matrix into sub-matrices with (up to)
batchsize rows with self.ncols() columns.
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.
Sourcepub fn par_window_iter(
&self,
batchsize: usize,
) -> impl IndexedParallelIterator<Item = MatrixView<'_, T::Elem>>
pub fn par_window_iter( &self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = MatrixView<'_, T::Elem>>
Return a parallel iterator that divides the matrix into 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.
Sourcepub fn par_window_iter_mut(
&mut self,
batchsize: usize,
) -> impl IndexedParallelIterator<Item = MutMatrixView<'_, T::Elem>>
pub fn par_window_iter_mut( &mut self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = MutMatrixView<'_, T::Elem>>
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.
Sourcepub fn par_row_iter(&self) -> impl IndexedParallelIterator<Item = &[T::Elem]>
pub fn par_row_iter(&self) -> impl IndexedParallelIterator<Item = &[T::Elem]>
Return a parallel iterator over the rows of the matrix.
Sourcepub fn par_row_iter_mut(
&mut self,
) -> impl IndexedParallelIterator<Item = &mut [T::Elem]>
pub fn par_row_iter_mut( &mut self, ) -> impl IndexedParallelIterator<Item = &mut [T::Elem]>
Return a parallel iterator over the rows of the matrix.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the matrix, returning the inner representation.
This loses the information about the number of rows and columnts.
Sourcepub fn as_view(&self) -> MatrixView<'_, T::Elem>
pub fn as_view(&self) -> MatrixView<'_, T::Elem>
Return a view over the matrix.
Sourcepub fn as_mut_view(&mut self) -> MutMatrixView<'_, T::Elem>where
T: MutDenseData,
pub fn as_mut_view(&mut self) -> MutMatrixView<'_, T::Elem>where
T: MutDenseData,
Return a mutable view over the matrix.
Sourcepub fn subview(&self, rows: Range<usize>) -> Option<MatrixView<'_, T::Elem>>
pub fn subview(&self, rows: Range<usize>) -> Option<MatrixView<'_, T::Elem>>
Return a view over the specified rows of the matrix.
If the specified range is out of bounds, return None.
use diskann_utils::views::Matrix;
let mut mat = Matrix::new(0usize, 4, 3);
// Fill the matrix with some data.
mat.row_iter_mut().enumerate().for_each(|(i, row)| row.fill(i));
// Creating a subview into an offset portion of the matrix.
let subview = mat.subview(1..3).unwrap();
assert_eq!(subview.nrows(), 2);
assert_eq!(subview.row(0), &[1, 1, 1]);
assert_eq!(subview.row(1), &[2, 2, 2]);
// A trying to access out-of-bounds returns `None`
assert!(mat.subview(3..5).is_none());Sourcepub fn as_mut_ptr(&mut self) -> *mut T::Elemwhere
T: MutDenseData,
pub fn as_mut_ptr(&mut self) -> *mut T::Elemwhere
T: MutDenseData,
Return a pointer to the base of the matrix.
Sourcepub unsafe fn get_unchecked(&self, row: usize, col: usize) -> &T::Elem
pub unsafe fn get_unchecked(&self, row: usize, col: usize) -> &T::Elem
Returns a reference to an element without boundschecking.
§Safety
The following conditions must hold to avoid undefined behavior:
row < self.nrows().col < self.ncols().
Sourcepub unsafe fn get_unchecked_mut(
&mut self,
row: usize,
col: usize,
) -> &mut T::Elemwhere
T: MutDenseData,
pub unsafe fn get_unchecked_mut(
&mut self,
row: usize,
col: usize,
) -> &mut T::Elemwhere
T: MutDenseData,
Returns a mutable reference to an element without boundschecking.
§Safety
The following conditions must hold to avoid undefined behavior:
row < self.nrows().col < self.ncols().
pub fn to_owned(&self) -> Matrix<T::Elem>
Trait Implementations§
Source§impl<T> Clone for MatrixBase<T>
impl<T> Clone for MatrixBase<T>
Source§fn clone(&self) -> MatrixBase<T>
fn clone(&self) -> MatrixBase<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for MatrixBase<T>
impl<T> Debug for MatrixBase<T>
Source§impl<'a, T> From<MatrixBase<&'a [T]>> for &'a [T]
Allow matrix views to be converted directly to slices.
impl<'a, T> From<MatrixBase<&'a [T]>> for &'a [T]
Allow matrix views to be converted directly to slices.
Source§fn from(view: MatrixView<'a, T>) -> Self
fn from(view: MatrixView<'a, T>) -> Self
Source§impl<'a, T> From<MatrixBase<&'a mut [T]>> for &'a [T]
Allow mutable matrix views to be converted directly to slices.
impl<'a, T> From<MatrixBase<&'a mut [T]>> for &'a [T]
Allow mutable matrix views to be converted directly to slices.
Source§fn from(view: MutMatrixView<'a, T>) -> Self
fn from(view: MutMatrixView<'a, T>) -> Self
Source§impl<T, U> From<MatrixBase<T>> for StridedBase<U>
impl<T, U> From<MatrixBase<T>> for StridedBase<U>
Source§fn from(matrix: MatrixBase<T>) -> Self
fn from(matrix: MatrixBase<T>) -> Self
Source§impl<T> Index<(usize, usize)> for MatrixBase<T>where
T: DenseData,
Return a reference to the item at entry (row, col) in the matrix.
impl<T> Index<(usize, usize)> for MatrixBase<T>where
T: DenseData,
Return a reference to the item at entry (row, col) in the matrix.
§Panics
Panics if row >= self.nrows() or col >= self.ncols().
Source§impl<T> IndexMut<(usize, usize)> for MatrixBase<T>where
T: MutDenseData,
Return a mutable reference to the item at entry (row, col) in the matrix.
impl<T> IndexMut<(usize, usize)> for MatrixBase<T>where
T: MutDenseData,
Return a mutable reference to the item at entry (row, col) in the matrix.
§Panics
Panics if row >= self.nrows() or col >= self.ncols().
Source§impl<T> PartialEq for MatrixBase<T>
impl<T> PartialEq for MatrixBase<T>
impl<T> Copy for MatrixBase<T>
impl<T> StructuralPartialEq for MatrixBase<T>where
T: DenseData,
Auto Trait Implementations§
impl<T> Freeze for MatrixBase<T>where
T: Freeze,
impl<T> RefUnwindSafe for MatrixBase<T>where
T: RefUnwindSafe,
impl<T> Send for MatrixBase<T>where
T: Send,
impl<T> Sync for MatrixBase<T>where
T: Sync,
impl<T> Unpin for MatrixBase<T>where
T: Unpin,
impl<T> UnsafeUnpin for MatrixBase<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for MatrixBase<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more