Struct DenseMatrix

Source
pub struct DenseMatrix<T, V = Vec<T>> {
    pub values: V,
    pub width: usize,
    /* private fields */
}
Expand description

A dense matrix in row-major format, with customizable backing storage.

The data is stored as a flat buffer, where rows are laid out consecutively.

Fields§

§values: V

Flat buffer of matrix values in row-major order.

§width: usize

Number of columns in the matrix.

The number of rows is implicitly determined as values.len() / width.

Implementations§

Source§

impl<T: Clone + Send + Sync + Default> DenseMatrix<T>

Source

pub fn default(width: usize, height: usize) -> Self

Create a new dense matrix of the given dimensions, backed by a Vec, and filled with default values.

Source§

impl<T: Clone + Send + Sync, S: DenseStorage<T>> DenseMatrix<T, S>

Source

pub fn new(values: S, width: usize) -> Self

Create a new dense matrix of the given dimensions, backed by the given storage.

Note that it is undefined behavior to create a matrix such that values.len() % width != 0.

Source

pub fn new_row(values: S) -> Self

Create a new RowMajorMatrix containing a single row.

Source

pub fn new_col(values: S) -> Self

Create a new RowMajorMatrix containing a single column.

Source

pub fn as_view(&self) -> RowMajorMatrixView<'_, T>

Get a view of the matrix, i.e. a reference to the underlying data.

Source

pub fn as_view_mut(&mut self) -> RowMajorMatrixViewMut<'_, T>
where S: BorrowMut<[T]>,

Get a mutable view of the matrix, i.e. a mutable reference to the underlying data.

Source

pub fn copy_from<S2>(&mut self, source: &DenseMatrix<T, S2>)
where T: Copy, S: BorrowMut<[T]>, S2: DenseStorage<T>,

Copy the values from the given matrix into this matrix.

Source

pub fn flatten_to_base<F: Field>(self) -> RowMajorMatrix<F>
where T: ExtensionField<F>,

Flatten an extension field matrix to a base field matrix.

Source

pub fn row_slices(&self) -> impl Iterator<Item = &[T]>

Get an iterator over the rows of the matrix.

Source

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

Get a parallel iterator over the rows of the matrix.

Source

pub fn row_mut(&mut self, r: usize) -> &mut [T]
where S: BorrowMut<[T]>,

Returns a slice of the given row.

§Panics

Panics if r larger than self.height().

Source

pub fn rows_mut(&mut self) -> impl Iterator<Item = &mut [T]>
where S: BorrowMut<[T]>,

Get a mutable iterator over the rows of the matrix.

Source

pub fn par_rows_mut<'a>( &'a mut self, ) -> impl IndexedParallelIterator<Item = &'a mut [T]>
where T: 'a + Send, S: BorrowMut<[T]>,

Get a mutable parallel iterator over the rows of the matrix.

Source

pub fn horizontally_packed_row_mut<P>( &mut self, r: usize, ) -> (&mut [P], &mut [T])
where P: PackedValue<Value = T>, S: BorrowMut<[T]>,

Get a mutable iterator over the rows of the matrix which packs the rows into packed values.

If P::WIDTH does not divide self.width, the remainder of the row will be returned as a base slice.

Source

pub fn scale_row(&mut self, r: usize, scale: T)
where T: Field, S: BorrowMut<[T]>,

Scale the given row by the given value.

§Panics

Panics if r larger than self.height().

Source

pub fn par_scale_row(&mut self, r: usize, scale: T)
where T: Field, S: BorrowMut<[T]>,

Scale the given row by the given value.

§Performance

This function is parallelized, which may introduce some overhead compared to Self::scale_row when the width is small.

§Panics

Panics if r larger than self.height().

Source

pub fn scale(&mut self, scale: T)
where T: Field, S: BorrowMut<[T]>,

Scale the entire matrix by the given value.

Source

pub fn split_rows( &self, r: usize, ) -> (RowMajorMatrixView<'_, T>, RowMajorMatrixView<'_, T>)

Split the matrix into two matrix views, one with the first r rows and one with the remaining rows.

§Panics

Panics if r larger than self.height().

Source

pub fn split_rows_mut( &mut self, r: usize, ) -> (RowMajorMatrixViewMut<'_, T>, RowMajorMatrixViewMut<'_, T>)
where S: BorrowMut<[T]>,

Split the matrix into two mutable matrix views, one with the first r rows and one with the remaining rows.

§Panics

Panics if r larger than self.height().

Source

pub fn par_row_chunks( &self, chunk_rows: usize, ) -> impl IndexedParallelIterator<Item = RowMajorMatrixView<'_, T>>
where T: Send,

Get an iterator over the rows of the matrix which takes chunk_rows rows at a time.

If chunk_rows does not divide the height of the matrix, the last chunk will be smaller.

Source

pub fn par_row_chunks_exact( &self, chunk_rows: usize, ) -> impl IndexedParallelIterator<Item = RowMajorMatrixView<'_, T>>
where T: Send,

Get a parallel iterator over the rows of the matrix which takes chunk_rows rows at a time.

If chunk_rows does not divide the height of the matrix, the last chunk will be smaller.

Source

pub fn par_row_chunks_mut( &mut self, chunk_rows: usize, ) -> impl IndexedParallelIterator<Item = RowMajorMatrixViewMut<'_, T>>
where T: Send, S: BorrowMut<[T]>,

Get a mutable iterator over the rows of the matrix which takes chunk_rows rows at a time.

If chunk_rows does not divide the height of the matrix, the last chunk will be smaller.

Source

pub fn row_chunks_exact_mut( &mut self, chunk_rows: usize, ) -> impl Iterator<Item = RowMajorMatrixViewMut<'_, T>>
where T: Send, S: BorrowMut<[T]>,

Get a mutable iterator over the rows of the matrix which takes chunk_rows rows at a time.

If chunk_rows does not divide the height of the matrix, the last up to chunk_rows - 1 rows of the matrix will be omitted.

Source

pub fn par_row_chunks_exact_mut( &mut self, chunk_rows: usize, ) -> impl IndexedParallelIterator<Item = RowMajorMatrixViewMut<'_, T>>
where T: Send, S: BorrowMut<[T]>,

Get a parallel mutable iterator over the rows of the matrix which takes chunk_rows rows at a time.

If chunk_rows does not divide the height of the matrix, the last up to chunk_rows - 1 rows of the matrix will be omitted.

Source

pub fn row_pair_mut( &mut self, row_1: usize, row_2: usize, ) -> (&mut [T], &mut [T])
where S: BorrowMut<[T]>,

Get a pair of mutable slices of the given rows.

§Panics

Panics if row_1 or row_2 are out of bounds or if row_1 >= row_2.

Source

pub fn packed_row_pair_mut<P>( &mut self, row_1: usize, row_2: usize, ) -> ((&mut [P], &mut [T]), (&mut [P], &mut [T]))
where S: BorrowMut<[T]>, P: PackedValue<Value = T>,

Get a pair of mutable slices of the given rows, both packed into packed field elements.

If P:WIDTH does not divide self.width, the remainder of the row will be returned as a base slice.

§Panics

Panics if row_1 or row_2 are out of bounds or if row_1 >= row_2.

Source

pub fn bit_reversed_zero_pad(self, added_bits: usize) -> RowMajorMatrix<T>
where T: Field,

Append zeros to the “end” of the given matrix, except that the matrix is in bit-reversed order, so in actuality we’re interleaving zero rows.

Source§

impl<T: Clone + Default + Send + Sync> DenseMatrix<T>

Source

pub fn as_cow<'a>(self) -> RowMajorMatrixCow<'a, T>

Source

pub fn rand<R: Rng>(rng: &mut R, rows: usize, cols: usize) -> Self

Source

pub fn rand_nonzero<R: Rng>(rng: &mut R, rows: usize, cols: usize) -> Self

Source

pub fn pad_to_height(&mut self, new_height: usize, fill: T)

Source§

impl<T: Copy + Default + Send + Sync, V: DenseStorage<T>> DenseMatrix<T, V>

Source

pub fn transpose(&self) -> RowMajorMatrix<T>

Return the transpose of this matrix.

Source

pub fn transpose_into<W: DenseStorage<T> + BorrowMut<[T]>>( &self, other: &mut DenseMatrix<T, W>, )

Transpose the matrix returning the result in other without intermediate allocation.

Source§

impl<'a, T: Clone + Default + Send + Sync> DenseMatrix<T, &'a [T]>

Source

pub fn as_cow(self) -> RowMajorMatrixCow<'a, T>

Trait Implementations§

Source§

impl<T: Clone + Send + Sync, S: DenseStorage<T>> BitReversibleMatrix<T> for DenseMatrix<T, S>

Source§

type BitRev = RowIndexMappedView<BitReversalPerm, DenseMatrix<T, S>>

The type returned when this matrix is viewed in bit-reversed order.
Source§

fn bit_reverse_rows(self) -> Self::BitRev

Return a version of the matrix with its row order reversed by bit index.
Source§

impl<T: Clone, V: Clone> Clone for DenseMatrix<T, V>

Source§

fn clone(&self) -> DenseMatrix<T, V>

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, V: Debug> Debug for DenseMatrix<T, V>

Source§

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

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

impl<'de, T, V> Deserialize<'de> for DenseMatrix<T, V>
where V: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Clone + Send + Sync, S: DenseStorage<T>> Matrix<T> for DenseMatrix<T, S>

Source§

fn width(&self) -> usize

Returns the number of columns in the matrix.
Source§

fn height(&self) -> usize

Returns the number of rows in the matrix.
Source§

unsafe fn get_unchecked(&self, r: usize, c: usize) -> T

Returns the element at the given row and column. Read more
Source§

unsafe fn row_subseq_unchecked( &self, r: usize, start: usize, end: usize, ) -> impl IntoIterator<Item = T, IntoIter = impl Iterator<Item = T> + Send + Sync>

Returns an iterator over the elements of the r-th row from position start to end. Read more
Source§

unsafe fn row_subslice_unchecked( &self, r: usize, start: usize, end: usize, ) -> impl Deref<Target = [T]>

Returns a subset of elements of the r-th row as something which can be coerced to a slice. Read more
Source§

fn to_row_major_matrix(self) -> RowMajorMatrix<T>
where Self: Sized, T: Clone,

Converts the matrix into a RowMajorMatrix by collecting all rows into a single vector.
Source§

fn horizontally_packed_row<'a, P>( &'a self, r: usize, ) -> (impl Iterator<Item = P> + Send + Sync, impl Iterator<Item = T> + Send + Sync)
where P: PackedValue<Value = T>, T: Clone + 'a,

Get a packed iterator over the r-th row. Read more
Source§

fn padded_horizontally_packed_row<'a, P>( &'a self, r: usize, ) -> impl Iterator<Item = P> + Send + Sync
where P: PackedValue<Value = T>, T: Clone + Default + 'a,

Get a packed iterator over the r-th row. Read more
Source§

fn dimensions(&self) -> Dimensions

Returns the dimensions (width, height) of the matrix.
Source§

fn get(&self, r: usize, c: usize) -> Option<T>

Returns the element at the given row and column. Read more
Source§

fn row( &self, r: usize, ) -> Option<impl IntoIterator<Item = T, IntoIter = impl Iterator<Item = T> + Send + Sync>>

Returns an iterator over the elements of the r-th row. Read more
Source§

unsafe fn row_unchecked( &self, r: usize, ) -> impl IntoIterator<Item = T, IntoIter = impl Iterator<Item = T> + Send + Sync>

Returns an iterator over the elements of the r-th row. Read more
Source§

fn row_slice(&self, r: usize) -> Option<impl Deref<Target = [T]>>

Returns the elements of the r-th row as something which can be coerced to a slice. Read more
Source§

unsafe fn row_slice_unchecked(&self, r: usize) -> impl Deref<Target = [T]>

Returns the elements of the r-th row as something which can be coerced to a slice. Read more
Source§

fn rows(&self) -> impl Iterator<Item = impl Iterator<Item = T>> + Send + Sync

Returns an iterator over all rows in the matrix.
Source§

fn par_rows( &self, ) -> impl IndexedParallelIterator<Item = impl Iterator<Item = T>> + Send + Sync

Returns a parallel iterator over all rows in the matrix.
Source§

fn wrapping_row_slices( &self, r: usize, c: usize, ) -> Vec<impl Deref<Target = [T]>>

Collect the elements of the rows r through r + c. If anything is larger than self.height() simply wrap around to the beginning of the matrix.
Source§

fn first_row( &self, ) -> Option<impl IntoIterator<Item = T, IntoIter = impl Iterator<Item = T> + Send + Sync>>

Returns an iterator over the first row of the matrix. Read more
Source§

fn last_row( &self, ) -> Option<impl IntoIterator<Item = T, IntoIter = impl Iterator<Item = T> + Send + Sync>>

Returns an iterator over the last row of the matrix. Read more
Source§

fn par_horizontally_packed_rows<'a, P>( &'a self, ) -> impl IndexedParallelIterator<Item = (impl Iterator<Item = P> + Send + Sync, impl Iterator<Item = T> + Send + Sync)>
where P: PackedValue<Value = T>, T: Clone + 'a,

Get a parallel iterator over all packed rows of the matrix. Read more
Source§

fn par_padded_horizontally_packed_rows<'a, P>( &'a self, ) -> impl IndexedParallelIterator<Item = impl Iterator<Item = P> + Send + Sync>
where P: PackedValue<Value = T>, T: Clone + Default + 'a,

Get a parallel iterator over all packed rows of the matrix. Read more
Source§

fn vertically_packed_row<P>(&self, r: usize) -> impl Iterator<Item = P>
where T: Copy, P: PackedValue<Value = T>,

Pack together a collection of adjacent rows from the matrix. Read more
Source§

fn vertically_packed_row_pair<P>(&self, r: usize, step: usize) -> Vec<P>
where T: Copy, P: PackedValue<Value = T>,

Pack together a collection of rows and “next” rows from the matrix. Read more
Source§

fn vertically_strided( self, stride: usize, offset: usize, ) -> VerticallyStridedMatrixView<Self>
where Self: Sized,

Returns a view over a vertically strided submatrix. Read more
Source§

fn columnwise_dot_product<EF>(&self, v: &[EF]) -> Vec<EF>
where T: Field, EF: ExtensionField<T>,

Compute Mᵀv, aka premultiply this matrix by the given vector, aka scale each row by the corresponding entry in v and take the sum across rows. v can be a vector of extension elements.
Source§

fn rowwise_packed_dot_product<EF>( &self, vec: &[EF::ExtensionPacking], ) -> impl IndexedParallelIterator<Item = EF>
where T: Field, EF: ExtensionField<T>,

Compute the matrix vector product M . vec, aka take the dot product of each row of M by vec. If the length of vec is longer than the width of M, vec is truncated to the first width() elements. Read more
Source§

impl<T: PartialEq, V: PartialEq> PartialEq for DenseMatrix<T, V>

Source§

fn eq(&self, other: &DenseMatrix<T, V>) -> 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, V> Serialize for DenseMatrix<T, V>
where V: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Copy, V: Copy> Copy for DenseMatrix<T, V>

Source§

impl<T: Eq, V: Eq> Eq for DenseMatrix<T, V>

Source§

impl<T, V> StructuralPartialEq for DenseMatrix<T, V>

Auto Trait Implementations§

§

impl<T, V> Freeze for DenseMatrix<T, V>
where V: Freeze,

§

impl<T, V> RefUnwindSafe for DenseMatrix<T, V>

§

impl<T, V> Send for DenseMatrix<T, V>
where V: Send, T: Send,

§

impl<T, V> Sync for DenseMatrix<T, V>
where V: Sync, T: Sync,

§

impl<T, V> Unpin for DenseMatrix<T, V>
where V: Unpin, T: Unpin,

§

impl<T, V> UnwindSafe for DenseMatrix<T, V>
where V: UnwindSafe, 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,