Skip to main content

MatrixBase

Struct MatrixBase 

Source
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]>>

Source

pub fn new<U>(generator: U, nrows: usize, ncols: usize) -> Self
where U: Generator<T>,

Construct a new Matrix initialized with the contents of the generator.

Elements are initialized in memory order.

Source§

impl<T> MatrixBase<T>
where T: DenseData,

Source

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.

Source

pub fn ncols(&self) -> usize

Return the number of columns in the matrix.

Source

pub fn nrows(&self) -> usize

Return the number of rows in the matrix.

Source

pub fn as_slice(&self) -> &[T::Elem]

Return the underlying data as a slice.

Source

pub fn as_mut_slice(&mut self) -> &mut [T::Elem]
where T: MutDenseData,

Return the underlying data as a mutable slice.

Source

pub fn row(&self, row: usize) -> &[T::Elem]

Return row row as a slice.

§Panic

Panics if row >= self.nrows().

Source

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.

Source

pub fn get_row(&self, row: usize) -> Option<&[T::Elem]>

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

Source

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().
Source

pub fn row_mut(&mut self, row: usize) -> &mut [T::Elem]
where T: MutDenseData,

Return row row as a mutable slice.

§Panics

Panics if row >= self.nrows().

Source

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().
Source

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.

Source

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.

Source

pub fn window_iter( &self, batchsize: usize, ) -> impl Iterator<Item = MatrixView<'_, T::Elem>>
where T::Elem: Sync,

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.

Source

pub fn par_window_iter( &self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = MatrixView<'_, T::Elem>>
where T::Elem: Sync,

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.

Source

pub fn par_window_iter_mut( &mut self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = MutMatrixView<'_, T::Elem>>
where T: MutDenseData, T::Elem: 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.

Source

pub fn par_row_iter(&self) -> impl IndexedParallelIterator<Item = &[T::Elem]>
where T::Elem: Sync,

Return a parallel iterator over the rows of the matrix.

Source

pub fn par_row_iter_mut( &mut self, ) -> impl IndexedParallelIterator<Item = &mut [T::Elem]>
where T: MutDenseData, T::Elem: Send,

Return a parallel iterator over the rows of the matrix.

Source

pub fn into_inner(self) -> T

Consume the matrix, returning the inner representation.

This loses the information about the number of rows and columnts.

Source

pub fn as_view(&self) -> MatrixView<'_, T::Elem>

Return a view over the matrix.

Source

pub fn as_mut_view(&mut self) -> MutMatrixView<'_, T::Elem>
where T: MutDenseData,

Return a mutable view over the matrix.

Source

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());
Source

pub fn as_ptr(&self) -> *const T::Elem

Return a pointer to the base of the matrix.

Source

pub fn as_mut_ptr(&mut self) -> *mut T::Elem
where T: MutDenseData,

Return a pointer to the base of the matrix.

Source

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().
Source

pub unsafe fn get_unchecked_mut( &mut self, row: usize, col: usize, ) -> &mut T::Elem
where 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().
Source

pub fn to_owned(&self) -> Matrix<T::Elem>
where T::Elem: Clone,

Trait Implementations§

Source§

impl<T> Clone for MatrixBase<T>
where T: DenseData + Clone,

Source§

fn clone(&self) -> MatrixBase<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for MatrixBase<T>
where T: DenseData + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Converts to this type from the input type.
Source§

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

Converts to this type from the input type.
Source§

impl<T, U> From<MatrixBase<T>> for StridedBase<U>
where T: DenseData + Into<U>, U: DenseData,

Source§

fn from(matrix: MatrixBase<T>) -> Self

Converts to this type from the input type.
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.

§Panics

Panics if row >= self.nrows() or col >= self.ncols().

Source§

type Output = <T as DenseData>::Elem

The returned type after indexing.
Source§

fn index(&self, (row, col): (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
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.

§Panics

Panics if row >= self.nrows() or col >= self.ncols().

Source§

fn index_mut(&mut self, (row, col): (usize, usize)) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> PartialEq for MatrixBase<T>
where T: DenseData + PartialEq,

Source§

fn eq(&self, other: &MatrixBase<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Copy for MatrixBase<T>
where T: DenseData + Copy,

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Generator<T> for T
where T: Clone,

Source§

fn generate(&mut self) -> T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> AsyncFriendly for T
where T: Send + Sync + 'static,