Struct concrete_core::math::fft::Fft [−][src]
pub struct Fft { /* fields omitted */ }
Expand description
A fast fourier transformer.
This transformer type allows to send polynomials of a fixed size, back and forth in the fourier domain.
Implementations
Generates a new transformer for polynomials a given size.
Example
use concrete_core::math::fft::Fft; use concrete_core::math::polynomial::PolynomialSize; let fft = Fft::new(PolynomialSize(256)); assert_eq!(fft.polynomial_size(), PolynomialSize(256));
Returns the polynomial size accepted by this transformer.
Example
use concrete_core::math::fft::Fft; use concrete_core::math::polynomial::PolynomialSize; let fft = Fft::new(PolynomialSize(256)); assert_eq!(fft.polynomial_size(), PolynomialSize(256));
pub fn forward_as_torus<OutCont, InCont, Coef>(
&mut self,
fourier_poly: &mut FourierPolynomial<OutCont>,
poly: &Polynomial<InCont>
) where
FourierPolynomial<OutCont>: AsMutTensor<Element = Complex64>,
Polynomial<InCont>: AsRefTensor<Element = Coef>,
Coef: UnsignedTorus,
pub fn forward_as_torus<OutCont, InCont, Coef>(
&mut self,
fourier_poly: &mut FourierPolynomial<OutCont>,
poly: &Polynomial<InCont>
) where
FourierPolynomial<OutCont>: AsMutTensor<Element = Complex64>,
Polynomial<InCont>: AsRefTensor<Element = Coef>,
Coef: UnsignedTorus,
Performs the forward fourier transform of the poly
polynomial, viewed as a polynomial of
torus coefficients, and stores the result in fourier_poly
.
Note
It should be noted that this method is subotpimal, as it only uses half of the computational
power of the transformer. For a faster approach, you should consider processing the
polynomials two by two with the Fft::forward_two_as_torus
method.
Example
use concrete_core::math::fft::{Fft, FourierPolynomial, Complex64}; use concrete_core::math::polynomial::{Polynomial, PolynomialSize}; use concrete_core::math::random::RandomGenerator; use concrete_core::math::tensor::AsRefTensor; use concrete_core::crypto::UnsignedTorus; let mut generator = RandomGenerator::new(None); let mut fft = Fft::new(PolynomialSize(256)); let mut fourier_poly = FourierPolynomial::allocate( Complex64::new(0.,0.), PolynomialSize(256) ); let mut poly = Polynomial::allocate(0u32, PolynomialSize(256)); generator.fill_tensor_with_random_uniform(&mut poly); fft.forward_as_torus(&mut fourier_poly, &poly); let mut out = Polynomial::allocate(0u32, PolynomialSize(256)); fft.add_backward_as_torus(&mut out, &mut fourier_poly); out.as_tensor() .iter() .zip(poly.as_tensor().iter()) .for_each(|(output, expected)| assert_eq!(*output, *expected));
pub fn forward_two_as_torus<InCont1, InCont2, OutCont1, OutCont2, Coef>(
&mut self,
fourier_poly_1: &mut FourierPolynomial<OutCont1>,
fourier_poly_2: &mut FourierPolynomial<OutCont2>,
poly_1: &Polynomial<InCont1>,
poly_2: &Polynomial<InCont2>
) where
Polynomial<InCont1>: AsRefTensor<Element = Coef>,
Polynomial<InCont2>: AsRefTensor<Element = Coef>,
FourierPolynomial<OutCont1>: AsMutTensor<Element = Complex64>,
FourierPolynomial<OutCont2>: AsMutTensor<Element = Complex64>,
Coef: UnsignedTorus,
pub fn forward_two_as_torus<InCont1, InCont2, OutCont1, OutCont2, Coef>(
&mut self,
fourier_poly_1: &mut FourierPolynomial<OutCont1>,
fourier_poly_2: &mut FourierPolynomial<OutCont2>,
poly_1: &Polynomial<InCont1>,
poly_2: &Polynomial<InCont2>
) where
Polynomial<InCont1>: AsRefTensor<Element = Coef>,
Polynomial<InCont2>: AsRefTensor<Element = Coef>,
FourierPolynomial<OutCont1>: AsMutTensor<Element = Complex64>,
FourierPolynomial<OutCont2>: AsMutTensor<Element = Complex64>,
Coef: UnsignedTorus,
Performs the forward fourier transform of the poly_1
and poly_2
polynomials, viewed
as polynomials of torus coefficients, and stores the result in fourier_poly_1
and
fourier_poly_2
.
Example
use concrete_core::math::fft::{Fft, FourierPolynomial, Complex64}; use concrete_core::math::polynomial::{Polynomial, PolynomialSize}; use concrete_core::math::random::RandomGenerator; use concrete_core::math::tensor::AsRefTensor; use concrete_core::crypto::UnsignedTorus; use concrete_commons::UnsignedInteger; let mut generator = RandomGenerator::new(None); let mut fft = Fft::new(PolynomialSize(256)); let mut fourier_poly_1 = FourierPolynomial::allocate( Complex64::new(0.,0.), PolynomialSize(256) ); let mut fourier_poly_2 = FourierPolynomial::allocate( Complex64::new(0.,0.), PolynomialSize(256) ); let mut poly_1 = Polynomial::allocate(0u32, PolynomialSize(256)); let mut poly_2 = Polynomial::allocate(0u32, PolynomialSize(256)); generator.fill_tensor_with_random_uniform(&mut poly_1); generator.fill_tensor_with_random_uniform(&mut poly_2); fft.forward_two_as_torus(&mut fourier_poly_1, &mut fourier_poly_2, &poly_1, &poly_2); let mut out_1 = Polynomial::allocate(0u32, PolynomialSize(256)); let mut out_2 = Polynomial::allocate(0u32, PolynomialSize(256)); fft.add_backward_two_as_torus( &mut out_1, &mut out_2, &mut fourier_poly_1, &mut fourier_poly_2 ); out_1.as_tensor() .iter() .zip(poly_1.as_tensor().iter()) .for_each(|(out, exp)| assert_eq!(out, exp)); out_2.as_tensor() .iter() .zip(poly_2.as_tensor().iter()) .for_each(|(out, exp)| assert_eq!(out, exp));
pub fn forward_as_integer<OutCont, InCont, Coef>(
&mut self,
fourier_poly: &mut FourierPolynomial<OutCont>,
poly: &Polynomial<InCont>
) where
FourierPolynomial<OutCont>: AsMutTensor<Element = Complex64>,
Polynomial<InCont>: AsRefTensor<Element = Coef>,
Coef: UnsignedInteger,
pub fn forward_as_integer<OutCont, InCont, Coef>(
&mut self,
fourier_poly: &mut FourierPolynomial<OutCont>,
poly: &Polynomial<InCont>
) where
FourierPolynomial<OutCont>: AsMutTensor<Element = Complex64>,
Polynomial<InCont>: AsRefTensor<Element = Coef>,
Coef: UnsignedInteger,
Performs the forward fourier transform of the poly
polynomial, viewed as a polynomial of
integer coefficients, and stores the result in fourier_poly
.
Note
It should be noted that this method is subotpimal, as it only uses half of the computational
power of the transformer. For a faster approach, you should consider processing the
polynomials two by two with the Fft::forward_two_as_integer
method.
Example
use concrete_core::math::fft::{Fft, FourierPolynomial, Complex64}; use concrete_core::math::polynomial::{Polynomial, PolynomialSize}; use concrete_core::math::random::RandomGenerator; use concrete_core::math::tensor::AsRefTensor; use concrete_commons::UnsignedInteger; let mut generator = RandomGenerator::new(None); let mut fft = Fft::new(PolynomialSize(256)); let mut fourier_poly = FourierPolynomial::allocate( Complex64::new(0.,0.), PolynomialSize(256) ); let mut poly = Polynomial::allocate(0u32, PolynomialSize(256)); generator.fill_tensor_with_random_uniform(&mut poly); fft.forward_as_integer(&mut fourier_poly, &poly); let mut out = Polynomial::allocate(0u32, PolynomialSize(256)); fft.add_backward_as_integer(&mut out, &mut fourier_poly); out.as_tensor() .iter() .zip(poly.as_tensor().iter()) .for_each(|(out, exp)| assert_eq!(*out, *exp));
pub fn forward_two_as_integer<InCont1, InCont2, OutCont1, OutCont2, Coef>(
&mut self,
fourier_poly_1: &mut FourierPolynomial<OutCont1>,
fourier_poly_2: &mut FourierPolynomial<OutCont2>,
poly_1: &Polynomial<InCont1>,
poly_2: &Polynomial<InCont2>
) where
Polynomial<InCont1>: AsRefTensor<Element = Coef>,
Polynomial<InCont2>: AsRefTensor<Element = Coef>,
FourierPolynomial<OutCont1>: AsMutTensor<Element = Complex64>,
FourierPolynomial<OutCont2>: AsMutTensor<Element = Complex64>,
Coef: UnsignedInteger,
pub fn forward_two_as_integer<InCont1, InCont2, OutCont1, OutCont2, Coef>(
&mut self,
fourier_poly_1: &mut FourierPolynomial<OutCont1>,
fourier_poly_2: &mut FourierPolynomial<OutCont2>,
poly_1: &Polynomial<InCont1>,
poly_2: &Polynomial<InCont2>
) where
Polynomial<InCont1>: AsRefTensor<Element = Coef>,
Polynomial<InCont2>: AsRefTensor<Element = Coef>,
FourierPolynomial<OutCont1>: AsMutTensor<Element = Complex64>,
FourierPolynomial<OutCont2>: AsMutTensor<Element = Complex64>,
Coef: UnsignedInteger,
Performs the forward fourier transform of the poly_1
and poly_2
polynomials, viewed
as polynomials of integer coefficients, and stores the result in fourier_poly_1
and
fourier_poly_2
.
Example
use concrete_core::math::fft::{Fft, FourierPolynomial, Complex64}; use concrete_core::math::polynomial::{Polynomial, PolynomialSize}; use concrete_core::math::random::RandomGenerator; use concrete_core::math::tensor::AsRefTensor; use concrete_commons::UnsignedInteger; let mut generator = RandomGenerator::new(None); let mut fft = Fft::new(PolynomialSize(256)); let mut fourier_poly_1 = FourierPolynomial::allocate( Complex64::new(0.,0.), PolynomialSize(256) ); let mut fourier_poly_2 = FourierPolynomial::allocate( Complex64::new(0.,0.), PolynomialSize(256) ); let mut poly_1 = Polynomial::allocate(0u32, PolynomialSize(256)); let mut poly_2 = Polynomial::allocate(0u32, PolynomialSize(256)); generator.fill_tensor_with_random_uniform(&mut poly_1); generator.fill_tensor_with_random_uniform(&mut poly_2); fft.forward_two_as_integer(&mut fourier_poly_1, &mut fourier_poly_2, &poly_1, &poly_2); let mut out_1 = Polynomial::allocate(0u32, PolynomialSize(256)); let mut out_2 = Polynomial::allocate(0u32, PolynomialSize(256)); fft.add_backward_two_as_integer( &mut out_1, &mut out_2, &mut fourier_poly_1, &mut fourier_poly_2 ); out_1.as_tensor() .iter() .zip(poly_1.as_tensor().iter()) .for_each(|(out, exp)| assert_eq!(out, exp)); out_2.as_tensor() .iter() .zip(poly_2.as_tensor().iter()) .for_each(|(out, exp)| assert_eq!(out, exp));
pub fn add_backward_as_torus<OutCont, InCont, Coef>(
&mut self,
poly: &mut Polynomial<OutCont>,
fourier_poly: &mut FourierPolynomial<InCont>
) where
Polynomial<OutCont>: AsMutTensor<Element = Coef>,
FourierPolynomial<InCont>: AsMutTensor<Element = Complex64>,
Coef: UnsignedTorus,
pub fn add_backward_as_torus<OutCont, InCont, Coef>(
&mut self,
poly: &mut Polynomial<OutCont>,
fourier_poly: &mut FourierPolynomial<InCont>
) where
Polynomial<OutCont>: AsMutTensor<Element = Coef>,
FourierPolynomial<InCont>: AsMutTensor<Element = Complex64>,
Coef: UnsignedTorus,
Performs the backward fourier transform of the fourier_poly
polynomial, viewed as a
polynomial of torus coefficients, and adds the result to poly
.
See Fft::forward_as_torus
for an example.
Note
It should be noted that this method is subotpimal, as it only uses half of the computational
power of the transformer. For a faster approach, you should consider processing the
polynomials two by two with the Fft::add_backward_two_as_torus
method.
pub fn add_backward_as_integer<OutCont, InCont, Coef>(
&mut self,
poly: &mut Polynomial<OutCont>,
fourier_poly: &mut FourierPolynomial<InCont>
) where
Polynomial<OutCont>: AsMutTensor<Element = Coef>,
FourierPolynomial<InCont>: AsMutTensor<Element = Complex64>,
Coef: UnsignedInteger,
pub fn add_backward_as_integer<OutCont, InCont, Coef>(
&mut self,
poly: &mut Polynomial<OutCont>,
fourier_poly: &mut FourierPolynomial<InCont>
) where
Polynomial<OutCont>: AsMutTensor<Element = Coef>,
FourierPolynomial<InCont>: AsMutTensor<Element = Complex64>,
Coef: UnsignedInteger,
Performs the backward fourier transform of the fourier_poly
polynomial, viewed as a
polynomial of integer coefficients, and adds the result to poly
.
See Fft::forward_as_integer
for an example.
Note
It should be noted that this method is subotpimal, as it only uses half of the computational
power of the transformer. For a faster approach, you should consider processing the
polynomials two by two with the Fft::add_backward_two_as_integer
method.
pub fn add_backward_two_as_torus<OutCont1, OutCont2, InCont1, InCont2, Coef>(
&mut self,
poly_1: &mut Polynomial<OutCont1>,
poly_2: &mut Polynomial<OutCont2>,
fourier_poly_1: &mut FourierPolynomial<InCont1>,
fourier_poly_2: &mut FourierPolynomial<InCont2>
) where
Polynomial<OutCont1>: AsMutTensor<Element = Coef>,
Polynomial<OutCont2>: AsMutTensor<Element = Coef>,
FourierPolynomial<InCont1>: AsMutTensor<Element = Complex64>,
FourierPolynomial<InCont2>: AsMutTensor<Element = Complex64>,
Coef: UnsignedTorus,
pub fn add_backward_two_as_torus<OutCont1, OutCont2, InCont1, InCont2, Coef>(
&mut self,
poly_1: &mut Polynomial<OutCont1>,
poly_2: &mut Polynomial<OutCont2>,
fourier_poly_1: &mut FourierPolynomial<InCont1>,
fourier_poly_2: &mut FourierPolynomial<InCont2>
) where
Polynomial<OutCont1>: AsMutTensor<Element = Coef>,
Polynomial<OutCont2>: AsMutTensor<Element = Coef>,
FourierPolynomial<InCont1>: AsMutTensor<Element = Complex64>,
FourierPolynomial<InCont2>: AsMutTensor<Element = Complex64>,
Coef: UnsignedTorus,
Performs the backward fourier transform of the fourier_poly_1
and fourier_poly_2
polynomials, viewed as polynomials of torus elements, and adds the result to the
poly_1
and poly_2
polynomials.
See Fft::forward_two_as_torus
for an example.
pub fn add_backward_two_as_integer<OutCont1, OutCont2, InCont1, InCont2, Coef>(
&mut self,
poly_1: &mut Polynomial<OutCont1>,
poly_2: &mut Polynomial<OutCont2>,
fourier_poly_1: &mut FourierPolynomial<InCont1>,
fourier_poly_2: &mut FourierPolynomial<InCont2>
) where
Polynomial<OutCont1>: AsMutTensor<Element = Coef>,
Polynomial<OutCont2>: AsMutTensor<Element = Coef>,
FourierPolynomial<InCont1>: AsMutTensor<Element = Complex64>,
FourierPolynomial<InCont2>: AsMutTensor<Element = Complex64>,
Coef: UnsignedInteger,
pub fn add_backward_two_as_integer<OutCont1, OutCont2, InCont1, InCont2, Coef>(
&mut self,
poly_1: &mut Polynomial<OutCont1>,
poly_2: &mut Polynomial<OutCont2>,
fourier_poly_1: &mut FourierPolynomial<InCont1>,
fourier_poly_2: &mut FourierPolynomial<InCont2>
) where
Polynomial<OutCont1>: AsMutTensor<Element = Coef>,
Polynomial<OutCont2>: AsMutTensor<Element = Coef>,
FourierPolynomial<InCont1>: AsMutTensor<Element = Complex64>,
FourierPolynomial<InCont2>: AsMutTensor<Element = Complex64>,
Coef: UnsignedInteger,
Performs the backward fourier transform of the fourier_poly_1
and fourier_poly_2
polynomials, viewed as polynomials of integer coefficients, and adds the result to the
poly_1
and poly_2
polynomials.
See Fft::forward_two_as_integer
for an example.
Auto Trait Implementations
impl RefUnwindSafe for Fft
impl UnwindSafe for Fft