chore: remove clippy warnings

This commit is contained in:
Alexander Camuto
2022-08-28 04:00:45 +02:00
parent 0d0584723d
commit 9b00e052bb
10 changed files with 1753 additions and 109 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
target

1696
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,7 @@
use halo2_proofs::{
arithmetic::FieldExt,
circuit::{layouter, AssignedCell, Layouter, Region, Value},
plonk::{
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Assigned, Circuit, Column,
ConstraintSystem, Constraints, Error, Expression, Selector,
},
circuit::{AssignedCell, Layouter, Region, Value},
plonk::{Advice, Assigned, Column, ConstraintSystem, Constraints, Expression, Selector},
poly::Rotation,
};
use std::marker::PhantomData;
@@ -129,7 +126,7 @@ where
// calculate value of output
let mut output: Vec<Value<Assigned<F>>> =
(0..OUT).map(|i| Value::known(F::zero().into())).collect();
(0..OUT).map(|_| Value::known(F::zero().into())).collect();
for i in 0..OUT {
for j in 0..IN {
@@ -189,7 +186,7 @@ where
constraints[i].clone() + virtual_cells.query_advice(bias, Rotation(i as i32));
}
let constraints = (0..OUT).map(|i| "c").zip(constraints);
let constraints = (0..OUT).map(|_| "c").zip(constraints);
Constraints::with_selector(q, constraints)
});
@@ -274,8 +271,8 @@ impl<F: FieldExt, const IN: usize, const OUT: usize> Affine1d<F, Value<Assigned<
let weights: Vec<Vec<Value<Assigned<F>>>> =
map2::<_, _, OUT, IN>(|i, j| Value::known(i32tofelt::<F>(weights[i][j]).into()));
let input: Vec<Value<Assigned<F>>> = (0..IN).map(|i| Value::default()).collect();
let output: Vec<Value<Assigned<F>>> = (0..OUT).map(|i| Value::default()).collect();
let input: Vec<Value<Assigned<F>>> = (0..IN).map(|_| Value::default()).collect();
let output: Vec<Value<Assigned<F>>> = (0..OUT).map(|_| Value::default()).collect();
Affine1d {
input,
@@ -292,7 +289,7 @@ impl<F: FieldExt, const IN: usize, const OUT: usize> Affine1d<F, Value<Assigned<
self.input = input.clone();
let mut output: Vec<Value<Assigned<F>>> =
(0..OUT).map(|i| Value::known(F::zero().into())).collect();
(0..OUT).map(|_| Value::known(F::zero().into())).collect();
for i in 0..OUT {
for j in 0..IN {
@@ -309,11 +306,3 @@ impl<F: FieldExt, const IN: usize, const OUT: usize> Affine1d<F, Value<Assigned<
output
}
}
#[cfg(test)]
use halo2_proofs::{
poly::commitment::Params,
transcript::{Blake2bRead, Blake2bWrite, Challenge255},
};
use pasta_curves::{pallas, vesta};
use rand::rngs::OsRng;

View File

@@ -74,7 +74,7 @@ where
* ((IMAGE_WIDTH + 2 * PADDING - KERNEL_WIDTH) / STRIDE + 1)]:,
{
pub fn configure(meta: &mut ConstraintSystem<F>, advices: Vec<Column<Advice>>) -> Self {
let output_height = (IMAGE_HEIGHT + 2 * PADDING - KERNEL_HEIGHT) / STRIDE + 1;
let _output_height = (IMAGE_HEIGHT + 2 * PADDING - KERNEL_HEIGHT) / STRIDE + 1;
let output_width = (IMAGE_WIDTH + 2 * PADDING - KERNEL_WIDTH) / STRIDE + 1;
for advice in advices.iter() {
@@ -408,7 +408,7 @@ mod tests {
config: Self::Config,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let output = config.assign(&mut layouter, self.image, self.kernels)?;
let _output = config.assign(&mut layouter, self.image, self.kernels)?;
Ok(())
}
}
@@ -416,7 +416,7 @@ mod tests {
#[test]
fn test_cnvrl() {
// use halo2_proofs::pasta::pallas;
use halo2curves::pasta::{pallas, vesta};
use halo2curves::pasta::{pallas};
const KERNEL_HEIGHT: usize = 3;
const KERNEL_WIDTH: usize = 3;

View File

@@ -1,39 +1,21 @@
use halo2_proofs::{
poly::{
commitment::ParamsProver,
ipa::{
commitment::{IPACommitmentScheme, ParamsIPA},
multiopen::ProverIPA,
strategy::SingleStrategy,
},
VerificationStrategy,
},
transcript::{TranscriptReadBuffer, TranscriptWriterBuffer},
};
use halo2_proofs::{
arithmetic::FieldExt,
circuit::{Layouter, SimpleFloorPlanner, Value},
plonk::{
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Assigned, Circuit, Column,
ConstraintSystem, Error, Instance,
},
poly::{commitment::Params, Rotation},
transcript::{Blake2bRead, Blake2bWrite, Challenge255},
plonk::{Circuit, Column, ConstraintSystem, Error, Instance},
};
use halo2curves::pasta::{pallas, vesta};
//use pasta_curves::{pallas, vesta};
// use rand::rngs::OsRng;
// use std::marker::PhantomData;
use crate::fieldutils::{felt_to_i32, i32tofelt};
use crate::fieldutils::felt_to_i32;
//use crate::tensorutils::{dot3, flatten3, flatten4, map2, map3, map3r, map4, map4r};
use std::cmp::max;
use crate::affine1d::{Affine1d, Affine1dConfig};
use crate::affine1d::Affine1dConfig;
use crate::cnvrl_generic;
use crate::eltwise::{DivideBy, Nonlin1d, NonlinConfig1d, ReLu};
use crate::eltwise::{DivideBy, NonlinConfig1d, ReLu};
#[derive(Clone)]
struct MyConfig<
@@ -179,7 +161,7 @@ where
// Here we wire together the layers by using the output advice in each layer as input advice in the next (not with copying / equality).
// This can be automated but we will sometimes want skip connections, etc. so we need the flexibility.
fn configure(cs: &mut ConstraintSystem<F>) -> Self::Config {
let output_height = (IMAGE_HEIGHT + 2 * PADDING - KERNEL_HEIGHT) / STRIDE + 1;
let _output_height = (IMAGE_HEIGHT + 2 * PADDING - KERNEL_HEIGHT) / STRIDE + 1;
let output_width = (IMAGE_WIDTH + 2 * PADDING - KERNEL_WIDTH) / STRIDE + 1;
// (IMAGE_HEIGHT + 2 * PADDING - KERNEL_HEIGHT) / STRIDE + 1 },
@@ -295,13 +277,13 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::fieldutils::felt_to_i32;
use crate::fieldutils::i32tofelt;
use halo2_proofs::{
arithmetic::{Field, FieldExt},
dev::{FailureLocation, MockProver, VerifyFailure},
// pasta::Fp as F,
plonk::{Any, Circuit},
plonk::{create_proof, keygen_pk, keygen_vk, verify_proof, Circuit},
transcript::{Blake2bRead, Blake2bWrite, Challenge255},
};
use halo2curves::pasta::vesta;
use halo2_proofs::{
poly::{
@@ -318,16 +300,16 @@ mod tests {
use halo2curves::pasta::Fp as F;
// use nalgebra;
use crate::cnvrl_generic::matrix;
use crate::fieldutils;
use crate::moreparams;
use crate::tensorutils::map4;
use halo2curves::pasta::pallas;
use mnist::*;
use ndarray::prelude::*;
use rand::prelude::*;
// use rand::prelude::*;
use rand::rngs::OsRng;
use std::time::{Duration, Instant};
use std::time::Instant;
const K: u32 = 17;
@@ -353,8 +335,8 @@ mod tests {
let Mnist {
trn_img,
trn_lbl,
tst_img,
tst_lbl,
tst_img: _,
tst_lbl: _,
..
} = MnistBuilder::new()
.label_format_digit()

View File

@@ -1,18 +1,13 @@
use halo2_proofs::{
arithmetic::FieldExt,
circuit::{AssignedCell, Layouter, Region, SimpleFloorPlanner, Value},
plonk::{
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Assigned, Circuit, Column,
ConstraintSystem, Constraints, Error, Expression, Instance, Selector, TableColumn,
},
poly::{commitment::Params, Rotation},
transcript::{Blake2bRead, Blake2bWrite, Challenge255},
plonk::{Advice, Assigned, Circuit, Column, ConstraintSystem, Error, Selector, TableColumn},
poly::Rotation,
};
use halo2curves::pasta::{pallas, vesta};
use std::{fmt::format, marker::PhantomData};
use std::marker::PhantomData;
use crate::fieldutils::{self, felt_to_i32, i32tofelt};
use crate::tensorutils::flatten3;
pub trait Nonlinearity<F: FieldExt> {
fn nonlinearity(x: i32) -> F;
@@ -36,7 +31,7 @@ impl<F: FieldExt, Inner, const LEN: usize, NL: Nonlinearity<F>> Nonlin1d<F, Inne
}
}
pub fn without_witnesses() -> Nonlin1d<F, Value<Assigned<F>>, LEN, NL> {
Nonlin1d::<F, Value<Assigned<F>>, LEN, NL>::fill(|i| Value::default())
Nonlin1d::<F, Value<Assigned<F>>, LEN, NL>::fill(|_| Value::default())
}
}
@@ -259,11 +254,6 @@ impl<
fn without_witnesses(&self) -> Self {
self.clone()
// let assigned = Nonlin1d::<F, Value<Assigned<F>>, LEN, NL>::fill(|i| Value::default());
// Self {
// assigned,
// _marker: PhantomData,
// }
}
fn configure(cs: &mut ConstraintSystem<F>) -> Self::Config {
@@ -334,15 +324,10 @@ impl<F: FieldExt, const D: usize> Nonlinearity<F> for DivideBy<F, D> {
#[cfg(test)]
mod tests {
use super::*;
use halo2_proofs::{
dev::{FailureLocation, MockProver, VerifyFailure},
plonk::{Any, Circuit},
};
use crate::tensorutils::flatten3;
use halo2_proofs::dev::MockProver;
use halo2curves::pasta::Fp as F;
// use nalgebra;
use std::time::{Duration, Instant};
#[test]
fn test_eltrelunl() {
let k = 9; //2^k rows
@@ -368,7 +353,7 @@ mod tests {
#[test]
fn test_eltsigmoid() {
for i in -127..127 {
let r = <Sigmoid<F, 128, 128> as Nonlinearity<F>>::nonlinearity(i);
let _r = <Sigmoid<F, 128, 128> as Nonlinearity<F>>::nonlinearity(i);
// println!("{i}, {:?}", r);
}
}
@@ -376,7 +361,7 @@ mod tests {
#[test]
fn test_eltdivide() {
for i in -127..127 {
let r = <DivideBy<F, 32> as Nonlinearity<F>>::nonlinearity(i);
let _r = <DivideBy<F, 32> as Nonlinearity<F>>::nonlinearity(i);
// println!("{i}, {:?}", r);
}
}

View File

@@ -26,7 +26,6 @@ pub fn felt_to_i32<F: FieldExt>(x: F) -> i32 {
mod test {
use super::*;
// use halo2_proofs::pasta::Fp as F;
use halo2curves::pasta::Fp as F;
#[test]

View File

@@ -1,11 +1,10 @@
use halo2_proofs::{
arithmetic::FieldExt,
circuit::{layouter, AssignedCell, Layouter, Region, Value},
circuit::{AssignedCell, Layouter, Value},
plonk::{
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Assigned, Circuit, Column,
ConstraintSystem, Constraints, Error, Expression, Selector,
Advice, Assigned, Column,
ConstraintSystem, Selector,
},
poly::Rotation,
};
use std::marker::PhantomData;

View File

@@ -1,9 +1,8 @@
use halo2_proofs::{
arithmetic::FieldExt,
circuit::{AssignedCell, Layouter, SimpleFloorPlanner, Value},
circuit::{Layouter, SimpleFloorPlanner},
plonk::{
//create_proof, keygen_pk, keygen_vk, verify_proof, Advice,
Assigned,
Circuit,
Column,
ConstraintSystem,
@@ -16,7 +15,7 @@ use halo2_proofs::{
//use pasta_curves::{pallas, vesta};
// use rand::rngs::OsRng;
// use std::marker::PhantomData;
use crate::fieldutils::i32tofelt;
use std::marker::PhantomData;
//use crate::tensorutils::{dot3, flatten3, flatten4, map2, map3, map3r, map4, map4r};
@@ -154,11 +153,11 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::fieldutils::felt_to_i32;
use halo2_proofs::dev::{FailureLocation, MockProver, VerifyFailure};
use crate::fieldutils::i32tofelt;
use halo2_proofs::dev::MockProver;
use halo2curves::pasta::Fp as F;
// use rand::prelude::*;
// use std::time::{Duration, Instant};
#[test]
fn test_rescale() {

View File

@@ -120,32 +120,26 @@ pub fn flatten4<T>(nested: Vec<Vec<Vec<Vec<T>>>>) -> Vec<T> {
}
pub fn dot3<F: FieldExt>(
a: &Vec<Vec<Vec<Expression<F>>>>,
b: &Vec<Vec<Vec<Expression<F>>>>,
a: &[Vec<Vec<Expression<F>>>],
b: &[Vec<Vec<Expression<F>>>],
) -> Expression<F> {
let aflat = a.into_iter().flatten().flatten(); //flatten3(a);
let bflat = b.into_iter().flatten().flatten();
let result = aflat
let aflat = a.iter().flatten().flatten(); //flatten3(a);
let bflat = b.iter().flatten().flatten();
aflat
.zip(bflat)
.map(|(x, y)| x.clone() * y.clone())
.fold(Expression::Constant(F::zero()), |sum, next| {
sum.clone() + next.clone()
});
result
.fold(Expression::Constant(F::zero()), |sum, next| sum + next)
}
pub fn dot3u(a: &Vec<Vec<Vec<u64>>>, b: &Vec<Vec<Vec<u64>>>) -> u64 {
let aflat = a.into_iter().flatten().flatten(); //flatten3(a);
let bflat = b.into_iter().flatten().flatten();
let result = aflat
.zip(bflat)
.map(|(x, y)| x.clone() * y.clone())
.fold(0u64, |sum, next| sum.clone() + next.clone());
result
pub fn dot3u(a: &[Vec<Vec<u64>>], b: &[Vec<Vec<u64>>]) -> u64 {
let aflat = a.iter().flatten().flatten(); //flatten3(a);
let bflat = b.iter().flatten().flatten();
aflat.zip(bflat).map(|(x, y)| x.clone() * y.clone()).sum()
}
mod test {
use super::*;
#[test]
fn indices4() {
let t: Vec<Vec<Vec<Vec<(usize, usize, usize, usize)>>>> =