Skip to content

Commit

Permalink
Change evaluation domain API for cosets (#487)
Browse files Browse the repository at this point in the history
Co-authored-by: Pratyush Mishra <[email protected]>
  • Loading branch information
andrewmilson and Pratyush authored Sep 29, 2022
1 parent ba9f533 commit 402e7f9
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 294 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
- New serialization format for Twisted Edwards curves:
- Points with a "positive" x-coordinate are serialized with the sign bit set to zero.
- Points with a "negative" x-coordinate are serialized with the sign bit set to one.
- [\#487](https://github.com/arkworks-rs/algebra/pull/487) (`ark-poly`) Refactor `EvaluationDomain` trait for cosets:
- Remove method `generator_inv`.
- Remove method `divide_by_vanishing_poly_on_coset_in_place`.
- Remove coset fft methods: `coset_fft`, `coset_fft_in_place`, `coset_ifft`, `coset_ifft_in_place`.

### Features

Expand All @@ -146,6 +150,10 @@
- [\#446](https://github.com/arkworks-rs/algebra/pull/446) (`ark-ff`) Add `CyclotomicMultSubgroup` trait and impl for extension fields
- [\#467](https://github.com/arkworks-rs/algebra/pull/467) (`ark-ec`)
- Move implementation of `serialize_with_mode()`, `deserialize_with_mode()`, and `serialized_size()` into `{SW,TE}CurveConfig` to allow customization.
- [\#487](https://github.com/arkworks-rs/algebra/pull/487) (`ark-poly`) Refactor `EvaluationDomain` trait for cosets:
- Add constructor `new_coset`.
- Add convenience method `get_coset`.
- Add methods `coset_offset`, `coset_offset_inv` and `coset_offset_pow_size`.

### Improvements

Expand Down
6 changes: 4 additions & 2 deletions poly-benches/benches/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,20 @@ fn bench_ifft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, deg
fn bench_coset_fft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, degree: &usize) {
// Per benchmark setup
let (domain, mut a) = fft_common_setup::<F, D>(*degree);
let coset_domain = domain.get_coset(F::GENERATOR).unwrap();
b.iter(|| {
// Per benchmark iteration
domain.coset_fft_in_place(&mut a);
coset_domain.fft_in_place(&mut a);
});
}

fn bench_coset_ifft_in_place<F: FftField, D: EvaluationDomain<F>>(b: &mut Bencher, degree: &usize) {
// Per benchmark setup
let (domain, mut a) = fft_common_setup::<F, D>(*degree);
let coset_domain = domain.get_coset(F::GENERATOR).unwrap();
b.iter(|| {
// Per benchmark iteration
domain.coset_ifft_in_place(&mut a);
coset_domain.ifft_in_place(&mut a);
});
}

Expand Down
33 changes: 17 additions & 16 deletions poly/src/domain/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ impl<F: FftField> EvaluationDomain<F> for GeneralEvaluationDomain<F> {
None
}

fn get_coset(&self, offset: F) -> Option<Self> {
Some(match self {
Self::Radix2(domain) => Self::Radix2(domain.get_coset(offset)?),
Self::MixedRadix(domain) => Self::MixedRadix(domain.get_coset(offset)?),
})
}

fn compute_size_of_domain(num_coeffs: usize) -> Option<usize> {
let domain_size = Radix2EvaluationDomain::<F>::compute_size_of_domain(num_coeffs);
if let Some(domain_size) = domain_size {
Expand Down Expand Up @@ -160,28 +167,27 @@ impl<F: FftField> EvaluationDomain<F> for GeneralEvaluationDomain<F> {
}

#[inline]
fn generator_inv(&self) -> F {
map!(self, generator_inv)
fn coset_offset(&self) -> F {
map!(self, coset_offset)
}

#[inline]
fn fft_in_place<T: DomainCoeff<F>>(&self, coeffs: &mut Vec<T>) {
map!(self, fft_in_place, coeffs)
fn coset_offset_inv(&self) -> F {
map!(self, coset_offset_inv)
}

#[inline]
fn ifft_in_place<T: DomainCoeff<F>>(&self, evals: &mut Vec<T>) {
map!(self, ifft_in_place, evals)
fn coset_offset_pow_size(&self) -> F {
map!(self, coset_offset_pow_size)
}

#[inline]
fn coset_fft_in_place<T: DomainCoeff<F>>(&self, coeffs: &mut Vec<T>) {
map!(self, coset_fft_in_place, coeffs)
fn fft_in_place<T: DomainCoeff<F>>(&self, coeffs: &mut Vec<T>) {
map!(self, fft_in_place, coeffs)
}

#[inline]
fn coset_ifft_in_place<T: DomainCoeff<F>>(&self, evals: &mut Vec<T>) {
map!(self, coset_ifft_in_place, evals)
fn ifft_in_place<T: DomainCoeff<F>>(&self, evals: &mut Vec<T>) {
map!(self, ifft_in_place, evals)
}

#[inline]
Expand All @@ -199,11 +205,6 @@ impl<F: FftField> EvaluationDomain<F> for GeneralEvaluationDomain<F> {
map!(self, evaluate_vanishing_polynomial, tau)
}

/// Returns the `i`-th element of the domain.
fn element(&self, i: usize) -> F {
map!(self, element, i)
}

/// Return an iterator over the elements of the domain.
fn elements(&self) -> GeneralElements<F> {
GeneralElements(map!(self, elements))
Expand Down
Loading

0 comments on commit 402e7f9

Please sign in to comment.