Add FieldVar::inner_product and Sum bounds on FieldVar#173
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the FieldVar abstraction by adding a generic inner_product method and Sum trait support across various field variable types, enabling concise summation and dot-product operations in R1CS.
- Extended
FieldVartrait withinner_productandSumbounds - Implemented
SumforQuadExtVar,CubicExtVar, andEmulatedFpVar - Added optimized
inner_productand batch-sum helpers inAllocatedFpandFpVar
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/fields/quadratic_extension.rs | Added Sum impls for QuadExtVar |
| src/fields/mod.rs | Updated FieldVar trait with inner_product and Sum |
| src/fields/fp/mod.rs | Added add_many, linear_combination, and inner_product to AllocatedFp; updated FpVar uses |
| src/fields/emulated_fp/field_var.rs | Added Sum impls for EmulatedFpVar |
| src/fields/cubic_extension.rs | Added Sum impls for CubicExtVar |
| Cargo.toml | Introduced itertools dependency |
Comments suppressed due to low confidence (1)
src/fields/quadratic_extension.rs:562
- [nitpick] There are no unit tests covering the new
Sumimpl forQuadExtVaror theinner_productonFieldVar. Consider adding tests to validate these behaviors.
impl<BF, P> Sum<Self> for QuadExtVar<BF, P>
alireza-shirzad
approved these changes
May 30, 2025
Pratyush
commented
May 30, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds generic summation and inner-product capabilities to field variables, enabling dot products and collection-based sums across various field extensions.
- Extends
FieldVartrait withSumbounds and a defaultinner_productmethod. - Implements
SumforQuadExtVar,CubicExtVar, andEmulatedFpVar. - Provides specialized
inner_productand improved aggregation in thefpmodule, updatesAllocatedFp::add_many, and adds tests forFpVar.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/fields/mod.rs | Added Sum bounds and default inner_product to FieldVar. |
| src/fields/quadratic_extension.rs | Implemented Sum<Self> and Sum<&Self> for QuadExtVar. |
| src/fields/cubic_extension.rs | Implemented Sum<Self> and Sum<&Self> for CubicExtVar. |
| src/fields/fp/mod.rs | Updated add_many, added linear_combination, specialized inner_product and Sum for FpVar. |
| src/fields/emulated_fp/field_var.rs | Added Sum impls for EmulatedFpVar. |
| Cargo.toml | Added itertools dependency to support multiunzip and zip_eq. |
Comments suppressed due to low confidence (2)
src/fields/cubic_extension.rs:589
- [nitpick] Similarly, this collects three vectors, which may hurt performance. Consider a single-pass
foldto accumulatec0,c1, andc2without intermediate allocations.
let (c0s, c1s, c2s): (Vec<_>, Vec<_>, Vec<_>) = itertools::multiunzip(iter.map(|x| (x.c0, x.c1, x.c2)));
src/fields/quadratic_extension.rs:562
- [nitpick] There are currently no unit tests for the new
Sumandinner_productimplementations onQuadExtVar(and similarly forCubicExtVar). Adding tests for these will help catch future regressions.
impl<BF, P> Sum<Self> for QuadExtVar<BF, P>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Also fixes #151.
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pendingsection inCHANGELOG.mdFiles changedin the Github PR explorer