1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use super::kernel::KernelParams;
use super::{Num, Setup};
use num_traits::Zero;
use std::borrow::Borrow;

/// Encapsulates the working area required for a transformation.
#[derive(Debug, Clone)]
pub struct Env<TNum, TSetupRef> {
    setup: TSetupRef,
    work_area: Vec<TNum>,
}

impl<TNum, TSetupRef> Env<TNum, TSetupRef>
where
    TNum: Num + 'static,
    TSetupRef: Borrow<Setup<TNum>>,
{
    pub fn new(setup: TSetupRef) -> Self {
        let work_area_size = setup.borrow().required_work_area_size();
        Env {
            setup: setup,
            work_area: vec![Zero::zero(); work_area_size],
        }
    }

    /// Transforms the supplied complex array `data` and writes the result to the same array (therefore this is an
    /// in-place operation).
    ///
    /// The array must be arranged in a interleaved order, in which the odd-th and even-th elements represent the real
    /// and imaginary components, respectively.
    pub fn transform(&mut self, data: &mut [TNum]) {
        let mut kernel_param = KernelParams {
            coefs: data,
            work_area: self.work_area.as_mut_slice(),
        };
        let setup = self.setup.borrow();
        for kernel in &setup.kernels {
            kernel.transform(&mut kernel_param);
        }
    }
}