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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use super::super::{ComplexNumberSpace, Domain, DspVec, MetaData, ToSliceMut, Vector};
use crate::array_to_complex_mut;
use crate::multicore_support::*;
use crate::numbers::*;
use crate::simd_extensions::*;
pub trait ComplexOps<T>
where
T: RealNumber,
{
fn multiply_complex_exponential(&mut self, a: T, b: T);
fn conj(&mut self);
}
macro_rules! assert_complex {
($self_: ident) => {
if !$self_.is_complex() {
$self_.number_space.to_real();
$self_.mark_vector_as_invalid();
}
};
}
impl<S, T, N, D> ComplexOps<T> for DspVec<S, T, N, D>
where
S: ToSliceMut<T>,
T: RealNumber,
N: ComplexNumberSpace,
D: Domain,
{
fn multiply_complex_exponential(&mut self, a: T, b: T) {
assert_complex!(self);
let a = a * self.delta();
let b = b * self.delta();
let data_length = self.len();
let array = self.data.to_slice_mut();
Chunk::execute_with_range(
Complexity::Small,
&self.multicore_settings,
&mut array[0..data_length],
2,
(a, b),
move |array, range, args| {
let (a, b) = args;
let mut exponential = Complex::<T>::from_polar(&T::one(), &b)
* Complex::<T>::from_polar(&T::one(), &(a * T::from(range.start / 2).unwrap()));
let increment = Complex::<T>::from_polar(&T::one(), &a);
let array = array_to_complex_mut(array);
for complex in array {
*complex = (*complex) * exponential;
exponential = exponential * increment;
}
},
);
}
fn conj(&mut self) {
assert_complex!(self);
let factor = Complex::<T>::new(T::one(), -T::one());
sel_reg!(self.simd_complex_operationf::<T>(
|x, y| x * y,
|x, _| x.conj(),
factor,
Complexity::Small
))
}
}