Skip to content

Commit

Permalink
Merge pull request #6 from lita-xyz/revert-debug-trace
Browse files Browse the repository at this point in the history
Revert debug trace and add derives to TwoRowMatrixView
  • Loading branch information
incertia authored Sep 26, 2024
2 parents 460702d + 9eabb87 commit 1347efd
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 65 deletions.
15 changes: 5 additions & 10 deletions air/src/air.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use core::fmt::Debug;
use core::ops::{Add, Mul, Sub};

use p3_field::{AbstractExtensionField, AbstractField, ExtensionField, Field};
use p3_matrix::dense::RowMajorMatrix;
use p3_matrix::MatrixRowSlices;

/// An AIR (algebraic intermediate representation).
pub trait BaseAir<F: core::fmt::Debug>: Sync {
pub trait BaseAir<F>: Sync {
/// The number of private columns (a.k.a. registers) in this AIR.
fn width(&self) -> usize;

Expand Down Expand Up @@ -52,8 +51,7 @@ pub trait AirBuilder: Sized {
+ Sub<Self::Expr, Output = Self::Expr>
+ Mul<Self::F, Output = Self::Expr>
+ Mul<Self::Var, Output = Self::Expr>
+ Mul<Self::Expr, Output = Self::Expr>
+ Debug;
+ Mul<Self::Expr, Output = Self::Expr>;

type M: MatrixRowSlices<Self::Var>;

Expand Down Expand Up @@ -133,7 +131,7 @@ pub trait ExtensionBuilder: AirBuilder {

type ExprEF: AbstractExtensionField<Self::Expr, F = Self::EF>;

type VarEF: Into<Self::ExprEF> + Copy + Debug;
type VarEF: Into<Self::ExprEF> + Copy;

fn assert_zero_ext<I>(&mut self, x: I)
where
Expand All @@ -155,10 +153,7 @@ pub trait ExtensionBuilder: AirBuilder {
}
}

pub trait PermutationAirBuilder: ExtensionBuilder
where
<Self as ExtensionBuilder>::VarEF: Debug,
{
pub trait PermutationAirBuilder: ExtensionBuilder {
type MP: MatrixRowSlices<Self::VarEF>;

fn permutation(&self) -> Self::MP;
Expand Down Expand Up @@ -235,7 +230,7 @@ mod tests {
#[allow(dead_code)]
struct FibonacciAir;

impl<F: core::fmt::Debug> BaseAir<F> for FibonacciAir {
impl<F> BaseAir<F> for FibonacciAir {
fn width(&self) -> usize {
1
}
Expand Down
6 changes: 3 additions & 3 deletions air/src/two_row_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::slice;

use p3_matrix::{Matrix, MatrixRowSlices, MatrixRows};

#[derive(Copy, Clone, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct TwoRowMatrixView<'a, T> {
pub local: &'a [T],
pub next: &'a [T],
Expand All @@ -25,7 +25,7 @@ impl<'a, T> Matrix<T> for TwoRowMatrixView<'a, T> {
}
}

impl<T: Clone + core::fmt::Debug> MatrixRows<T> for TwoRowMatrixView<'_, T> {
impl<T: Clone> MatrixRows<T> for TwoRowMatrixView<'_, T> {
type Row<'a>
= Cloned<slice::Iter<'a, T>>
where
Expand All @@ -42,7 +42,7 @@ impl<T: Clone + core::fmt::Debug> MatrixRows<T> for TwoRowMatrixView<'_, T> {
}
}

impl<T: Clone + core::fmt::Debug> MatrixRowSlices<T> for TwoRowMatrixView<'_, T> {
impl<T: Clone> MatrixRowSlices<T> for TwoRowMatrixView<'_, T> {
fn row_slice(&self, r: usize) -> &[T] {
match r {
0 => self.local,
Expand Down
4 changes: 2 additions & 2 deletions commit/src/mmcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde::Serialize;
/// The `DirectMmcs` sub-trait represents an MMS which can be directly constructed from a set of
/// matrices. Other MMCSs may be virtual combinations of child MMCSs, or may be constructed in a
/// streaming manner.
pub trait Mmcs<T: core::fmt::Debug>: Clone {
pub trait Mmcs<T>: Clone {
type ProverData;
type Commitment: Clone + Serialize + DeserializeOwned;
type Proof: Serialize + DeserializeOwned;
Expand Down Expand Up @@ -72,7 +72,7 @@ pub trait Mmcs<T: core::fmt::Debug>: Clone {
}

/// An MMCS over explicit inputs which are supplied upfront.
pub trait DirectMmcs<T: core::fmt::Debug>: Mmcs<T> {
pub trait DirectMmcs<T>: Mmcs<T> {
fn commit(&self, inputs: Vec<RowMajorMatrix<T>>) -> (Self::Commitment, Self::ProverData);

fn commit_matrix(&self, input: RowMajorMatrix<T>) -> (Self::Commitment, Self::ProverData) {
Expand Down
2 changes: 1 addition & 1 deletion fri/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ where
}
}

struct CommitPhaseResult<F: std::fmt::Debug, M: Mmcs<F>> {
struct CommitPhaseResult<F, M: Mmcs<F>> {
commits: Vec<M::Commitment>,
data: Vec<M::ProverData>,
final_poly: F,
Expand Down
3 changes: 1 addition & 2 deletions keccak-air/src/air.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::borrow::Borrow;
use core::fmt::Debug;

use p3_air::{Air, AirBuilder, BaseAir};
use p3_field::AbstractField;
Expand All @@ -14,7 +13,7 @@ use crate::{BITS_PER_LIMB, NUM_ROUNDS, U64_LIMBS};
/// Assumes the field size is at least 16 bits.
pub struct KeccakAir {}

impl<F: Debug> BaseAir<F> for KeccakAir {
impl<F> BaseAir<F> for KeccakAir {
fn width(&self) -> usize {
NUM_KECCAK_COLS
}
Expand Down
16 changes: 6 additions & 10 deletions matrix/src/bitrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{Matrix, MatrixGet, MatrixRowSlices, MatrixRowSlicesMut, MatrixRows};
/// A matrix that is possibly bit-reversed, and can easily switch
/// between orderings. Pretty much just either `RowMajorMatrix` or
/// `BitReversedMatrixView<RowMajorMatrix>`.
pub trait BitReversableMatrix<T: core::fmt::Debug>: MatrixRowSlicesMut<T> {
pub trait BitReversableMatrix<T>: MatrixRowSlicesMut<T> {
type BitRev: BitReversableMatrix<T>;
fn bit_reverse_rows(self) -> Self::BitRev;
}
Expand Down Expand Up @@ -46,7 +46,7 @@ impl<T, Inner: MatrixGet<T>> MatrixGet<T> for BitReversedMatrixView<Inner> {
}
}

impl<T: core::fmt::Debug, Inner: MatrixRows<T>> MatrixRows<T> for BitReversedMatrixView<Inner> {
impl<T, Inner: MatrixRows<T>> MatrixRows<T> for BitReversedMatrixView<Inner> {
type Row<'a>
= Inner::Row<'a>
where
Expand All @@ -67,31 +67,27 @@ impl<T: core::fmt::Debug, Inner: MatrixRows<T>> MatrixRows<T> for BitReversedMat
}
}

impl<T: core::fmt::Debug, Inner: MatrixRowSlices<T>> MatrixRowSlices<T>
for BitReversedMatrixView<Inner>
{
impl<T, Inner: MatrixRowSlices<T>> MatrixRowSlices<T> for BitReversedMatrixView<Inner> {
fn row_slice(&self, r: usize) -> &[T] {
self.inner.row_slice(reverse_bits_len(r, self.log_height))
}
}

impl<T: core::fmt::Debug, Inner: MatrixRowSlicesMut<T>> MatrixRowSlicesMut<T>
for BitReversedMatrixView<Inner>
{
impl<T, Inner: MatrixRowSlicesMut<T>> MatrixRowSlicesMut<T> for BitReversedMatrixView<Inner> {
fn row_slice_mut(&mut self, r: usize) -> &mut [T] {
self.inner
.row_slice_mut(reverse_bits_len(r, self.log_height))
}
}

impl<T: Clone + Debug> BitReversableMatrix<T> for BitReversedMatrixView<RowMajorMatrix<T>> {
impl<T: Clone> BitReversableMatrix<T> for BitReversedMatrixView<RowMajorMatrix<T>> {
type BitRev = RowMajorMatrix<T>;
fn bit_reverse_rows(self) -> Self::BitRev {
self.inner
}
}

impl<T: Clone + Debug> BitReversableMatrix<T> for RowMajorMatrix<T> {
impl<T: Clone> BitReversableMatrix<T> for RowMajorMatrix<T> {
type BitRev = BitReversedMatrixView<RowMajorMatrix<T>>;
fn bit_reverse_rows(self) -> Self::BitRev {
BitReversedMatrixView::new(self)
Expand Down
32 changes: 15 additions & 17 deletions matrix/src/dense.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use alloc::fmt::Debug;
use alloc::vec;
use alloc::vec::Vec;
use core::iter::Cloned;
Expand All @@ -19,13 +18,13 @@ const TRANSPOSE_BLOCK_SIZE: usize = 64;
/// A dense matrix stored in row-major form.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct RowMajorMatrix<T: Debug> {
pub struct RowMajorMatrix<T> {
/// All values, stored in row-major order.
pub values: Vec<T>,
pub width: usize,
}

impl<T: Debug> RowMajorMatrix<T> {
impl<T> RowMajorMatrix<T> {
#[must_use]
pub fn new(values: Vec<T>, width: usize) -> Self {
debug_assert!(width == 0 || values.len() % width == 0);
Expand Down Expand Up @@ -102,7 +101,7 @@ impl<T: Debug> RowMajorMatrix<T> {
}
}

pub fn map<U: Debug, F: Fn(T) -> U>(&self, f: F) -> RowMajorMatrix<U>
pub fn map<U, F: Fn(T) -> U>(&self, f: F) -> RowMajorMatrix<U>
where
T: Clone,
{
Expand Down Expand Up @@ -182,7 +181,7 @@ impl<T: Debug> RowMajorMatrix<T> {
}
}

impl<T: core::fmt::Debug> Matrix<T> for RowMajorMatrix<T> {
impl<T> Matrix<T> for RowMajorMatrix<T> {
fn width(&self) -> usize {
self.width
}
Expand All @@ -196,14 +195,14 @@ impl<T: core::fmt::Debug> Matrix<T> for RowMajorMatrix<T> {
}
}

impl<T: Clone + core::fmt::Debug> MatrixGet<T> for RowMajorMatrix<T> {
impl<T: Clone> MatrixGet<T> for RowMajorMatrix<T> {
#[inline]
fn get(&self, r: usize, c: usize) -> T {
self.values[r * self.width + c].clone()
}
}

impl<T: Clone + core::fmt::Debug> MatrixRows<T> for RowMajorMatrix<T> {
impl<T: Clone> MatrixRows<T> for RowMajorMatrix<T> {
type Row<'a>
= Cloned<slice::Iter<'a, T>>
where
Expand All @@ -221,21 +220,21 @@ impl<T: Clone + core::fmt::Debug> MatrixRows<T> for RowMajorMatrix<T> {
}
}

impl<T: Clone + core::fmt::Debug> MatrixRowSlices<T> for RowMajorMatrix<T> {
impl<T: Clone> MatrixRowSlices<T> for RowMajorMatrix<T> {
fn row_slice(&self, r: usize) -> &[T] {
debug_assert!(r < self.height());
&self.values[r * self.width..(r + 1) * self.width]
}
}

impl<T: Clone + core::fmt::Debug> MatrixRowSlicesMut<T> for RowMajorMatrix<T> {
impl<T: Clone> MatrixRowSlicesMut<T> for RowMajorMatrix<T> {
fn row_slice_mut(&mut self, r: usize) -> &mut [T] {
debug_assert!(r < self.height());
&mut self.values[r * self.width..(r + 1) * self.width]
}
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone)]
pub struct RowMajorMatrixView<'a, T> {
pub values: &'a [T],
pub width: usize,
Expand Down Expand Up @@ -289,7 +288,7 @@ impl<T: Clone> MatrixGet<T> for RowMajorMatrixView<'_, T> {
}
}

impl<T: Clone + core::fmt::Debug> MatrixRows<T> for RowMajorMatrixView<'_, T> {
impl<T: Clone> MatrixRows<T> for RowMajorMatrixView<'_, T> {
type Row<'a>
= Cloned<slice::Iter<'a, T>>
where
Expand All @@ -309,14 +308,13 @@ impl<T: Clone + core::fmt::Debug> MatrixRows<T> for RowMajorMatrixView<'_, T> {
}
}

impl<T: Clone + core::fmt::Debug> MatrixRowSlices<T> for RowMajorMatrixView<'_, T> {
impl<T: Clone> MatrixRowSlices<T> for RowMajorMatrixView<'_, T> {
fn row_slice(&self, r: usize) -> &[T] {
debug_assert!(r < self.height());
&self.values[r * self.width..(r + 1) * self.width]
}
}

#[derive(Debug)]
pub struct RowMajorMatrixViewMut<'a, T> {
pub values: &'a mut [T],
pub width: usize,
Expand Down Expand Up @@ -429,7 +427,7 @@ impl<T: Clone> MatrixGet<T> for RowMajorMatrixViewMut<'_, T> {
}
}

impl<T: Clone + core::fmt::Debug> MatrixRows<T> for RowMajorMatrixViewMut<'_, T> {
impl<T: Clone> MatrixRows<T> for RowMajorMatrixViewMut<'_, T> {
type Row<'a>
= Cloned<slice::Iter<'a, T>>
where
Expand All @@ -449,14 +447,14 @@ impl<T: Clone + core::fmt::Debug> MatrixRows<T> for RowMajorMatrixViewMut<'_, T>
}
}

impl<T: Clone + core::fmt::Debug> MatrixRowSlices<T> for RowMajorMatrixViewMut<'_, T> {
impl<T: Clone> MatrixRowSlices<T> for RowMajorMatrixViewMut<'_, T> {
fn row_slice(&self, r: usize) -> &[T] {
debug_assert!(r < self.height());
&self.values[r * self.width..(r + 1) * self.width]
}
}

impl<T: Clone + core::fmt::Debug> MatrixRowSlicesMut<T> for RowMajorMatrixViewMut<'_, T> {
impl<T: Clone> MatrixRowSlicesMut<T> for RowMajorMatrixViewMut<'_, T> {
fn row_slice_mut(&mut self, r: usize) -> &mut [T] {
debug_assert!(r < self.height());
&mut self.values[r * self.width..(r + 1) * self.width]
Expand All @@ -465,7 +463,7 @@ impl<T: Clone + core::fmt::Debug> MatrixRowSlicesMut<T> for RowMajorMatrixViewMu

impl<T> MatrixTranspose<T> for RowMajorMatrix<T>
where
T: Clone + Default + Send + Sync + Debug,
T: Clone + Default + Send + Sync,
{
fn transpose(self) -> Self {
let block_size = TRANSPOSE_BLOCK_SIZE;
Expand Down
8 changes: 4 additions & 4 deletions matrix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait MatrixGet<T>: Matrix<T> {
}

/// A `Matrix` that supports randomly accessing particular rows.
pub trait MatrixRows<T: core::fmt::Debug>: Matrix<T> {
pub trait MatrixRows<T>: Matrix<T> {
type Row<'a>: IntoIterator<Item = T>
where
Self: 'a;
Expand Down Expand Up @@ -102,16 +102,16 @@ pub trait MatrixRows<T: core::fmt::Debug>: Matrix<T> {
}

/// A `Matrix` which supports access its rows as slices.
pub trait MatrixRowSlices<T: core::fmt::Debug>: MatrixRows<T> + Debug {
pub trait MatrixRowSlices<T>: MatrixRows<T> {
fn row_slice(&self, r: usize) -> &[T];
}

/// A `Matrix` which supports access its rows as mutable slices.
pub trait MatrixRowSlicesMut<T: core::fmt::Debug>: MatrixRowSlices<T> {
pub trait MatrixRowSlicesMut<T>: MatrixRowSlices<T> {
fn row_slice_mut(&mut self, r: usize) -> &mut [T];
}

/// A `TransposeMatrix` which supports transpose logic for matrices
pub trait MatrixTranspose<T: core::fmt::Debug>: MatrixRows<T> {
pub trait MatrixTranspose<T>: MatrixRows<T> {
fn transpose(self) -> Self;
}
1 change: 0 additions & 1 deletion matrix/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl<T, First, Second> MatrixRows<T> for VerticalPair<T, First, Second>
where
First: MatrixRows<T>,
Second: MatrixRows<T>,
T: core::fmt::Debug,
{
type Row<'a>
= EitherIterable<First::Row<'a>, Second::Row<'a>>
Expand Down
4 changes: 1 addition & 3 deletions matrix/src/strided.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ impl<T, Inner: MatrixGet<T>> MatrixGet<T> for VerticallyStridedMatrixView<Inner>
}
}

impl<T: core::fmt::Debug, Inner: MatrixRows<T>> MatrixRows<T>
for VerticallyStridedMatrixView<Inner>
{
impl<T, Inner: MatrixRows<T>> MatrixRows<T> for VerticallyStridedMatrixView<Inner> {
type Row<'a>
= Inner::Row<'a>
where
Expand Down
4 changes: 2 additions & 2 deletions matrix/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use p3_util::{log2_strict_usize, reverse_bits_len};
use crate::dense::RowMajorMatrix;
use crate::Matrix;

pub fn reverse_matrix_index_bits<F: core::fmt::Debug>(mat: &mut RowMajorMatrix<F>) {
pub fn reverse_matrix_index_bits<F>(mat: &mut RowMajorMatrix<F>) {
let w = mat.width();
let h = mat.height();
let log_h = log2_strict_usize(h);
Expand All @@ -20,7 +20,7 @@ pub fn reverse_matrix_index_bits<F: core::fmt::Debug>(mat: &mut RowMajorMatrix<F
}

/// Assumes `i < j`.
pub fn swap_rows<F: core::fmt::Debug>(mat: &mut RowMajorMatrix<F>, i: usize, j: usize) {
pub fn swap_rows<F>(mat: &mut RowMajorMatrix<F>, i: usize, j: usize) {
let w = mat.width();
let (upper, lower) = mat.values.split_at_mut(j * w);
let row_i = &mut upper[i * w..(i + 1) * w];
Expand Down
Loading

0 comments on commit 1347efd

Please sign in to comment.