Struct winterfell::Matrix
source · [−]pub struct Matrix<E> where
E: FieldElement, { /* private fields */ }
Expand description
A two-dimensional matrix of field elements arranged in column-major order.
This struct is used as a backing type for many objects manipulated by the prover. The matrix itself does not assign any contextual meaning to the values stored in it. For example, columns may contain evaluations of polynomials, or polynomial coefficients, or really anything else. However, the matrix does expose a number of methods which make assumptions about the underlying data.
A matrix imposes the following restrictions on its content:
- A matrix must consist of at least 1 column and at least 2 rows.
- All columns must be of the same length.
- Number of rows must be a power of two.
Implementations
sourceimpl<E> Matrix<E> where
E: FieldElement,
impl<E> Matrix<E> where
E: FieldElement,
sourcepub fn get(&self, col_idx: usize, row_idx: usize) -> E
pub fn get(&self, col_idx: usize, row_idx: usize) -> E
Returns the element located at the specified column and row indexes in this matrix.
Panics
Panics if either col_idx
or row_idx
are out of bounds for this matrix.
sourcepub fn set(&mut self, col_idx: usize, row_idx: usize, value: E)
pub fn set(&mut self, col_idx: usize, row_idx: usize, value: E)
Set the cell in this matrix at the specified column and row indexes to the provided value.
Panics
Panics if either col_idx
or row_idx
are out of bounds for this matrix.
sourcepub fn get_column(&self, col_idx: usize) -> &[E]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn get_column(&self, col_idx: usize) -> &[E]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Returns a reference to the column at the specified index.
sourcepub fn get_column_mut(&mut self, col_idx: usize) -> &mut [E]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn get_column_mut(&mut self, col_idx: usize) -> &mut [E]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Returns a reference to the column at the specified index.
sourcepub fn read_row_into(&self, row_idx: usize, row: &mut [E])
pub fn read_row_into(&self, row_idx: usize, row: &mut [E])
Copies values of all columns at the specified row into the specified row slice.
Panics
Panics if row_idx
is out of bounds for this matrix.
sourcepub fn update_row(&mut self, row_idx: usize, row: &[E])
pub fn update_row(&mut self, row_idx: usize, row: &[E])
Updates a row in this matrix at the specified index to the provided data.
Panics
Panics if row_idx
is out of bounds for this matrix.
sourcepub fn columns(&self) -> ColumnIter<'_, E>
pub fn columns(&self) -> ColumnIter<'_, E>
Returns an iterator over the columns of this matrix.
sourcepub fn columns_mut(&mut self) -> ColumnIterMut<'_, E>
pub fn columns_mut(&mut self) -> ColumnIterMut<'_, E>
Returns a mutable iterator over the columns of this matrix.
sourcepub fn interpolate_columns(&self) -> Matrix<E>
pub fn interpolate_columns(&self) -> Matrix<E>
Interpolates columns of the matrix into polynomials in coefficient form and returns the result.
The interpolation is performed as follows:
- Each column of the matrix is interpreted as evaluations of degree
num_rows - 1
polynomial over a subgroup of sizenum_rows
. - Then each column is interpolated using iFFT algorithm into a polynomial in coefficient form.
- The resulting polynomials are returned as a single matrix where each column contains
coefficients of a degree
num_rows - 1
polynomial.
sourcepub fn interpolate_columns_into(self) -> Matrix<E>
pub fn interpolate_columns_into(self) -> Matrix<E>
Interpolates columns of the matrix into polynomials in coefficient form and returns the result. The input matrix is consumed in the process.
The interpolation is performed as follows:
- Each column of the matrix is interpreted as evaluations of degree
num_rows - 1
polynomial over a subgroup of sizenum_rows
. - Then each column is interpolated (in place) using iFFT algorithm into a polynomial in coefficient form.
- The resulting polynomials are returned as a single matrix where each column contains
coefficients of a degree
num_rows - 1
polynomial.
sourcepub fn evaluate_columns_over(
&self,
domain: &StarkDomain<<E as FieldElement>::BaseField>
) -> Matrix<E>
pub fn evaluate_columns_over(
&self,
domain: &StarkDomain<<E as FieldElement>::BaseField>
) -> Matrix<E>
Evaluates polynomials contained in the columns of this matrix over the specified domain and returns the result.
The evaluation is done as follows:
- Each column of the matrix is interpreted as coefficients of degree
num_rows - 1
polynomial. - These polynomials are evaluated over the LDE domain defined by the specified StarkDomain using FFT algorithm. The domain specification includes the size of the subgroup as well as the domain offset (to define a coset).
- The resulting evaluations are returned in a new Matrix.
sourcepub fn evaluate_columns_at<F>(&self, x: F) -> Vec<F, Global> where
F: FieldElement + From<E>,
pub fn evaluate_columns_at<F>(&self, x: F) -> Vec<F, Global> where
F: FieldElement + From<E>,
Evaluates polynomials contained in the columns of this matrix at a single point x
.
sourcepub fn commit_to_rows<H>(&self) -> MerkleTree<H> where
H: ElementHasher<BaseField = <E as FieldElement>::BaseField>,
pub fn commit_to_rows<H>(&self) -> MerkleTree<H> where
H: ElementHasher<BaseField = <E as FieldElement>::BaseField>,
Returns a commitment to this matrix.
The commitment is built as follows:
- Each row of the matrix is hashed into a single digest of the specified hash function.
- The resulting values are used to built a binary Merkle tree such that each row digest becomes a leaf in the tree. Thus, the number of leaves in the tree is equal to the number of rows in the matrix.
- The resulting Merkle tree is return as the commitment to the entire matrix.
Trait Implementations
Auto Trait Implementations
impl<E> RefUnwindSafe for Matrix<E> where
E: RefUnwindSafe,
impl<E> Send for Matrix<E>
impl<E> Sync for Matrix<E>
impl<E> Unpin for Matrix<E> where
E: Unpin,
impl<E> UnwindSafe for Matrix<E> where
E: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more