1use super::*;
2use crate::TransformContent;
3use std::marker;
4
5macro_rules! add_mat_impl {
6 ($($matrix:ident);*) => {
7 $(
8 impl <V: Vector<T> + ToRealResult, S: ToSlice<T>, T: RealNumber>
9 ToRealResult for $matrix<V, S, T>
10 where <V as ToRealResult>::RealResult: Vector<T> {
11 type RealResult = $matrix<V::RealResult, S, T>;
12 }
13
14 impl<V: Vector<T>, S: ToSlice<T>, T: RealNumber>
15 ComplexToRealTransformsOps<T> for $matrix<V, S, T>
16 where <V as ToRealResult>::RealResult: Vector<T>,
17 V: ComplexToRealTransformsOps<T> {
18 fn magnitude(self) -> Self::RealResult {
19 let rows = self.rows.transform(|v|v.magnitude());
20 $matrix {
21 rows: rows,
22 storage_type: marker::PhantomData,
23 number_type: marker::PhantomData
24 }
25 }
26
27 fn magnitude_squared(self) -> Self::RealResult {
28 let rows = self.rows.transform(|v|v.magnitude_squared());
29 $matrix {
30 rows: rows,
31 storage_type: marker::PhantomData,
32 number_type: marker::PhantomData
33 }
34 }
35
36 fn to_real(self) -> Self::RealResult {
37 let rows = self.rows.transform(|v|v.to_real());
38 $matrix {
39 rows: rows,
40 storage_type: marker::PhantomData,
41 number_type: marker::PhantomData
42 }
43 }
44
45 fn to_imag(self) -> Self::RealResult {
46 let rows = self.rows.transform(|v|v.to_imag());
47 $matrix {
48 rows: rows,
49 storage_type: marker::PhantomData,
50 number_type: marker::PhantomData
51 }
52 }
53
54 fn phase(self) -> Self::RealResult {
55 let rows = self.rows.transform(|v|v.phase());
56 $matrix {
57 rows: rows,
58 storage_type: marker::PhantomData,
59 number_type: marker::PhantomData
60 }
61 }
62 }
63
64 impl<V: Vector<T>, S: ToSliceMut<T>, T: RealNumber>
65 ComplexToRealTransformsOpsBuffered<S, T> for $matrix<V, S, T>
66 where <V as ToRealResult>::RealResult: Vector<T>,
67 V: ComplexToRealTransformsOpsBuffered<S, T> {
68 fn magnitude_b<B>(self, buffer: &mut B) -> Self::RealResult
69 where B: for<'b> Buffer<'b, S, T> {
70 let rows = self.rows.transform(|v|v.magnitude_b(buffer));
71 $matrix {
72 rows: rows,
73 storage_type: marker::PhantomData,
74 number_type: marker::PhantomData
75 }
76 }
77
78 fn magnitude_squared_b<B>(self, buffer: &mut B) -> Self::RealResult
79 where B: for<'b> Buffer<'b, S, T> {
80 let rows = self.rows.transform(|v|v.magnitude_squared_b(buffer));
81 $matrix {
82 rows: rows,
83 storage_type: marker::PhantomData,
84 number_type: marker::PhantomData
85 }
86 }
87
88 fn to_real_b<B>(self, buffer: &mut B) -> Self::RealResult
89 where B: for<'b> Buffer<'b, S, T> {
90 let rows = self.rows.transform(|v|v.to_real_b(buffer));
91 $matrix {
92 rows: rows,
93 storage_type: marker::PhantomData,
94 number_type: marker::PhantomData
95 }
96 }
97
98 fn to_imag_b<B>(self, buffer: &mut B) -> Self::RealResult
99 where B: for<'b> Buffer<'b, S, T> {
100 let rows = self.rows.transform(|v|v.to_imag_b(buffer));
101 $matrix {
102 rows: rows,
103 storage_type: marker::PhantomData,
104 number_type: marker::PhantomData
105 }
106 }
107
108 fn phase_b<B>(self, buffer: &mut B) -> Self::RealResult
109 where B: for<'b> Buffer<'b, S, T> {
110 let rows = self.rows.transform(|v|v.phase_b(buffer));
111 $matrix {
112 rows: rows,
113 storage_type: marker::PhantomData,
114 number_type: marker::PhantomData
115 }
116 }
117 }
118
119 impl<V: Vector<T>, S: ToSlice<T>, T: RealNumber, N: NumberSpace, D: Domain, O>
120 ComplexToRealGetterOps<O, T, N, D> for $matrix<V, S, T>
121 where O: Matrix<V, T> + GetMetaData<T, N, D>,
122 V: ComplexToRealGetterOps<V, T, N, D> + GetMetaData<T, N, D> {
123 fn get_real(&self, destination: &mut O) {
124 for (o, v) in destination.rows_mut().iter_mut().zip(self.rows()) {
125 v.get_real(o);
126 }
127 }
128
129 fn get_imag(&self, destination: &mut O) {
130 for (o, v) in destination.rows_mut().iter_mut().zip(self.rows()) {
131 v.get_imag(o);
132 }
133 }
134
135 fn get_magnitude(&self, destination: &mut O) {
136 for (o, v) in destination.rows_mut().iter_mut().zip(self.rows()) {
137 v.get_imag(o);
138 }
139 }
140
141 fn get_magnitude_squared(&self, destination: &mut O) {
142 for (o, v) in destination.rows_mut().iter_mut().zip(self.rows()) {
143 v.get_imag(o);
144 }
145 }
146
147 fn get_phase(&self, destination: &mut O) {
148 for (o, v) in destination.rows_mut().iter_mut().zip(self.rows()) {
149 v.get_imag(o);
150 }
151 }
152
153 fn get_real_imag(&self,
154 real: &mut O,
155 imag: &mut O) {
156 for ((r, i), v) in real.rows_mut().iter_mut()
157 .zip(imag.rows_mut())
158 .zip(self.rows()) {
159 v.get_real_imag(r, i);
160 }
161 }
162
163 fn get_mag_phase(&self,
164 mag: &mut O,
165 phase: &mut O) {
166 for ((r, i), v) in mag.rows_mut().iter_mut()
167 .zip(phase.rows_mut())
168 .zip(self.rows()) {
169 v.get_mag_phase(r, i);
170 }
171 }
172 }
173
174 impl<V: Vector<T>, S: ToSlice<T>, T: RealNumber, N: NumberSpace, D: Domain, O>
175 ComplexToRealSetterOps<O, T, N, D> for $matrix<V, S, T>
176 where O: Matrix<V, T> + GetMetaData<T, N, D>,
177 V: ComplexToRealSetterOps<V, T, N, D> + GetMetaData<T, N, D> {
178 fn set_real_imag(&mut self,
179 real: &O,
180 imag: &O) -> VoidResult {
181 for ((v, r), i) in self.rows_mut().iter_mut()
182 .zip(real.rows())
183 .zip(imag.rows()) {
184 v.set_real_imag(r, i)?;
185 }
186
187 Ok(())
188 }
189
190 fn set_mag_phase(&mut self,
191 mag: &O,
192 phase: &O) -> VoidResult {
193 for ((v, r), i) in self.rows_mut().iter_mut()
194 .zip(mag.rows())
195 .zip(phase.rows()) {
196 v.set_mag_phase(r, i)?;
197 }
198
199 Ok(())
200 }
201 }
202
203 impl<V: Vector<T>, S: ToSlice<T>, T: RealNumber> ComplexOps<T>
204 for $matrix<V, S, T>
205 where V: ComplexOps<T> {
206 fn multiply_complex_exponential(&mut self, a: T, b: T) {
207 for v in self.rows_mut() {
208 v.multiply_complex_exponential(a, b);
209 }
210 }
211
212 fn conj(&mut self) {
213 for v in self.rows_mut() {
214 v.conj();
215 }
216 }
217 }
218 )*
219 }
220}
221
222add_mat_impl!(MatrixMxN; Matrix2xN; Matrix3xN; Matrix4xN);