Chris@49
|
1 // Copyright (C) 2008-2012 NICTA (www.nicta.com.au)
|
Chris@49
|
2 // Copyright (C) 2008-2012 Conrad Sanderson
|
Chris@49
|
3 //
|
Chris@49
|
4 // This Source Code Form is subject to the terms of the Mozilla Public
|
Chris@49
|
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
|
Chris@49
|
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
Chris@49
|
7
|
Chris@49
|
8
|
Chris@49
|
9 //! \addtogroup op_misc
|
Chris@49
|
10 //! @{
|
Chris@49
|
11
|
Chris@49
|
12
|
Chris@49
|
13
|
Chris@49
|
14 template<typename T1>
|
Chris@49
|
15 inline
|
Chris@49
|
16 void
|
Chris@49
|
17 op_real::apply( Mat<typename T1::pod_type>& out, const mtOp<typename T1::pod_type, T1, op_real>& X )
|
Chris@49
|
18 {
|
Chris@49
|
19 arma_extra_debug_sigprint();
|
Chris@49
|
20
|
Chris@49
|
21 typedef typename T1::pod_type T;
|
Chris@49
|
22
|
Chris@49
|
23 const Proxy<T1> P(X.m);
|
Chris@49
|
24
|
Chris@49
|
25 const uword n_rows = P.get_n_rows();
|
Chris@49
|
26 const uword n_cols = P.get_n_cols();
|
Chris@49
|
27
|
Chris@49
|
28 out.set_size(n_rows, n_cols);
|
Chris@49
|
29
|
Chris@49
|
30 T* out_mem = out.memptr();
|
Chris@49
|
31
|
Chris@49
|
32 if(Proxy<T1>::prefer_at_accessor == false)
|
Chris@49
|
33 {
|
Chris@49
|
34 typedef typename Proxy<T1>::ea_type ea_type;
|
Chris@49
|
35
|
Chris@49
|
36 const uword n_elem = P.get_n_elem();
|
Chris@49
|
37 ea_type A = P.get_ea();
|
Chris@49
|
38
|
Chris@49
|
39 for(uword i=0; i < n_elem; ++i)
|
Chris@49
|
40 {
|
Chris@49
|
41 out_mem[i] = std::real( A[i] );
|
Chris@49
|
42 }
|
Chris@49
|
43 }
|
Chris@49
|
44 else
|
Chris@49
|
45 {
|
Chris@49
|
46 for(uword col=0; col < n_cols; ++col)
|
Chris@49
|
47 for(uword row=0; row < n_rows; ++row)
|
Chris@49
|
48 {
|
Chris@49
|
49 *out_mem = std::real( P.at(row,col) );
|
Chris@49
|
50 out_mem++;
|
Chris@49
|
51 }
|
Chris@49
|
52 }
|
Chris@49
|
53 }
|
Chris@49
|
54
|
Chris@49
|
55
|
Chris@49
|
56
|
Chris@49
|
57 template<typename T1>
|
Chris@49
|
58 inline
|
Chris@49
|
59 void
|
Chris@49
|
60 op_real::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T1::pod_type, T1, op_real>& X )
|
Chris@49
|
61 {
|
Chris@49
|
62 arma_extra_debug_sigprint();
|
Chris@49
|
63
|
Chris@49
|
64 typedef typename T1::pod_type T;
|
Chris@49
|
65
|
Chris@49
|
66 const ProxyCube<T1> P(X.m);
|
Chris@49
|
67
|
Chris@49
|
68 const uword n_rows = P.get_n_rows();
|
Chris@49
|
69 const uword n_cols = P.get_n_cols();
|
Chris@49
|
70 const uword n_slices = P.get_n_slices();
|
Chris@49
|
71
|
Chris@49
|
72 out.set_size(n_rows, n_cols, n_slices);
|
Chris@49
|
73
|
Chris@49
|
74 T* out_mem = out.memptr();
|
Chris@49
|
75
|
Chris@49
|
76 if(ProxyCube<T1>::prefer_at_accessor == false)
|
Chris@49
|
77 {
|
Chris@49
|
78 typedef typename ProxyCube<T1>::ea_type ea_type;
|
Chris@49
|
79
|
Chris@49
|
80 const uword n_elem = P.get_n_elem();
|
Chris@49
|
81 ea_type A = P.get_ea();
|
Chris@49
|
82
|
Chris@49
|
83 for(uword i=0; i < n_elem; ++i)
|
Chris@49
|
84 {
|
Chris@49
|
85 out_mem[i] = std::real( A[i] );
|
Chris@49
|
86 }
|
Chris@49
|
87 }
|
Chris@49
|
88 else
|
Chris@49
|
89 {
|
Chris@49
|
90 for(uword slice=0; slice < n_slices; ++slice)
|
Chris@49
|
91 for(uword col=0; col < n_cols; ++col )
|
Chris@49
|
92 for(uword row=0; row < n_rows; ++row )
|
Chris@49
|
93 {
|
Chris@49
|
94 *out_mem = std::real( P.at(row,col,slice) );
|
Chris@49
|
95 out_mem++;
|
Chris@49
|
96 }
|
Chris@49
|
97 }
|
Chris@49
|
98 }
|
Chris@49
|
99
|
Chris@49
|
100
|
Chris@49
|
101
|
Chris@49
|
102 template<typename T1>
|
Chris@49
|
103 inline
|
Chris@49
|
104 void
|
Chris@49
|
105 op_imag::apply( Mat<typename T1::pod_type>& out, const mtOp<typename T1::pod_type, T1, op_imag>& X )
|
Chris@49
|
106 {
|
Chris@49
|
107 arma_extra_debug_sigprint();
|
Chris@49
|
108
|
Chris@49
|
109 typedef typename T1::pod_type T;
|
Chris@49
|
110
|
Chris@49
|
111 const Proxy<T1> P(X.m);
|
Chris@49
|
112
|
Chris@49
|
113 const uword n_rows = P.get_n_rows();
|
Chris@49
|
114 const uword n_cols = P.get_n_cols();
|
Chris@49
|
115
|
Chris@49
|
116 out.set_size(n_rows, n_cols);
|
Chris@49
|
117
|
Chris@49
|
118 T* out_mem = out.memptr();
|
Chris@49
|
119
|
Chris@49
|
120 if(Proxy<T1>::prefer_at_accessor == false)
|
Chris@49
|
121 {
|
Chris@49
|
122 typedef typename Proxy<T1>::ea_type ea_type;
|
Chris@49
|
123
|
Chris@49
|
124 const uword n_elem = P.get_n_elem();
|
Chris@49
|
125 ea_type A = P.get_ea();
|
Chris@49
|
126
|
Chris@49
|
127 for(uword i=0; i < n_elem; ++i)
|
Chris@49
|
128 {
|
Chris@49
|
129 out_mem[i] = std::imag( A[i] );
|
Chris@49
|
130 }
|
Chris@49
|
131 }
|
Chris@49
|
132 else
|
Chris@49
|
133 {
|
Chris@49
|
134 for(uword col=0; col < n_cols; ++col)
|
Chris@49
|
135 for(uword row=0; row < n_rows; ++row)
|
Chris@49
|
136 {
|
Chris@49
|
137 *out_mem = std::imag( P.at(row,col) );
|
Chris@49
|
138 out_mem++;
|
Chris@49
|
139 }
|
Chris@49
|
140 }
|
Chris@49
|
141 }
|
Chris@49
|
142
|
Chris@49
|
143
|
Chris@49
|
144
|
Chris@49
|
145 template<typename T1>
|
Chris@49
|
146 inline
|
Chris@49
|
147 void
|
Chris@49
|
148 op_imag::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T1::pod_type, T1, op_imag>& X )
|
Chris@49
|
149 {
|
Chris@49
|
150 arma_extra_debug_sigprint();
|
Chris@49
|
151
|
Chris@49
|
152 typedef typename T1::pod_type T;
|
Chris@49
|
153
|
Chris@49
|
154 const ProxyCube<T1> P(X.m);
|
Chris@49
|
155
|
Chris@49
|
156 const uword n_rows = P.get_n_rows();
|
Chris@49
|
157 const uword n_cols = P.get_n_cols();
|
Chris@49
|
158 const uword n_slices = P.get_n_slices();
|
Chris@49
|
159
|
Chris@49
|
160 out.set_size(n_rows, n_cols, n_slices);
|
Chris@49
|
161
|
Chris@49
|
162 T* out_mem = out.memptr();
|
Chris@49
|
163
|
Chris@49
|
164 if(ProxyCube<T1>::prefer_at_accessor == false)
|
Chris@49
|
165 {
|
Chris@49
|
166 typedef typename ProxyCube<T1>::ea_type ea_type;
|
Chris@49
|
167
|
Chris@49
|
168 const uword n_elem = P.get_n_elem();
|
Chris@49
|
169 ea_type A = P.get_ea();
|
Chris@49
|
170
|
Chris@49
|
171 for(uword i=0; i < n_elem; ++i)
|
Chris@49
|
172 {
|
Chris@49
|
173 out_mem[i] = std::imag( A[i] );
|
Chris@49
|
174 }
|
Chris@49
|
175 }
|
Chris@49
|
176 else
|
Chris@49
|
177 {
|
Chris@49
|
178 for(uword slice=0; slice < n_slices; ++slice)
|
Chris@49
|
179 for(uword col=0; col < n_cols; ++col )
|
Chris@49
|
180 for(uword row=0; row < n_rows; ++row )
|
Chris@49
|
181 {
|
Chris@49
|
182 *out_mem = std::imag( P.at(row,col,slice) );
|
Chris@49
|
183 out_mem++;
|
Chris@49
|
184 }
|
Chris@49
|
185 }
|
Chris@49
|
186 }
|
Chris@49
|
187
|
Chris@49
|
188
|
Chris@49
|
189
|
Chris@49
|
190 template<typename T1>
|
Chris@49
|
191 inline
|
Chris@49
|
192 void
|
Chris@49
|
193 op_abs::apply( Mat<typename T1::pod_type>& out, const mtOp<typename T1::pod_type, T1, op_abs>& X )
|
Chris@49
|
194 {
|
Chris@49
|
195 arma_extra_debug_sigprint();
|
Chris@49
|
196
|
Chris@49
|
197 typedef typename T1::pod_type T;
|
Chris@49
|
198
|
Chris@49
|
199 const Proxy<T1> P(X.m);
|
Chris@49
|
200
|
Chris@49
|
201 const uword n_rows = P.get_n_rows();
|
Chris@49
|
202 const uword n_cols = P.get_n_cols();
|
Chris@49
|
203
|
Chris@49
|
204 out.set_size(n_rows, n_cols);
|
Chris@49
|
205
|
Chris@49
|
206 T* out_mem = out.memptr();
|
Chris@49
|
207
|
Chris@49
|
208 if(Proxy<T1>::prefer_at_accessor == false)
|
Chris@49
|
209 {
|
Chris@49
|
210 typedef typename Proxy<T1>::ea_type ea_type;
|
Chris@49
|
211
|
Chris@49
|
212 const uword n_elem = P.get_n_elem();
|
Chris@49
|
213 ea_type A = P.get_ea();
|
Chris@49
|
214
|
Chris@49
|
215 for(uword i=0; i < n_elem; ++i)
|
Chris@49
|
216 {
|
Chris@49
|
217 out_mem[i] = std::abs( A[i] );
|
Chris@49
|
218 }
|
Chris@49
|
219 }
|
Chris@49
|
220 else
|
Chris@49
|
221 {
|
Chris@49
|
222 for(uword col=0; col < n_cols; ++col)
|
Chris@49
|
223 for(uword row=0; row < n_rows; ++row)
|
Chris@49
|
224 {
|
Chris@49
|
225 *out_mem = std::abs( P.at(row,col) );
|
Chris@49
|
226 out_mem++;
|
Chris@49
|
227 }
|
Chris@49
|
228 }
|
Chris@49
|
229 }
|
Chris@49
|
230
|
Chris@49
|
231
|
Chris@49
|
232
|
Chris@49
|
233 template<typename T1>
|
Chris@49
|
234 inline
|
Chris@49
|
235 void
|
Chris@49
|
236 op_abs::apply( Cube<typename T1::pod_type>& out, const mtOpCube<typename T1::pod_type, T1, op_abs>& X )
|
Chris@49
|
237 {
|
Chris@49
|
238 arma_extra_debug_sigprint();
|
Chris@49
|
239
|
Chris@49
|
240 typedef typename T1::pod_type T;
|
Chris@49
|
241
|
Chris@49
|
242 const ProxyCube<T1> P(X.m);
|
Chris@49
|
243
|
Chris@49
|
244 const uword n_rows = P.get_n_rows();
|
Chris@49
|
245 const uword n_cols = P.get_n_cols();
|
Chris@49
|
246 const uword n_slices = P.get_n_slices();
|
Chris@49
|
247
|
Chris@49
|
248 out.set_size(n_rows, n_cols, n_slices);
|
Chris@49
|
249
|
Chris@49
|
250 T* out_mem = out.memptr();
|
Chris@49
|
251
|
Chris@49
|
252 if(ProxyCube<T1>::prefer_at_accessor == false)
|
Chris@49
|
253 {
|
Chris@49
|
254 typedef typename ProxyCube<T1>::ea_type ea_type;
|
Chris@49
|
255
|
Chris@49
|
256 const uword n_elem = P.get_n_elem();
|
Chris@49
|
257 ea_type A = P.get_ea();
|
Chris@49
|
258
|
Chris@49
|
259 for(uword i=0; i < n_elem; ++i)
|
Chris@49
|
260 {
|
Chris@49
|
261 out_mem[i] = std::abs( A[i] );
|
Chris@49
|
262 }
|
Chris@49
|
263 }
|
Chris@49
|
264 else
|
Chris@49
|
265 {
|
Chris@49
|
266 for(uword slice=0; slice < n_slices; ++slice)
|
Chris@49
|
267 for(uword col=0; col < n_cols; ++col )
|
Chris@49
|
268 for(uword row=0; row < n_rows; ++row )
|
Chris@49
|
269 {
|
Chris@49
|
270 *out_mem = std::abs( P.at(row,col,slice) );
|
Chris@49
|
271 out_mem++;
|
Chris@49
|
272 }
|
Chris@49
|
273 }
|
Chris@49
|
274 }
|
Chris@49
|
275
|
Chris@49
|
276
|
Chris@49
|
277
|
Chris@49
|
278 template<typename T1>
|
Chris@49
|
279 inline
|
Chris@49
|
280 void
|
Chris@49
|
281 op_sympd::apply( Mat<typename T1::elem_type>& out, const Op<T1, op_sympd>& X )
|
Chris@49
|
282 {
|
Chris@49
|
283 arma_extra_debug_sigprint();
|
Chris@49
|
284
|
Chris@49
|
285 out = X.m;
|
Chris@49
|
286 }
|
Chris@49
|
287
|
Chris@49
|
288
|
Chris@49
|
289
|
Chris@49
|
290 //! @}
|