1use super::*;
2use crate::TransformContent;
3use std::marker;
4
5macro_rules! try_transform {
6 ($op: expr, $matrix: ident) => {{
7 match $op {
8 Ok(rows) => Ok($matrix {
9 rows: rows,
10 storage_type: marker::PhantomData,
11 number_type: marker::PhantomData,
12 }),
13 Err((r, rows)) => Err((
14 r,
15 $matrix {
16 rows: rows,
17 storage_type: marker::PhantomData,
18 number_type: marker::PhantomData,
19 },
20 )),
21 }
22 }};
23}
24
25macro_rules! add_mat_impl {
26 ($($matrix:ident);*) => {
27 $(
28 impl <V: Vector<T> + ToComplexResult, S: ToSlice<T>, T: RealNumber>
29 ToComplexResult for $matrix<V, S, T>
30 where <V as ToComplexResult>::ComplexResult: Vector<T> {
31 type ComplexResult = $matrix<V::ComplexResult, S, T>;
32 }
33
34 impl<V: Vector<T>, S: ToSlice<T>, T: RealNumber>
35 RealToComplexTransformsOps<T> for $matrix<V, S, T>
36 where <V as ToComplexResult>::ComplexResult: Vector<T>,
37 V: RealToComplexTransformsOps<T> {
38 fn to_complex(self) -> TransRes<Self::ComplexResult> {
39 let rows = self.rows.transform_res(|v|v.to_complex());
40 try_transform!(rows, $matrix)
41 }
42 }
43
44 impl<V: Vector<T>, S: ToSliceMut<T>, T: RealNumber>
45 RealToComplexTransformsOpsBuffered<S, T> for $matrix<V, S, T>
46 where <V as ToComplexResult>::ComplexResult: Vector<T>,
47 V: RealToComplexTransformsOpsBuffered<S, T> {
48 fn to_complex_b<B>(self, buffer: &mut B) -> Self::ComplexResult
49 where B: for<'b> Buffer<'b, S, T> {
50 let rows = self.rows.transform(|v|v.to_complex_b(buffer));
51 $matrix {
52 rows: rows,
53 storage_type: marker::PhantomData,
54 number_type: marker::PhantomData
55 }
56 }
57 }
58
59 impl<V: Vector<T>, S: ToSlice<T>, T: RealNumber> RealOps
60 for $matrix<V, S, T>
61 where V: RealOps {
62 fn abs(&mut self) {
63 for v in self.rows_mut() {
64 v.abs();
65 }
66 }
67 }
68
69 impl<V: Vector<T>, S: ToSlice<T>, T: RealNumber> ModuloOps<T>
70 for $matrix<V, S, T>
71 where V: ModuloOps<T> {
72 fn wrap(&mut self, divisor: T) {
73 for v in self.rows_mut() {
74 v.wrap(divisor);
75 }
76 }
77
78 fn unwrap(&mut self, divisor: T) {
79 for v in self.rows_mut() {
80 v.unwrap(divisor);
81 }
82 }
83 }
84
85 impl<S: ToSlice<T>, V: Vector<T> + ApproximatedOps<T>, T: RealNumber>
86 ApproximatedOps<T> for $matrix<V, S, T> {
87 fn ln_approx(&mut self) {
88 for v in self.rows_mut() {
89 v.ln_approx()
90 }
91 }
92
93 fn exp_approx(&mut self) {
94 for v in self.rows_mut() {
95 v.exp_approx()
96 }
97 }
98
99 fn sin_approx(&mut self) {
100 for v in self.rows_mut() {
101 v.sin_approx()
102 }
103 }
104
105 fn cos_approx(&mut self) {
106 for v in self.rows_mut() {
107 v.cos_approx()
108 }
109 }
110
111 fn log_approx(&mut self, base: T) {
112 for v in self.rows_mut() {
113 v.log_approx(base)
114 }
115 }
116
117 fn expf_approx(&mut self, base: T) {
118 for v in self.rows_mut() {
119 v.expf_approx(base)
120 }
121 }
122
123 fn powf_approx(&mut self, exponent: T) {
124 for v in self.rows_mut() {
125 v.powf_approx(exponent)
126 }
127 }
128 }
129 )*
130 }
131}
132
133add_mat_impl!(MatrixMxN; Matrix2xN; Matrix3xN; Matrix4xN);