p3_dft/
util.rs

1use core::borrow::BorrowMut;
2
3use p3_field::Field;
4use p3_matrix::dense::{DenseMatrix, DenseStorage, RowMajorMatrix};
5use p3_matrix::Matrix;
6use tracing::instrument;
7
8/// Divide each coefficient of the given matrix by its height.
9#[instrument(skip_all, fields(dims = %mat.dimensions()))]
10pub fn divide_by_height<F: Field, S: DenseStorage<F> + BorrowMut<[F]>>(
11    mat: &mut DenseMatrix<F, S>,
12) {
13    mat.scale(F::from_canonical_usize(mat.height()).inverse())
14}
15
16/// Multiply each element of row `i` of `mat` by `shift**i`.
17pub(crate) fn coset_shift_cols<F: Field>(mat: &mut RowMajorMatrix<F>, shift: F) {
18    mat.rows_mut()
19        .zip(shift.powers())
20        .for_each(|(row, weight)| {
21            row.iter_mut().for_each(|coeff| {
22                *coeff *= weight;
23            })
24        });
25}