Struct concrete_core::math::fft::FourierPolynomial[][src]

pub struct FourierPolynomial<Cont> { /* fields omitted */ }
Expand description

A polynomial in the fourier domain.

This structure represents a polynomial, which was put in the fourier domain.

Implementations

Allocates a new empty fourier polynomial.

Example

use concrete_commons::parameters::PolynomialSize;
use concrete_core::math::fft::{Complex64, FourierPolynomial};
let fourier_poly = FourierPolynomial::allocate(Complex64::new(0., 0.), PolynomialSize(128));
assert_eq!(fourier_poly.polynomial_size(), PolynomialSize(128));

Creates a complex polynomial from an existing container of values.

Example

use concrete_commons::parameters::PolynomialSize;
use concrete_core::math::fft::{AlignedVec, Complex64, FourierPolynomial};
let mut alvec: AlignedVec<Complex64> = AlignedVec::new(128);
let fourier_poly = FourierPolynomial::from_container(alvec.as_slice_mut());
assert_eq!(fourier_poly.polynomial_size(), PolynomialSize(128));

Returns the number of coefficients in the polynomial.

Example

use concrete_commons::parameters::PolynomialSize;
use concrete_core::math::fft::{Complex64, FourierPolynomial};
let fourier_poly = FourierPolynomial::allocate(Complex64::new(0., 0.), PolynomialSize(128));
assert_eq!(fourier_poly.polynomial_size(), PolynomialSize(128));

Returns an iterator over borrowed polynomial coefficients.

Note

We do not give any guarantee on the order of the coefficients.

Example

use concrete_commons::parameters::PolynomialSize;
use concrete_core::math::fft::{Complex64, FourierPolynomial};
let fourier_poly = FourierPolynomial::allocate(Complex64::new(0., 0.), PolynomialSize(128));
for coef in fourier_poly.coefficient_iter() {
    assert_eq!(*coef, Complex64::new(0., 0.));
}
assert_eq!(fourier_poly.coefficient_iter().count(), 128);

Returns an iterator over mutably borrowed polynomial coefficients.

Note

We do not give any guarantee on the order of the coefficients.

Example

use concrete_commons::parameters::PolynomialSize;
use concrete_core::math::fft::{Complex64, FourierPolynomial};
use concrete_core::math::tensor::AsRefTensor;
let mut fourier_poly = FourierPolynomial::allocate(Complex64::new(0., 0.), PolynomialSize(128));
for mut coef in fourier_poly.coefficient_iter_mut() {
    *coef = Complex64::new(1., 1.);
}
assert!(fourier_poly
    .as_tensor()
    .iter()
    .all(|a| *a == Complex64::new(1., 1.)));
assert_eq!(fourier_poly.coefficient_iter_mut().count(), 128);

Adds the result of the element-wise product of two polynomials to $(self.len()/2)+2$ elements of the current polynomial: $$ self[i] = self[i] + poly_1[i] * poly_2[i] $$

Example

use concrete_commons::parameters::PolynomialSize;
use concrete_core::math::fft::{Complex64, FourierPolynomial};
let mut fpoly1 = FourierPolynomial::allocate(Complex64::new(1., 2.), PolynomialSize(128));
let fpoly2 = FourierPolynomial::allocate(Complex64::new(3., 4.), PolynomialSize(128));
let fpoly3 = FourierPolynomial::allocate(Complex64::new(5., 6.), PolynomialSize(128));
fpoly1.update_with_multiply_accumulate(&fpoly2, &fpoly3);
// It actually update half+2 elements.
let half = fpoly1.polynomial_size().0 / 2 + 2;
assert!(fpoly1
    .coefficient_iter()
    .take(half)
    .all(|a| *a == Complex64::new(-8., 40.)));
assert!(fpoly1
    .coefficient_iter()
    .skip(half)
    .all(|a| *a == Complex64::new(1., 2.)));

Adds the result of the element-wise product of poly_1 with poly_2, and the result of the element-wise product of poly_3 with poly_4, to $(self.len()/2)+2$ elements of the current polynomial: $$ self[i] = self[i] + poly_1[i] * poly_2[i] + poly_3[i] * poly_4[i] $$

Example

use concrete_commons::parameters::PolynomialSize;
use concrete_core::math::fft::{Complex64, FourierPolynomial};
let mut fpoly1 = FourierPolynomial::allocate(Complex64::new(1., 2.), PolynomialSize(128));
let fpoly2 = FourierPolynomial::allocate(Complex64::new(3., 4.), PolynomialSize(128));
let fpoly3 = FourierPolynomial::allocate(Complex64::new(5., 6.), PolynomialSize(128));
let fpoly4 = FourierPolynomial::allocate(Complex64::new(7., 8.), PolynomialSize(128));
let fpoly5 = FourierPolynomial::allocate(Complex64::new(9., 10.), PolynomialSize(128));
fpoly1.update_with_two_multiply_accumulate(&fpoly2, &fpoly3, &fpoly4, &fpoly5);
// It actually update half+2 elements.
let half = fpoly1.polynomial_size().0 / 2 + 2;
assert!(fpoly1
    .coefficient_iter()
    .take(half)
    .all(|a| *a == Complex64::new(-25., 182.)));
assert!(fpoly1
    .coefficient_iter()
    .skip(half)
    .all(|a| *a == Complex64::new(1., 2.)));

Updates two polynomials with the following operation:

$$ result_1[i]=result_1[i]+poly_{a_1}[i]*poly_b[i]+poly_{c_1}[i]*poly_d[i]\\ result_2[i]=result_2[i]+poly_{a_2}[i]*poly_b[i]+poly_{c_2}[i]*poly_d[i] $$

Example

use concrete_commons::parameters::PolynomialSize;
use concrete_core::math::fft::{Complex64, FourierPolynomial};
macro_rules! new_poly {
    ($name: ident, $re: literal, $im: literal) => {
        let mut $name =
            FourierPolynomial::allocate(Complex64::new($re, $im), PolynomialSize(128));
    };
}
new_poly!(fpoly_1, 1., 2.);
new_poly!(fpoly_2, 3., 4.);
new_poly!(fpoly_3, 5., 6.);
new_poly!(fpoly_4, 7., 8.);
new_poly!(fpoly_5, 9., 10.);
new_poly!(fpoly_6, 11., 12.);
new_poly!(fpoly_7, 13., 14.);
new_poly!(fpoly_8, 15., 16.);
FourierPolynomial::update_two_with_two_multiply_accumulate(
    &mut fpoly_1,
    &mut fpoly_2,
    &fpoly_3,
    &fpoly_4,
    &fpoly_5,
    &fpoly_6,
    &fpoly_7,
    &fpoly_8,
);
// It actually update half+2 elements.
let half = fpoly_1.polynomial_size().0 / 2 + 2;
assert!(fpoly_1
    .coefficient_iter()
    .take(half)
    .all(|a| *a == Complex64::new(-41., 462.)));
assert!(fpoly_1
    .coefficient_iter()
    .skip(half)
    .all(|a| *a == Complex64::new(1., 2.)));
assert!(fpoly_2
    .coefficient_iter()
    .take(half)
    .all(|a| *a == Complex64::new(-43., 564.)));
assert!(fpoly_2
    .coefficient_iter()
    .skip(half)
    .all(|a| *a == Complex64::new(3., 4.)));

Trait Implementations

The element type.

The container used by the tensor.

Returns a mutable reference to the enclosed tensor.

The element type.

The container used by the tensor.

Returns a reference to the enclosed tensor.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

The element type of the collection container.

The type of the collection container.

Consumes self and returns an owned tensor.

Serialize this value into the given Serde serializer. Read more

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.