-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Field::sum_of_products
method
#80
base: main
Are you sure you want to change the base?
Conversation
9d9b11f
to
8ef6be8
Compare
Force-pushed to remove the |
8ef6be8
to
be49a7c
Compare
src/lib.rs
Outdated
/// above. Implementations of `Field` should override this to use more efficient | ||
/// methods that take advantage of their internal representation, such as interleaving | ||
/// or sharing modular reductions. | ||
fn sum_of_products<'a, I: IntoIterator<Item = (&'a Self, &'a Self)> + Clone>(pairs: I) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally made this an iterator of &(a, b)
, and I tested this against the array impl and saw little-to-no performance difference. I then changed it to an iterator of (&a, &b)
because I thought it would be more flexible, but doing that significantly hurts performance (I presume because we're calling .clone()
on an owned tuple that contains references, rather than on a reference).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, even using nicer tricks for constructing the input arrays, having this API take (&a, &b)
causes bls12_381
pairings to be over 5% slower compared to arrays or &(a, b)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried two iterators instead:
fn sum_of_products<'a>(
a: impl IntoIterator<Item = &'a Self> + Clone,
b: impl IntoIterator<Item = &'a Self> + Clone,
) -> Self
and then a.clone().into_iter().zip(b.clone().into_iter())
; this is similarly slower than arrays.
be49a7c
to
77fb7f0
Compare
77fb7f0
to
17a24ac
Compare
Force-pushed to re-introduce the faster array-based API (moving the iterator-based API to a different name). |
4e3cc87
to
6fd7771
Compare
While this PR adds APIs that could be introduced in a patch release, I'll instead propose adding them in 0.14.0. |
6fd7771
to
bf00cca
Compare
Force-pushed to fix rebase conflicts. |
Closes #79.