Trait feanor_math::algorithms::fft::FFTAlgorithm
source · pub trait FFTAlgorithm<R: ?Sized + RingBase> {
// Required methods
fn len(&self) -> usize;
fn root_of_unity(&self, ring: &R) -> &R::Element;
fn unordered_fft_permutation(&self, i: usize) -> usize;
fn unordered_fft_permutation_inv(&self, i: usize) -> usize;
fn unordered_fft<V>(&self, values: V, ring: &R)
where V: SwappableVectorViewMut<R::Element>;
fn unordered_inv_fft<V>(&self, values: V, ring: &R)
where V: SwappableVectorViewMut<R::Element>;
// Provided methods
fn fft<V>(&self, values: V, ring: &R)
where V: SwappableVectorViewMut<R::Element> { ... }
fn inv_fft<V>(&self, values: V, ring: &R)
where V: SwappableVectorViewMut<R::Element> { ... }
}
Expand description
Trait for objects that can perform a fast fourier transform over some ring.
Usually fast implementations of FFTs have to store a lot of precomputed data (e.g. powers of roots of unity), hence they should be represented as objects implementing this trait.
§Note on equality
If you choose to implement PartialEq
for an FFTTable, and F == G
, then
F
and G
should satisfy the following properties:
F
andG
support the same ringsF.len() == G.len()
F.root_of_unity(ring) == G.root_of_unity(ring)
for each supported ringring
F.unordered_fft_permutation(i) == G.unordered_fft_permutation(i)
for alli
In other words,F
andG
must have exactly the same output forunordered_fft
(and thusfft
,inv_fft
, …) on same inputs.
Required Methods§
sourcefn root_of_unity(&self, ring: &R) -> &R::Element
fn root_of_unity(&self, ring: &R) -> &R::Element
The root of unity used for the FFT. While all primitive n
-th roots
of unity can be used equally for computing a Fourier transform, the
concrete one used determines the order of the output values.
sourcefn unordered_fft_permutation(&self, i: usize) -> usize
fn unordered_fft_permutation(&self, i: usize) -> usize
On input i
, returns j
such that unordered_fft(values)[i]
contains the evaluation
at zeta^j
of values. Here zeta
is the value returned by FFTAlgorithm::root_of_unity()
sourcefn unordered_fft_permutation_inv(&self, i: usize) -> usize
fn unordered_fft_permutation_inv(&self, i: usize) -> usize
The inverse of FFTAlgorithm::unordered_fft_permutation()
, i.e. for all i, have
self.unordered_fft_permutation_inv(self.unordered_fft_permutation(i)) == i
.
sourcefn unordered_fft<V>(&self, values: V, ring: &R)where
V: SwappableVectorViewMut<R::Element>,
fn unordered_fft<V>(&self, values: V, ring: &R)where
V: SwappableVectorViewMut<R::Element>,
Computes the Fourier transform of the given values, but the output values are arbitrarily permuted
(in a way compatible with FFTAlgorithm::unordered_inv_fft()
).
Note that the FFT of a sequence a_0, ..., a_(N - 1)
is defined as Fa_k = sum_i a_i z^(-ik)
where z
is an N-th root of unity.
sourcefn unordered_inv_fft<V>(&self, values: V, ring: &R)where
V: SwappableVectorViewMut<R::Element>,
fn unordered_inv_fft<V>(&self, values: V, ring: &R)where
V: SwappableVectorViewMut<R::Element>,
Inverse to FFTAlgorithm::unordered_fft()
, with basically the same contract.
Provided Methods§
sourcefn fft<V>(&self, values: V, ring: &R)where
V: SwappableVectorViewMut<R::Element>,
fn fft<V>(&self, values: V, ring: &R)where
V: SwappableVectorViewMut<R::Element>,
Computes the Fourier transform of the given values
over the specified ring.
The output is in standard order, i.e. the i
-th output element is the evaluation
of the input at self.root_of_unity()^-i
(note the -
, which is standard
convention for Fourier transforms).
§Panics
This function panics if values.len() != self.len()
.
sourcefn inv_fft<V>(&self, values: V, ring: &R)where
V: SwappableVectorViewMut<R::Element>,
fn inv_fft<V>(&self, values: V, ring: &R)where
V: SwappableVectorViewMut<R::Element>,
Computes the Fourier transform of the given values
over the specified ring.
The output is in standard order, i.e. the i
-th output element is the evaluation
of the input at self.root_of_unity()^i
, divided by self.len()
.
§Panics
This function panics if values.len() != self.len()
.