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

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

A polynomial in the fourier domain.

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

Implementations

impl FourierPolynomial<AlignedVec<Complex64>>[src]

pub fn allocate(value: Complex64, coef_count: PolynomialSize) -> Self[src]

Allocates a new empty fourier polynomial.

Example

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

impl<Cont> FourierPolynomial<Cont>[src]

pub fn from_container(cont: Cont) -> Self[src]

Creates a complex polynomial from an existing container of values.

Example

use concrete_core::math::fft::{FourierPolynomial, Complex64};
use concrete_core::math::polynomial::PolynomialSize;
use fftw::array::AlignedVec;
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));

pub fn polynomial_size(&self) -> PolynomialSize where
    Self: AsRefTensor
[src]

Returns the number of coefficients in the polynomial.

Example

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

pub fn coefficient_iter(&self) -> impl Iterator<Item = &Complex64> where
    Self: AsRefTensor<Element = Complex64>, 
[src]

Returns an iterator over borrowed polynomial coefficients.

Note

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

Example

use concrete_core::math::fft::{FourierPolynomial, Complex64};
use concrete_core::math::polynomial::PolynomialSize;
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);

pub fn coefficient_iter_mut(&mut self) -> impl Iterator<Item = &mut Complex64> where
    Self: AsMutTensor<Element = Complex64>, 
[src]

Returns an iterator over mutably borrowed polynomial coefficients.

Note

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

Example

use concrete_core::math::fft::{FourierPolynomial, Complex64};
use concrete_core::math::polynomial::PolynomialSize;
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);

pub fn update_with_multiply_accumulate<PolyCont1, PolyCont2>(
    &mut self,
    poly_1: &FourierPolynomial<PolyCont1>,
    poly_2: &FourierPolynomial<PolyCont2>
) where
    Self: AsMutTensor<Element = Complex64>,
    FourierPolynomial<PolyCont1>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<PolyCont2>: AsRefTensor<Element = Complex64>, 
[src]

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_core::math::fft::{FourierPolynomial, Complex64};
use concrete_core::math::polynomial::PolynomialSize;
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.)));

pub fn update_with_two_multiply_accumulate<Cont1, Cont2, Cont3, Cont4>(
    &mut self,
    poly_1: &FourierPolynomial<Cont1>,
    poly_2: &FourierPolynomial<Cont2>,
    poly_3: &FourierPolynomial<Cont3>,
    poly_4: &FourierPolynomial<Cont4>
) where
    Self: AsMutTensor<Element = Complex64>,
    FourierPolynomial<Cont1>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<Cont2>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<Cont3>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<Cont4>: AsRefTensor<Element = Complex64>, 
[src]

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_core::math::fft::{FourierPolynomial, Complex64};
use concrete_core::math::polynomial::PolynomialSize;
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.)));

pub fn update_two_with_two_multiply_accumulate<C2, C3, C4, C5, C6, C7, C8>(
    result_1: &mut FourierPolynomial<Cont>,
    result_2: &mut FourierPolynomial<C2>,
    poly_a_1: &FourierPolynomial<C3>,
    poly_a_2: &FourierPolynomial<C7>,
    poly_b: &FourierPolynomial<C4>,
    poly_c_1: &FourierPolynomial<C5>,
    poly_c_2: &FourierPolynomial<C8>,
    poly_d: &FourierPolynomial<C6>
) where
    FourierPolynomial<Cont>: AsMutTensor<Element = Complex64>,
    FourierPolynomial<C2>: AsMutTensor<Element = Complex64>,
    FourierPolynomial<C3>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<C4>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<C5>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<C6>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<C7>: AsRefTensor<Element = Complex64>,
    FourierPolynomial<C8>: AsRefTensor<Element = Complex64>, 
[src]

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_core::math::fft::{FourierPolynomial, Complex64};
use concrete_core::math::polynomial::PolynomialSize;
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

impl<Element> AsMutTensor for FourierPolynomial<Vec<Element>>[src]

type Element = Element

The element type.

type Container = Vec<Element>

The container used by the tensor.

impl<Element> AsMutTensor for FourierPolynomial<[Element; 1]>[src]

type Element = Element

The element type.

type Container = [Element; 1]

The container used by the tensor.

impl<Element> AsMutTensor for FourierPolynomial<AlignedVec<Element>>[src]

type Element = Element

The element type.

type Container = AlignedVec<Element>

The container used by the tensor.

impl<'a, Element> AsMutTensor for FourierPolynomial<&'a mut [Element]>[src]

type Element = Element

The element type.

type Container = &'a mut [Element]

The container used by the tensor.

impl<Element> AsRefTensor for FourierPolynomial<Vec<Element>>[src]

type Element = Element

The element type.

type Container = Vec<Element>

The container used by the tensor.

impl<Element> AsRefTensor for FourierPolynomial<AlignedVec<Element>>[src]

type Element = Element

The element type.

type Container = AlignedVec<Element>

The container used by the tensor.

impl<Element> AsRefTensor for FourierPolynomial<[Element; 1]>[src]

type Element = Element

The element type.

type Container = [Element; 1]

The container used by the tensor.

impl<'a, Element> AsRefTensor for FourierPolynomial<&'a [Element]>[src]

type Element = Element

The element type.

type Container = &'a [Element]

The container used by the tensor.

impl<'a, Element> AsRefTensor for FourierPolynomial<&'a mut [Element]>[src]

type Element = Element

The element type.

type Container = &'a mut [Element]

The container used by the tensor.

impl<Cont: Clone> Clone for FourierPolynomial<Cont>[src]

impl<Cont: Debug> Debug for FourierPolynomial<Cont>[src]

impl<Element> IntoTensor for FourierPolynomial<Vec<Element>>[src]

type Element = Element

The element type of the collection container.

type Container = Vec<Element>

The type of the collection container.

impl<Element> IntoTensor for FourierPolynomial<AlignedVec<Element>>[src]

type Element = Element

The element type of the collection container.

type Container = AlignedVec<Element>

The type of the collection container.

impl<Element> IntoTensor for FourierPolynomial<[Element; 1]>[src]

type Element = Element

The element type of the collection container.

type Container = [Element; 1]

The type of the collection container.

impl<'a, Element> IntoTensor for FourierPolynomial<&'a [Element]>[src]

type Element = Element

The element type of the collection container.

type Container = &'a [Element]

The type of the collection container.

impl<'a, Element> IntoTensor for FourierPolynomial<&'a mut [Element]>[src]

type Element = Element

The element type of the collection container.

type Container = &'a mut [Element]

The type of the collection container.

Auto Trait Implementations

impl<Cont> RefUnwindSafe for FourierPolynomial<Cont> where
    Cont: RefUnwindSafe

impl<Cont> Send for FourierPolynomial<Cont> where
    Cont: Send

impl<Cont> Sync for FourierPolynomial<Cont> where
    Cont: Sync

impl<Cont> Unpin for FourierPolynomial<Cont> where
    Cont: Unpin

impl<Cont> UnwindSafe for FourierPolynomial<Cont> where
    Cont: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Input, Output> CastInto<Output> for Input where
    Output: CastFrom<Input>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.