pub struct ColMatrix<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§
Source§impl<E> ColMatrix<E>where
E: FieldElement,
impl<E> ColMatrix<E>where
E: FieldElement,
Sourcepub fn new(columns: Vec<Vec<E>>) -> ColMatrix<E>
pub fn new(columns: Vec<Vec<E>>) -> ColMatrix<E>
Returns a new [Matrix] instantiated with the data from the specified columns.
§Panics
Panics if:
- The provided vector of columns is empty.
- Not all of the columns have the same number of elements.
- Number of rows is smaller than or equal to 1.
- Number of rows is not a power of two.
Sourcepub fn num_base_cols(&self) -> usize
pub fn num_base_cols(&self) -> usize
Returns the number of base field columns in this matrix.
The number of base field columns is defined as the number of columns multiplied by the extension degree of field elements contained in this matrix.
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 get_base_element(
&self,
base_col_idx: usize,
row_idx: usize,
) -> <E as FieldElement>::BaseField
pub fn get_base_element( &self, base_col_idx: usize, row_idx: usize, ) -> <E as FieldElement>::BaseField
Returns base field elements located at the specified column and row indexes in this matrix.
For STARK fields, base_col_idx
is the same as col_idx
used in Self::get
method. For
extension fields, each column in the matrix is viewed as 2 or more columns in the base
field.
Thus, for example, if we are in a degree 2 extension field, base_col_idx = 0
would refer
to the first base element of the first column, base_col_idx = 1
would refer to the second
base element of the first column, base_col_idx = 2
would refer to the first base element
of the second column etc.
§Panics
Panics if either base_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]
pub fn get_column(&self, col_idx: usize) -> &[E]
Returns a reference to the column at the specified index.
Sourcepub fn get_column_mut(&mut self, col_idx: usize) -> &mut [E]
pub fn get_column_mut(&mut self, col_idx: usize) -> &mut [E]
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 merge_column(&mut self, column: Vec<E>)
pub fn merge_column(&mut self, column: Vec<E>)
Merges a column to the end of the matrix provided its length matches the matrix.
§Panics
Panics if the column has a different length to other columns in the matrix.
Sourcepub fn remove_column(&mut self, index: usize) -> Vec<E>
pub fn remove_column(&mut self, index: usize) -> Vec<E>
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) -> ColMatrix<E>
pub fn interpolate_columns(&self) -> ColMatrix<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) -> ColMatrix<E>
pub fn interpolate_columns_into(self) -> ColMatrix<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>,
) -> ColMatrix<E>
pub fn evaluate_columns_over( &self, domain: &StarkDomain<<E as FieldElement>::BaseField>, ) -> ColMatrix<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>where
F: FieldElement + From<E>,
pub fn evaluate_columns_at<F>(&self, x: F) -> Vec<F>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, V>(&self) -> V
pub fn commit_to_rows<H, V>(&self) -> V
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 vector of digests is committed to using the specified vector commitment scheme.
- The resulting commitment is returned as the commitment to the entire matrix.
Sourcepub fn into_columns(self) -> Vec<Vec<E>>
pub fn into_columns(self) -> Vec<Vec<E>>
Returns the columns of this matrix as a list of vectors.
TODO: replace this with an iterator.
Trait Implementations§
Auto Trait Implementations§
impl<E> Freeze for ColMatrix<E>
impl<E> RefUnwindSafe for ColMatrix<E>where
E: RefUnwindSafe,
impl<E> Send for ColMatrix<E>
impl<E> Sync for ColMatrix<E>
impl<E> Unpin for ColMatrix<E>where
E: Unpin,
impl<E> UnwindSafe for ColMatrix<E>where
E: 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more