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));

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));

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));

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));

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));

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.

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.

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.

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.