From c01e772fd80526de8a4e803971498b5668fbee0b Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Wed, 23 Jun 2021 15:41:39 +0200 Subject: [PATCH] Simplify filter computation --- src/gates/gate.rs | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/gates/gate.rs b/src/gates/gate.rs index 2ab410d4..1e73e37d 100644 --- a/src/gates/gate.rs +++ b/src/gates/gate.rs @@ -59,17 +59,7 @@ pub trait Gate, const D: usize>: 'static + Send + Sync { ) -> Vec>; fn eval_filtered(&self, vars: EvaluationVars, prefix: &[bool]) -> Vec { - let filter: F::Extension = prefix - .iter() - .enumerate() - .map(|(i, &b)| { - if b { - vars.local_constants[i] - } else { - F::Extension::ONE - vars.local_constants[i] - } - }) - .product(); + let filter = compute_filter(prefix, vars.local_constants); self.eval_unfiltered(vars) .into_iter() .map(|c| filter * c) @@ -78,17 +68,7 @@ pub trait Gate, const D: usize>: 'static + Send + Sync { /// Like `eval_filtered`, but specialized for points in the base field. fn eval_filtered_base(&self, vars: EvaluationVarsBase, prefix: &[bool]) -> Vec { - let filter = prefix - .iter() - .enumerate() - .map(|(i, &b)| { - if b { - vars.local_constants[i] - } else { - F::ONE - vars.local_constants[i] - } - }) - .product(); + let filter = compute_filter(prefix, vars.local_constants); self.eval_unfiltered_base(vars) .into_iter() .map(|c| c * filter) @@ -180,6 +160,16 @@ impl, T: Borrow>, const D: usize> Index for Ga } } -// impl, const D: usize> GatePrefixes { -// pub fn prefix_len() -// } +fn compute_filter(prefix: &[bool], constants: &[K]) -> K { + prefix + .iter() + .enumerate() + .map(|(i, &b)| { + if b { + constants[i] + } else { + K::ONE - constants[i] + } + }) + .product() +}