Skip to content

Commit

Permalink
relation tracker bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ohad-starkware committed Dec 3, 2024
1 parent df4a642 commit e25b37d
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions crates/prover/src/constraint_framework/relation_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ impl<'a> EvalAtRow for RelationTrackerEvaluator<'a> {
if cannonical_index >= self.n_rows {
continue;
}
let values = values.iter().map(|v| v[j]).collect_vec();
let mut values = values.iter().map(|v| v[j]).collect_vec();
while values.last().is_some_and(|v| v.is_zero()) {
values.pop();
}
let mult = mult[j].to_m31_array()[0];
self.entries.push(RelationTrackerEntry {
relation: relation.clone(),
Expand All @@ -194,9 +197,15 @@ impl RelationSummary {
/// Returns the sum of every entry's yields and uses.
/// The result is a map from relation name to a list of values(M31 vectors) and their sum.
pub fn summarize_relations(entries: &[RelationTrackerEntry]) -> Self {
let mut entry_by_relation = HashMap::new();
for entry in entries {
entry_by_relation
.entry(entry.relation.clone())
.or_insert_with(Vec::new)
.push(entry);
}
let mut summary = vec![];
let relations = entries.iter().group_by(|entry| entry.relation.clone());
for (relation, entries) in &relations {
for (relation, entries) in entry_by_relation {
let mut relation_sums: HashMap<Vec<_>, M31> = HashMap::new();
for entry in entries {
let mult = relation_sums
Expand All @@ -216,6 +225,22 @@ impl RelationSummary {
.find(|(name, _)| name == relation)
.map(|(_, entries)| entries.as_slice())
}

pub fn cleaned(self) -> Self {
let mut cleaned = vec![];
for (relation, entries) in self.0 {
let mut cleaned_entries = vec![];
for (vector, sum) in entries {
if !sum.is_zero() {
cleaned_entries.push((vector, sum));
}
}
if !cleaned_entries.is_empty() {
cleaned.push((relation, cleaned_entries));
}
}
Self(cleaned)
}
}
impl Debug for RelationSummary {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down

0 comments on commit e25b37d

Please sign in to comment.