Change number of coeffs supported in ReducingGate depending on config

This commit is contained in:
wborgeaud 2021-07-23 17:35:23 +02:00
parent c16d93ab33
commit 5a16d7c555
2 changed files with 11 additions and 4 deletions

View File

@ -20,6 +20,10 @@ impl<const D: usize> ReducingGate<D> {
Self { num_coeffs }
}
pub fn max_coeffs_len(num_wires: usize, num_routed_wires: usize) -> usize {
(num_routed_wires - 3 * D).min((num_wires - 3 * D) / (D + 1))
}
pub fn wires_output() -> Range<usize> {
0..D
}

View File

@ -100,7 +100,10 @@ impl<const D: usize> ReducingFactorTarget<D> {
where
F: Extendable<D>,
{
let max_coeffs = 21;
let max_coeffs_len = ReducingGate::<D>::max_coeffs_len(
builder.config.num_wires,
builder.config.num_routed_wires,
);
self.count += terms.len() as u64;
let zero = builder.zero();
let zero_ext = builder.zero_extension();
@ -108,12 +111,12 @@ impl<const D: usize> ReducingFactorTarget<D> {
let mut gate_index;
let mut acc = zero_ext;
let mut reversed_terms = terms.to_vec();
while reversed_terms.len() % max_coeffs != 0 {
while reversed_terms.len() % max_coeffs_len != 0 {
reversed_terms.push(zero);
}
reversed_terms.reverse();
for chunk in reversed_terms.chunks_exact(max_coeffs) {
gate = ReducingGate::new(max_coeffs);
for chunk in reversed_terms.chunks_exact(max_coeffs_len) {
gate = ReducingGate::new(max_coeffs_len);
gate_index = builder.add_gate(gate.clone(), Vec::new());
builder.route_extension(