arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-hal/src/reference/fft64/reim4/mod.rs
poulpy-hal/src/reference/fft64/reim4/mod.rsRaw
 1mod arithmetic_ref;
 2
 3pub use arithmetic_ref::*;
 4
 5use crate::{layouts::Backend, reference::fft64::reim::as_arr_mut};
 6
 7pub trait Reim4Extract1BlkContiguous {
 8    fn reim4_extract_1blk_contiguous(m: usize, rows: usize, blk: usize, dst: &mut [f64], src: &[f64]);
 9}
10
11pub trait Reim4Save1BlkContiguous {
12    fn reim4_save_1blk_contiguous(m: usize, rows: usize, blk: usize, dst: &mut [f64], src: &[f64]);
13}
14
15pub trait Reim4Save1Blk {
16    fn reim4_save_1blk<const OVERWRITE: bool>(m: usize, blk: usize, dst: &mut [f64], src: &[f64]);
17}
18
19pub trait Reim4Save2Blks {
20    fn reim4_save_2blks<const OVERWRITE: bool>(m: usize, blk: usize, dst: &mut [f64], src: &[f64]);
21}
22
23pub trait Reim4Mat1ColProd {
24    fn reim4_mat1col_prod(nrows: usize, dst: &mut [f64], u: &[f64], v: &[f64]);
25}
26
27pub trait Reim4Mat2ColsProd {
28    fn reim4_mat2cols_prod(nrows: usize, dst: &mut [f64], u: &[f64], v: &[f64]);
29}
30
31pub trait Reim4Mat2Cols2ndColProd {
32    fn reim4_mat2cols_2ndcol_prod(nrows: usize, dst: &mut [f64], u: &[f64], v: &[f64]);
33}
34
35pub trait Reim4Convolution1Coeff {
36    fn reim4_convolution_1coeff(k: usize, dst: &mut [f64; 8], a: &[f64], a_size: usize, b: &[f64], b_size: usize);
37}
38
39pub trait Reim4Convolution2Coeffs {
40    fn reim4_convolution_2coeffs(k: usize, dst: &mut [f64; 16], a: &[f64], a_size: usize, b: &[f64], b_size: usize);
41}
42
43pub trait Reim4ConvolutionByRealConst1Coeff {
44    fn reim4_convolution_by_real_const_1coeff(k: usize, dst: &mut [f64; 8], a: &[f64], a_size: usize, b: &[f64]);
45}
46
47pub trait Reim4ConvolutionByRealConst2Coeffs {
48    fn reim4_convolution_by_real_const_2coeffs(k: usize, dst: &mut [f64; 16], a: &[f64], a_size: usize, b: &[f64]);
49}
50
51impl<BE: Backend> Reim4Convolution<BE> for BE where Self: Reim4Convolution1Coeff + Reim4Convolution2Coeffs {}
52
53pub trait Reim4Convolution<BE: Backend>
54where
55    BE: Reim4Convolution1Coeff + Reim4Convolution2Coeffs,
56{
57    fn reim4_convolution(dst: &mut [f64], dst_size: usize, offset: usize, a: &[f64], a_size: usize, b: &[f64], b_size: usize) {
58        assert!(a_size > 0);
59        assert!(b_size > 0);
60
61        for k in (0..dst_size - 1).step_by(2) {
62            BE::reim4_convolution_2coeffs(k + offset, as_arr_mut(&mut dst[8 * k..]), a, a_size, b, b_size);
63        }
64
65        if !dst_size.is_multiple_of(2) {
66            let k: usize = dst_size - 1;
67            BE::reim4_convolution_1coeff(k + offset, as_arr_mut(&mut dst[8 * k..]), a, a_size, b, b_size);
68        }
69    }
70}
71
72impl<BE: Backend> Reim4ConvolutionByRealConst<BE> for BE where
73    Self: Reim4ConvolutionByRealConst1Coeff + Reim4ConvolutionByRealConst2Coeffs
74{
75}
76
77pub trait Reim4ConvolutionByRealConst<BE: Backend>
78where
79    BE: Reim4ConvolutionByRealConst1Coeff + Reim4ConvolutionByRealConst2Coeffs,
80{
81    fn reim4_convolution_by_real_const(dst: &mut [f64], dst_size: usize, offset: usize, a: &[f64], a_size: usize, b: &[f64]) {
82        assert!(a_size > 0);
83
84        for k in (0..dst_size - 1).step_by(2) {
85            BE::reim4_convolution_by_real_const_2coeffs(k + offset, as_arr_mut(&mut dst[8 * k..]), a, a_size, b);
86        }
87
88        if !dst_size.is_multiple_of(2) {
89            let k: usize = dst_size - 1;
90            BE::reim4_convolution_by_real_const_1coeff(k + offset, as_arr_mut(&mut dst[8 * k..]), a, a_size, b);
91        }
92    }
93}