Chris@49
|
1 // Copyright (C) 2010-2013 NICTA (www.nicta.com.au)
|
Chris@49
|
2 // Copyright (C) 2010-2013 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 eglue_core
|
Chris@49
|
10 //! @{
|
Chris@49
|
11
|
Chris@49
|
12
|
Chris@49
|
13
|
Chris@49
|
14 #undef arma_applier_1u
|
Chris@49
|
15 #undef arma_applier_1a
|
Chris@49
|
16 #undef arma_applier_2
|
Chris@49
|
17 #undef arma_applier_3
|
Chris@49
|
18 #undef operatorA
|
Chris@49
|
19 #undef operatorB
|
Chris@49
|
20
|
Chris@49
|
21 #define arma_applier_1u(operatorA, operatorB) \
|
Chris@49
|
22 {\
|
Chris@49
|
23 uword i,j;\
|
Chris@49
|
24 \
|
Chris@49
|
25 for(i=0, j=1; j<n_elem; i+=2, j+=2)\
|
Chris@49
|
26 {\
|
Chris@49
|
27 eT tmp_i = P1[i];\
|
Chris@49
|
28 eT tmp_j = P1[j];\
|
Chris@49
|
29 \
|
Chris@49
|
30 tmp_i operatorB##= P2[i];\
|
Chris@49
|
31 tmp_j operatorB##= P2[j];\
|
Chris@49
|
32 \
|
Chris@49
|
33 out_mem[i] operatorA tmp_i;\
|
Chris@49
|
34 out_mem[j] operatorA tmp_j;\
|
Chris@49
|
35 }\
|
Chris@49
|
36 \
|
Chris@49
|
37 if(i < n_elem)\
|
Chris@49
|
38 {\
|
Chris@49
|
39 out_mem[i] operatorA P1[i] operatorB P2[i];\
|
Chris@49
|
40 }\
|
Chris@49
|
41 }
|
Chris@49
|
42
|
Chris@49
|
43
|
Chris@49
|
44
|
Chris@49
|
45 #define arma_applier_1a(operatorA, operatorB) \
|
Chris@49
|
46 {\
|
Chris@49
|
47 uword i,j;\
|
Chris@49
|
48 \
|
Chris@49
|
49 for(i=0, j=1; j<n_elem; i+=2, j+=2)\
|
Chris@49
|
50 {\
|
Chris@49
|
51 eT tmp_i = P1.at_alt(i);\
|
Chris@49
|
52 eT tmp_j = P1.at_alt(j);\
|
Chris@49
|
53 \
|
Chris@49
|
54 tmp_i operatorB##= P2.at_alt(i);\
|
Chris@49
|
55 tmp_j operatorB##= P2.at_alt(j);\
|
Chris@49
|
56 \
|
Chris@49
|
57 out_mem[i] operatorA tmp_i;\
|
Chris@49
|
58 out_mem[j] operatorA tmp_j;\
|
Chris@49
|
59 }\
|
Chris@49
|
60 \
|
Chris@49
|
61 if(i < n_elem)\
|
Chris@49
|
62 {\
|
Chris@49
|
63 out_mem[i] operatorA P1.at_alt(i) operatorB P2.at_alt(i);\
|
Chris@49
|
64 }\
|
Chris@49
|
65 }
|
Chris@49
|
66
|
Chris@49
|
67
|
Chris@49
|
68
|
Chris@49
|
69 #define arma_applier_2(operatorA, operatorB) \
|
Chris@49
|
70 {\
|
Chris@49
|
71 if(n_rows != 1)\
|
Chris@49
|
72 {\
|
Chris@49
|
73 for(uword col=0; col<n_cols; ++col)\
|
Chris@49
|
74 {\
|
Chris@49
|
75 uword i,j;\
|
Chris@49
|
76 \
|
Chris@49
|
77 for(i=0, j=1; j<n_rows; i+=2, j+=2)\
|
Chris@49
|
78 {\
|
Chris@49
|
79 eT tmp_i = P1.at(i,col);\
|
Chris@49
|
80 eT tmp_j = P1.at(j,col);\
|
Chris@49
|
81 \
|
Chris@49
|
82 tmp_i operatorB##= P2.at(i,col);\
|
Chris@49
|
83 tmp_j operatorB##= P2.at(j,col);\
|
Chris@49
|
84 \
|
Chris@49
|
85 *out_mem operatorA tmp_i; out_mem++; \
|
Chris@49
|
86 *out_mem operatorA tmp_j; out_mem++; \
|
Chris@49
|
87 }\
|
Chris@49
|
88 \
|
Chris@49
|
89 if(i < n_rows)\
|
Chris@49
|
90 {\
|
Chris@49
|
91 *out_mem operatorA P1.at(i,col) operatorB P2.at(i,col); out_mem++; \
|
Chris@49
|
92 }\
|
Chris@49
|
93 }\
|
Chris@49
|
94 }\
|
Chris@49
|
95 else\
|
Chris@49
|
96 {\
|
Chris@49
|
97 uword i,j;\
|
Chris@49
|
98 for(i=0, j=1; j < n_cols; i+=2, j+=2)\
|
Chris@49
|
99 {\
|
Chris@49
|
100 eT tmp_i = P1.at(0,i);\
|
Chris@49
|
101 eT tmp_j = P1.at(0,j);\
|
Chris@49
|
102 \
|
Chris@49
|
103 tmp_i operatorB##= P2.at(0,i);\
|
Chris@49
|
104 tmp_j operatorB##= P2.at(0,j);\
|
Chris@49
|
105 \
|
Chris@49
|
106 out_mem[i] operatorA tmp_i;\
|
Chris@49
|
107 out_mem[j] operatorA tmp_j;\
|
Chris@49
|
108 }\
|
Chris@49
|
109 \
|
Chris@49
|
110 if(i < n_cols)\
|
Chris@49
|
111 {\
|
Chris@49
|
112 out_mem[i] operatorA P1.at(0,i) operatorB P2.at(0,i);\
|
Chris@49
|
113 }\
|
Chris@49
|
114 }\
|
Chris@49
|
115 }
|
Chris@49
|
116
|
Chris@49
|
117
|
Chris@49
|
118
|
Chris@49
|
119 #define arma_applier_3(operatorA, operatorB) \
|
Chris@49
|
120 {\
|
Chris@49
|
121 for(uword slice=0; slice<n_slices; ++slice)\
|
Chris@49
|
122 {\
|
Chris@49
|
123 for(uword col=0; col<n_cols; ++col)\
|
Chris@49
|
124 {\
|
Chris@49
|
125 uword i,j;\
|
Chris@49
|
126 \
|
Chris@49
|
127 for(i=0, j=1; j<n_rows; i+=2, j+=2)\
|
Chris@49
|
128 {\
|
Chris@49
|
129 eT tmp_i = P1.at(i,col,slice);\
|
Chris@49
|
130 eT tmp_j = P1.at(j,col,slice);\
|
Chris@49
|
131 \
|
Chris@49
|
132 tmp_i operatorB##= P2.at(i,col,slice);\
|
Chris@49
|
133 tmp_j operatorB##= P2.at(j,col,slice);\
|
Chris@49
|
134 \
|
Chris@49
|
135 *out_mem operatorA tmp_i; out_mem++; \
|
Chris@49
|
136 *out_mem operatorA tmp_j; out_mem++; \
|
Chris@49
|
137 }\
|
Chris@49
|
138 \
|
Chris@49
|
139 if(i < n_rows)\
|
Chris@49
|
140 {\
|
Chris@49
|
141 *out_mem operatorA P1.at(i,col,slice) operatorB P2.at(i,col,slice); out_mem++; \
|
Chris@49
|
142 }\
|
Chris@49
|
143 }\
|
Chris@49
|
144 }\
|
Chris@49
|
145 }
|
Chris@49
|
146
|
Chris@49
|
147
|
Chris@49
|
148
|
Chris@49
|
149 //
|
Chris@49
|
150 // matrices
|
Chris@49
|
151
|
Chris@49
|
152
|
Chris@49
|
153
|
Chris@49
|
154 template<typename eglue_type>
|
Chris@49
|
155 template<typename T1, typename T2>
|
Chris@49
|
156 arma_hot
|
Chris@49
|
157 inline
|
Chris@49
|
158 void
|
Chris@49
|
159 eglue_core<eglue_type>::apply(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x)
|
Chris@49
|
160 {
|
Chris@49
|
161 arma_extra_debug_sigprint();
|
Chris@49
|
162
|
Chris@49
|
163 typedef typename T1::elem_type eT;
|
Chris@49
|
164
|
Chris@49
|
165 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
|
Chris@49
|
166
|
Chris@49
|
167 // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing;
|
Chris@49
|
168 // size setting and alias checking is done by either the Mat contructor or operator=()
|
Chris@49
|
169
|
Chris@49
|
170
|
Chris@49
|
171 eT* out_mem = out.memptr();
|
Chris@49
|
172
|
Chris@49
|
173 if(prefer_at_accessor == false)
|
Chris@49
|
174 {
|
Chris@49
|
175 const uword n_elem = (Proxy<T1>::is_fixed || Proxy<T2>::is_fixed) ? x.get_n_elem() : out.n_elem;
|
Chris@49
|
176
|
Chris@49
|
177 //if( memory::is_aligned(out_mem) )
|
Chris@49
|
178 if( memory::is_aligned(out_mem) && ((Proxy<T1>::is_fixed && Proxy<T2>::is_fixed) ? (x.get_n_elem() >= 32) : true) )
|
Chris@49
|
179 {
|
Chris@49
|
180 memory::mark_as_aligned(out_mem);
|
Chris@49
|
181
|
Chris@49
|
182 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
183 {
|
Chris@49
|
184 typename Proxy<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
185 typename Proxy<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
186
|
Chris@49
|
187 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(=, +); }
|
Chris@49
|
188 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(=, -); }
|
Chris@49
|
189 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(=, /); }
|
Chris@49
|
190 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(=, *); }
|
Chris@49
|
191 }
|
Chris@49
|
192 else
|
Chris@49
|
193 {
|
Chris@49
|
194 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
195 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
196
|
Chris@49
|
197 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(=, +); }
|
Chris@49
|
198 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(=, -); }
|
Chris@49
|
199 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(=, /); }
|
Chris@49
|
200 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(=, *); }
|
Chris@49
|
201 }
|
Chris@49
|
202 }
|
Chris@49
|
203 else
|
Chris@49
|
204 {
|
Chris@49
|
205 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
206 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
207
|
Chris@49
|
208 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(=, +); }
|
Chris@49
|
209 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(=, -); }
|
Chris@49
|
210 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(=, /); }
|
Chris@49
|
211 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(=, *); }
|
Chris@49
|
212 }
|
Chris@49
|
213 }
|
Chris@49
|
214 else
|
Chris@49
|
215 {
|
Chris@49
|
216 const uword n_rows = x.get_n_rows();
|
Chris@49
|
217 const uword n_cols = x.get_n_cols();
|
Chris@49
|
218
|
Chris@49
|
219 const Proxy<T1>& P1 = x.P1;
|
Chris@49
|
220 const Proxy<T2>& P2 = x.P2;
|
Chris@49
|
221
|
Chris@49
|
222 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(=, +); }
|
Chris@49
|
223 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(=, -); }
|
Chris@49
|
224 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(=, /); }
|
Chris@49
|
225 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(=, *); }
|
Chris@49
|
226 }
|
Chris@49
|
227 }
|
Chris@49
|
228
|
Chris@49
|
229
|
Chris@49
|
230
|
Chris@49
|
231 template<typename eglue_type>
|
Chris@49
|
232 template<typename T1, typename T2>
|
Chris@49
|
233 arma_hot
|
Chris@49
|
234 inline
|
Chris@49
|
235 void
|
Chris@49
|
236 eglue_core<eglue_type>::apply_inplace_plus(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x)
|
Chris@49
|
237 {
|
Chris@49
|
238 arma_extra_debug_sigprint();
|
Chris@49
|
239
|
Chris@49
|
240 const uword n_rows = x.get_n_rows();
|
Chris@49
|
241 const uword n_cols = x.get_n_cols();
|
Chris@49
|
242
|
Chris@49
|
243 arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition");
|
Chris@49
|
244
|
Chris@49
|
245 typedef typename T1::elem_type eT;
|
Chris@49
|
246
|
Chris@49
|
247 eT* out_mem = out.memptr();
|
Chris@49
|
248
|
Chris@49
|
249 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
|
Chris@49
|
250
|
Chris@49
|
251 if(prefer_at_accessor == false)
|
Chris@49
|
252 {
|
Chris@49
|
253 const uword n_elem = (Proxy<T1>::is_fixed || Proxy<T2>::is_fixed) ? x.get_n_elem() : out.n_elem;
|
Chris@49
|
254
|
Chris@49
|
255 if(memory::is_aligned(out_mem))
|
Chris@49
|
256 {
|
Chris@49
|
257 memory::mark_as_aligned(out_mem);
|
Chris@49
|
258
|
Chris@49
|
259 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
260 {
|
Chris@49
|
261 typename Proxy<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
262 typename Proxy<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
263
|
Chris@49
|
264 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(+=, +); }
|
Chris@49
|
265 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(+=, -); }
|
Chris@49
|
266 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(+=, /); }
|
Chris@49
|
267 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(+=, *); }
|
Chris@49
|
268 }
|
Chris@49
|
269 else
|
Chris@49
|
270 {
|
Chris@49
|
271 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
272 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
273
|
Chris@49
|
274 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(+=, +); }
|
Chris@49
|
275 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(+=, -); }
|
Chris@49
|
276 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(+=, /); }
|
Chris@49
|
277 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(+=, *); }
|
Chris@49
|
278 }
|
Chris@49
|
279 }
|
Chris@49
|
280 else
|
Chris@49
|
281 {
|
Chris@49
|
282 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
283 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
284
|
Chris@49
|
285 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(+=, +); }
|
Chris@49
|
286 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(+=, -); }
|
Chris@49
|
287 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(+=, /); }
|
Chris@49
|
288 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(+=, *); }
|
Chris@49
|
289 }
|
Chris@49
|
290 }
|
Chris@49
|
291 else
|
Chris@49
|
292 {
|
Chris@49
|
293 const Proxy<T1>& P1 = x.P1;
|
Chris@49
|
294 const Proxy<T2>& P2 = x.P2;
|
Chris@49
|
295
|
Chris@49
|
296 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(+=, +); }
|
Chris@49
|
297 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(+=, -); }
|
Chris@49
|
298 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(+=, /); }
|
Chris@49
|
299 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(+=, *); }
|
Chris@49
|
300 }
|
Chris@49
|
301 }
|
Chris@49
|
302
|
Chris@49
|
303
|
Chris@49
|
304
|
Chris@49
|
305 template<typename eglue_type>
|
Chris@49
|
306 template<typename T1, typename T2>
|
Chris@49
|
307 arma_hot
|
Chris@49
|
308 inline
|
Chris@49
|
309 void
|
Chris@49
|
310 eglue_core<eglue_type>::apply_inplace_minus(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x)
|
Chris@49
|
311 {
|
Chris@49
|
312 arma_extra_debug_sigprint();
|
Chris@49
|
313
|
Chris@49
|
314 const uword n_rows = x.get_n_rows();
|
Chris@49
|
315 const uword n_cols = x.get_n_cols();
|
Chris@49
|
316
|
Chris@49
|
317 arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction");
|
Chris@49
|
318
|
Chris@49
|
319 typedef typename T1::elem_type eT;
|
Chris@49
|
320
|
Chris@49
|
321 eT* out_mem = out.memptr();
|
Chris@49
|
322
|
Chris@49
|
323 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
|
Chris@49
|
324
|
Chris@49
|
325 if(prefer_at_accessor == false)
|
Chris@49
|
326 {
|
Chris@49
|
327 const uword n_elem = (Proxy<T1>::is_fixed || Proxy<T2>::is_fixed) ? x.get_n_elem() : out.n_elem;
|
Chris@49
|
328
|
Chris@49
|
329 if(memory::is_aligned(out_mem))
|
Chris@49
|
330 {
|
Chris@49
|
331 memory::mark_as_aligned(out_mem);
|
Chris@49
|
332
|
Chris@49
|
333 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
334 {
|
Chris@49
|
335 typename Proxy<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
336 typename Proxy<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
337
|
Chris@49
|
338 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(-=, +); }
|
Chris@49
|
339 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(-=, -); }
|
Chris@49
|
340 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(-=, /); }
|
Chris@49
|
341 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(-=, *); }
|
Chris@49
|
342 }
|
Chris@49
|
343 else
|
Chris@49
|
344 {
|
Chris@49
|
345 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
346 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
347
|
Chris@49
|
348 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(-=, +); }
|
Chris@49
|
349 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(-=, -); }
|
Chris@49
|
350 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(-=, /); }
|
Chris@49
|
351 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(-=, *); }
|
Chris@49
|
352 }
|
Chris@49
|
353 }
|
Chris@49
|
354 else
|
Chris@49
|
355 {
|
Chris@49
|
356 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
357 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
358
|
Chris@49
|
359 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(-=, +); }
|
Chris@49
|
360 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(-=, -); }
|
Chris@49
|
361 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(-=, /); }
|
Chris@49
|
362 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(-=, *); }
|
Chris@49
|
363 }
|
Chris@49
|
364 }
|
Chris@49
|
365 else
|
Chris@49
|
366 {
|
Chris@49
|
367 const Proxy<T1>& P1 = x.P1;
|
Chris@49
|
368 const Proxy<T2>& P2 = x.P2;
|
Chris@49
|
369
|
Chris@49
|
370 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(-=, +); }
|
Chris@49
|
371 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(-=, -); }
|
Chris@49
|
372 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(-=, /); }
|
Chris@49
|
373 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(-=, *); }
|
Chris@49
|
374 }
|
Chris@49
|
375 }
|
Chris@49
|
376
|
Chris@49
|
377
|
Chris@49
|
378
|
Chris@49
|
379 template<typename eglue_type>
|
Chris@49
|
380 template<typename T1, typename T2>
|
Chris@49
|
381 arma_hot
|
Chris@49
|
382 inline
|
Chris@49
|
383 void
|
Chris@49
|
384 eglue_core<eglue_type>::apply_inplace_schur(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x)
|
Chris@49
|
385 {
|
Chris@49
|
386 arma_extra_debug_sigprint();
|
Chris@49
|
387
|
Chris@49
|
388 const uword n_rows = x.get_n_rows();
|
Chris@49
|
389 const uword n_cols = x.get_n_cols();
|
Chris@49
|
390
|
Chris@49
|
391 arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication");
|
Chris@49
|
392
|
Chris@49
|
393 typedef typename T1::elem_type eT;
|
Chris@49
|
394
|
Chris@49
|
395 eT* out_mem = out.memptr();
|
Chris@49
|
396
|
Chris@49
|
397 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
|
Chris@49
|
398
|
Chris@49
|
399 if(prefer_at_accessor == false)
|
Chris@49
|
400 {
|
Chris@49
|
401 const uword n_elem = (Proxy<T1>::is_fixed || Proxy<T2>::is_fixed) ? x.get_n_elem() : out.n_elem;
|
Chris@49
|
402
|
Chris@49
|
403 if(memory::is_aligned(out_mem))
|
Chris@49
|
404 {
|
Chris@49
|
405 memory::mark_as_aligned(out_mem);
|
Chris@49
|
406
|
Chris@49
|
407 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
408 {
|
Chris@49
|
409 typename Proxy<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
410 typename Proxy<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
411
|
Chris@49
|
412 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(*=, +); }
|
Chris@49
|
413 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(*=, -); }
|
Chris@49
|
414 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(*=, /); }
|
Chris@49
|
415 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(*=, *); }
|
Chris@49
|
416 }
|
Chris@49
|
417 else
|
Chris@49
|
418 {
|
Chris@49
|
419 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
420 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
421
|
Chris@49
|
422 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(*=, +); }
|
Chris@49
|
423 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(*=, -); }
|
Chris@49
|
424 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(*=, /); }
|
Chris@49
|
425 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(*=, *); }
|
Chris@49
|
426 }
|
Chris@49
|
427 }
|
Chris@49
|
428 else
|
Chris@49
|
429 {
|
Chris@49
|
430 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
431 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
432
|
Chris@49
|
433 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(*=, +); }
|
Chris@49
|
434 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(*=, -); }
|
Chris@49
|
435 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(*=, /); }
|
Chris@49
|
436 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(*=, *); }
|
Chris@49
|
437 }
|
Chris@49
|
438 }
|
Chris@49
|
439 else
|
Chris@49
|
440 {
|
Chris@49
|
441 const Proxy<T1>& P1 = x.P1;
|
Chris@49
|
442 const Proxy<T2>& P2 = x.P2;
|
Chris@49
|
443
|
Chris@49
|
444 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(*=, +); }
|
Chris@49
|
445 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(*=, -); }
|
Chris@49
|
446 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(*=, /); }
|
Chris@49
|
447 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(*=, *); }
|
Chris@49
|
448 }
|
Chris@49
|
449 }
|
Chris@49
|
450
|
Chris@49
|
451
|
Chris@49
|
452
|
Chris@49
|
453 template<typename eglue_type>
|
Chris@49
|
454 template<typename T1, typename T2>
|
Chris@49
|
455 arma_hot
|
Chris@49
|
456 inline
|
Chris@49
|
457 void
|
Chris@49
|
458 eglue_core<eglue_type>::apply_inplace_div(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x)
|
Chris@49
|
459 {
|
Chris@49
|
460 arma_extra_debug_sigprint();
|
Chris@49
|
461
|
Chris@49
|
462 const uword n_rows = x.get_n_rows();
|
Chris@49
|
463 const uword n_cols = x.get_n_cols();
|
Chris@49
|
464
|
Chris@49
|
465 arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division");
|
Chris@49
|
466
|
Chris@49
|
467 typedef typename T1::elem_type eT;
|
Chris@49
|
468
|
Chris@49
|
469 eT* out_mem = out.memptr();
|
Chris@49
|
470
|
Chris@49
|
471 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor);
|
Chris@49
|
472
|
Chris@49
|
473 if(prefer_at_accessor == false)
|
Chris@49
|
474 {
|
Chris@49
|
475 const uword n_elem = (Proxy<T1>::is_fixed || Proxy<T2>::is_fixed) ? x.get_n_elem() : out.n_elem;
|
Chris@49
|
476
|
Chris@49
|
477 if(memory::is_aligned(out_mem))
|
Chris@49
|
478 {
|
Chris@49
|
479 memory::mark_as_aligned(out_mem);
|
Chris@49
|
480
|
Chris@49
|
481 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
482 {
|
Chris@49
|
483 typename Proxy<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
484 typename Proxy<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
485
|
Chris@49
|
486 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(/=, +); }
|
Chris@49
|
487 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(/=, -); }
|
Chris@49
|
488 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(/=, /); }
|
Chris@49
|
489 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(/=, *); }
|
Chris@49
|
490 }
|
Chris@49
|
491 else
|
Chris@49
|
492 {
|
Chris@49
|
493 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
494 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
495
|
Chris@49
|
496 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(/=, +); }
|
Chris@49
|
497 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(/=, -); }
|
Chris@49
|
498 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(/=, /); }
|
Chris@49
|
499 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(/=, *); }
|
Chris@49
|
500 }
|
Chris@49
|
501 }
|
Chris@49
|
502 else
|
Chris@49
|
503 {
|
Chris@49
|
504 typename Proxy<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
505 typename Proxy<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
506
|
Chris@49
|
507 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(/=, +); }
|
Chris@49
|
508 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(/=, -); }
|
Chris@49
|
509 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(/=, /); }
|
Chris@49
|
510 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(/=, *); }
|
Chris@49
|
511 }
|
Chris@49
|
512 }
|
Chris@49
|
513 else
|
Chris@49
|
514 {
|
Chris@49
|
515 const Proxy<T1>& P1 = x.P1;
|
Chris@49
|
516 const Proxy<T2>& P2 = x.P2;
|
Chris@49
|
517
|
Chris@49
|
518 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(/=, +); }
|
Chris@49
|
519 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(/=, -); }
|
Chris@49
|
520 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(/=, /); }
|
Chris@49
|
521 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(/=, *); }
|
Chris@49
|
522 }
|
Chris@49
|
523 }
|
Chris@49
|
524
|
Chris@49
|
525
|
Chris@49
|
526
|
Chris@49
|
527 //
|
Chris@49
|
528 // cubes
|
Chris@49
|
529
|
Chris@49
|
530
|
Chris@49
|
531
|
Chris@49
|
532 template<typename eglue_type>
|
Chris@49
|
533 template<typename T1, typename T2>
|
Chris@49
|
534 arma_hot
|
Chris@49
|
535 inline
|
Chris@49
|
536 void
|
Chris@49
|
537 eglue_core<eglue_type>::apply(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x)
|
Chris@49
|
538 {
|
Chris@49
|
539 arma_extra_debug_sigprint();
|
Chris@49
|
540
|
Chris@49
|
541 typedef typename T1::elem_type eT;
|
Chris@49
|
542
|
Chris@49
|
543 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
|
Chris@49
|
544
|
Chris@49
|
545 // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing;
|
Chris@49
|
546 // size setting and alias checking is done by either the Cube contructor or operator=()
|
Chris@49
|
547
|
Chris@49
|
548
|
Chris@49
|
549 eT* out_mem = out.memptr();
|
Chris@49
|
550
|
Chris@49
|
551 if(prefer_at_accessor == false)
|
Chris@49
|
552 {
|
Chris@49
|
553 const uword n_elem = out.n_elem;
|
Chris@49
|
554
|
Chris@49
|
555 if(memory::is_aligned(out_mem))
|
Chris@49
|
556 {
|
Chris@49
|
557 memory::mark_as_aligned(out_mem);
|
Chris@49
|
558
|
Chris@49
|
559 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
560 {
|
Chris@49
|
561 typename ProxyCube<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
562 typename ProxyCube<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
563
|
Chris@49
|
564 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(=, +); }
|
Chris@49
|
565 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(=, -); }
|
Chris@49
|
566 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(=, /); }
|
Chris@49
|
567 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(=, *); }
|
Chris@49
|
568 }
|
Chris@49
|
569 else
|
Chris@49
|
570 {
|
Chris@49
|
571 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
572 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
573
|
Chris@49
|
574 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(=, +); }
|
Chris@49
|
575 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(=, -); }
|
Chris@49
|
576 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(=, /); }
|
Chris@49
|
577 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(=, *); }
|
Chris@49
|
578 }
|
Chris@49
|
579 }
|
Chris@49
|
580 else
|
Chris@49
|
581 {
|
Chris@49
|
582 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
583 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
584
|
Chris@49
|
585 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(=, +); }
|
Chris@49
|
586 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(=, -); }
|
Chris@49
|
587 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(=, /); }
|
Chris@49
|
588 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(=, *); }
|
Chris@49
|
589 }
|
Chris@49
|
590 }
|
Chris@49
|
591 else
|
Chris@49
|
592 {
|
Chris@49
|
593 const uword n_rows = x.get_n_rows();
|
Chris@49
|
594 const uword n_cols = x.get_n_cols();
|
Chris@49
|
595 const uword n_slices = x.get_n_slices();
|
Chris@49
|
596
|
Chris@49
|
597 const ProxyCube<T1>& P1 = x.P1;
|
Chris@49
|
598 const ProxyCube<T2>& P2 = x.P2;
|
Chris@49
|
599
|
Chris@49
|
600 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(=, +); }
|
Chris@49
|
601 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(=, -); }
|
Chris@49
|
602 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(=, /); }
|
Chris@49
|
603 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(=, *); }
|
Chris@49
|
604 }
|
Chris@49
|
605 }
|
Chris@49
|
606
|
Chris@49
|
607
|
Chris@49
|
608
|
Chris@49
|
609 template<typename eglue_type>
|
Chris@49
|
610 template<typename T1, typename T2>
|
Chris@49
|
611 arma_hot
|
Chris@49
|
612 inline
|
Chris@49
|
613 void
|
Chris@49
|
614 eglue_core<eglue_type>::apply_inplace_plus(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x)
|
Chris@49
|
615 {
|
Chris@49
|
616 arma_extra_debug_sigprint();
|
Chris@49
|
617
|
Chris@49
|
618 const uword n_rows = x.get_n_rows();
|
Chris@49
|
619 const uword n_cols = x.get_n_cols();
|
Chris@49
|
620 const uword n_slices = x.get_n_slices();
|
Chris@49
|
621
|
Chris@49
|
622 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition");
|
Chris@49
|
623
|
Chris@49
|
624 typedef typename T1::elem_type eT;
|
Chris@49
|
625
|
Chris@49
|
626 eT* out_mem = out.memptr();
|
Chris@49
|
627
|
Chris@49
|
628 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
|
Chris@49
|
629
|
Chris@49
|
630 if(prefer_at_accessor == false)
|
Chris@49
|
631 {
|
Chris@49
|
632 const uword n_elem = out.n_elem;
|
Chris@49
|
633
|
Chris@49
|
634 if(memory::is_aligned(out_mem))
|
Chris@49
|
635 {
|
Chris@49
|
636 memory::mark_as_aligned(out_mem);
|
Chris@49
|
637
|
Chris@49
|
638 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
639 {
|
Chris@49
|
640 typename ProxyCube<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
641 typename ProxyCube<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
642
|
Chris@49
|
643 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(+=, +); }
|
Chris@49
|
644 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(+=, -); }
|
Chris@49
|
645 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(+=, /); }
|
Chris@49
|
646 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(+=, *); }
|
Chris@49
|
647 }
|
Chris@49
|
648 else
|
Chris@49
|
649 {
|
Chris@49
|
650 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
651 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
652
|
Chris@49
|
653 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(+=, +); }
|
Chris@49
|
654 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(+=, -); }
|
Chris@49
|
655 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(+=, /); }
|
Chris@49
|
656 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(+=, *); }
|
Chris@49
|
657 }
|
Chris@49
|
658 }
|
Chris@49
|
659 else
|
Chris@49
|
660 {
|
Chris@49
|
661 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
662 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
663
|
Chris@49
|
664 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(+=, +); }
|
Chris@49
|
665 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(+=, -); }
|
Chris@49
|
666 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(+=, /); }
|
Chris@49
|
667 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(+=, *); }
|
Chris@49
|
668 }
|
Chris@49
|
669 }
|
Chris@49
|
670 else
|
Chris@49
|
671 {
|
Chris@49
|
672 const ProxyCube<T1>& P1 = x.P1;
|
Chris@49
|
673 const ProxyCube<T2>& P2 = x.P2;
|
Chris@49
|
674
|
Chris@49
|
675 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(+=, +); }
|
Chris@49
|
676 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(+=, -); }
|
Chris@49
|
677 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(+=, /); }
|
Chris@49
|
678 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(+=, *); }
|
Chris@49
|
679 }
|
Chris@49
|
680 }
|
Chris@49
|
681
|
Chris@49
|
682
|
Chris@49
|
683
|
Chris@49
|
684 template<typename eglue_type>
|
Chris@49
|
685 template<typename T1, typename T2>
|
Chris@49
|
686 arma_hot
|
Chris@49
|
687 inline
|
Chris@49
|
688 void
|
Chris@49
|
689 eglue_core<eglue_type>::apply_inplace_minus(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x)
|
Chris@49
|
690 {
|
Chris@49
|
691 arma_extra_debug_sigprint();
|
Chris@49
|
692
|
Chris@49
|
693 const uword n_rows = x.get_n_rows();
|
Chris@49
|
694 const uword n_cols = x.get_n_cols();
|
Chris@49
|
695 const uword n_slices = x.get_n_slices();
|
Chris@49
|
696
|
Chris@49
|
697 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction");
|
Chris@49
|
698
|
Chris@49
|
699 typedef typename T1::elem_type eT;
|
Chris@49
|
700
|
Chris@49
|
701 eT* out_mem = out.memptr();
|
Chris@49
|
702
|
Chris@49
|
703 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
|
Chris@49
|
704
|
Chris@49
|
705 if(prefer_at_accessor == false)
|
Chris@49
|
706 {
|
Chris@49
|
707 const uword n_elem = out.n_elem;
|
Chris@49
|
708
|
Chris@49
|
709 if(memory::is_aligned(out_mem))
|
Chris@49
|
710 {
|
Chris@49
|
711 memory::mark_as_aligned(out_mem);
|
Chris@49
|
712
|
Chris@49
|
713 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
714 {
|
Chris@49
|
715 typename ProxyCube<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
716 typename ProxyCube<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
717
|
Chris@49
|
718 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(-=, +); }
|
Chris@49
|
719 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(-=, -); }
|
Chris@49
|
720 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(-=, /); }
|
Chris@49
|
721 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(-=, *); }
|
Chris@49
|
722 }
|
Chris@49
|
723 else
|
Chris@49
|
724 {
|
Chris@49
|
725 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
726 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
727
|
Chris@49
|
728 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(-=, +); }
|
Chris@49
|
729 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(-=, -); }
|
Chris@49
|
730 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(-=, /); }
|
Chris@49
|
731 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(-=, *); }
|
Chris@49
|
732 }
|
Chris@49
|
733 }
|
Chris@49
|
734 else
|
Chris@49
|
735 {
|
Chris@49
|
736 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
737 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
738
|
Chris@49
|
739 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(-=, +); }
|
Chris@49
|
740 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(-=, -); }
|
Chris@49
|
741 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(-=, /); }
|
Chris@49
|
742 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(-=, *); }
|
Chris@49
|
743 }
|
Chris@49
|
744 }
|
Chris@49
|
745 else
|
Chris@49
|
746 {
|
Chris@49
|
747 const ProxyCube<T1>& P1 = x.P1;
|
Chris@49
|
748 const ProxyCube<T2>& P2 = x.P2;
|
Chris@49
|
749
|
Chris@49
|
750 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(-=, +); }
|
Chris@49
|
751 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(-=, -); }
|
Chris@49
|
752 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(-=, /); }
|
Chris@49
|
753 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(-=, *); }
|
Chris@49
|
754 }
|
Chris@49
|
755 }
|
Chris@49
|
756
|
Chris@49
|
757
|
Chris@49
|
758
|
Chris@49
|
759 template<typename eglue_type>
|
Chris@49
|
760 template<typename T1, typename T2>
|
Chris@49
|
761 arma_hot
|
Chris@49
|
762 inline
|
Chris@49
|
763 void
|
Chris@49
|
764 eglue_core<eglue_type>::apply_inplace_schur(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x)
|
Chris@49
|
765 {
|
Chris@49
|
766 arma_extra_debug_sigprint();
|
Chris@49
|
767
|
Chris@49
|
768 const uword n_rows = x.get_n_rows();
|
Chris@49
|
769 const uword n_cols = x.get_n_cols();
|
Chris@49
|
770 const uword n_slices = x.get_n_slices();
|
Chris@49
|
771
|
Chris@49
|
772 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication");
|
Chris@49
|
773
|
Chris@49
|
774 typedef typename T1::elem_type eT;
|
Chris@49
|
775
|
Chris@49
|
776 eT* out_mem = out.memptr();
|
Chris@49
|
777
|
Chris@49
|
778 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
|
Chris@49
|
779
|
Chris@49
|
780 if(prefer_at_accessor == false)
|
Chris@49
|
781 {
|
Chris@49
|
782 const uword n_elem = out.n_elem;
|
Chris@49
|
783
|
Chris@49
|
784 if(memory::is_aligned(out_mem))
|
Chris@49
|
785 {
|
Chris@49
|
786 memory::mark_as_aligned(out_mem);
|
Chris@49
|
787
|
Chris@49
|
788 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
789 {
|
Chris@49
|
790 typename ProxyCube<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
791 typename ProxyCube<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
792
|
Chris@49
|
793 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(*=, +); }
|
Chris@49
|
794 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(*=, -); }
|
Chris@49
|
795 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(*=, /); }
|
Chris@49
|
796 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(*=, *); }
|
Chris@49
|
797 }
|
Chris@49
|
798 else
|
Chris@49
|
799 {
|
Chris@49
|
800 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
801 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
802
|
Chris@49
|
803 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(*=, +); }
|
Chris@49
|
804 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(*=, -); }
|
Chris@49
|
805 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(*=, /); }
|
Chris@49
|
806 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(*=, *); }
|
Chris@49
|
807 }
|
Chris@49
|
808 }
|
Chris@49
|
809 else
|
Chris@49
|
810 {
|
Chris@49
|
811 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
812 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
813
|
Chris@49
|
814 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(*=, +); }
|
Chris@49
|
815 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(*=, -); }
|
Chris@49
|
816 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(*=, /); }
|
Chris@49
|
817 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(*=, *); }
|
Chris@49
|
818 }
|
Chris@49
|
819 }
|
Chris@49
|
820 else
|
Chris@49
|
821 {
|
Chris@49
|
822 const ProxyCube<T1>& P1 = x.P1;
|
Chris@49
|
823 const ProxyCube<T2>& P2 = x.P2;
|
Chris@49
|
824
|
Chris@49
|
825 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(*=, +); }
|
Chris@49
|
826 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(*=, -); }
|
Chris@49
|
827 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(*=, /); }
|
Chris@49
|
828 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(*=, *); }
|
Chris@49
|
829 }
|
Chris@49
|
830 }
|
Chris@49
|
831
|
Chris@49
|
832
|
Chris@49
|
833
|
Chris@49
|
834 template<typename eglue_type>
|
Chris@49
|
835 template<typename T1, typename T2>
|
Chris@49
|
836 arma_hot
|
Chris@49
|
837 inline
|
Chris@49
|
838 void
|
Chris@49
|
839 eglue_core<eglue_type>::apply_inplace_div(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x)
|
Chris@49
|
840 {
|
Chris@49
|
841 arma_extra_debug_sigprint();
|
Chris@49
|
842
|
Chris@49
|
843 const uword n_rows = x.get_n_rows();
|
Chris@49
|
844 const uword n_cols = x.get_n_cols();
|
Chris@49
|
845 const uword n_slices = x.get_n_slices();
|
Chris@49
|
846
|
Chris@49
|
847 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division");
|
Chris@49
|
848
|
Chris@49
|
849 typedef typename T1::elem_type eT;
|
Chris@49
|
850
|
Chris@49
|
851 eT* out_mem = out.memptr();
|
Chris@49
|
852
|
Chris@49
|
853 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor);
|
Chris@49
|
854
|
Chris@49
|
855 if(prefer_at_accessor == false)
|
Chris@49
|
856 {
|
Chris@49
|
857 const uword n_elem = out.n_elem;
|
Chris@49
|
858
|
Chris@49
|
859 if(memory::is_aligned(out_mem))
|
Chris@49
|
860 {
|
Chris@49
|
861 memory::mark_as_aligned(out_mem);
|
Chris@49
|
862
|
Chris@49
|
863 if(x.P1.is_aligned() && x.P2.is_aligned())
|
Chris@49
|
864 {
|
Chris@49
|
865 typename ProxyCube<T1>::aligned_ea_type P1 = x.P1.get_aligned_ea();
|
Chris@49
|
866 typename ProxyCube<T2>::aligned_ea_type P2 = x.P2.get_aligned_ea();
|
Chris@49
|
867
|
Chris@49
|
868 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1a(/=, +); }
|
Chris@49
|
869 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1a(/=, -); }
|
Chris@49
|
870 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1a(/=, /); }
|
Chris@49
|
871 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1a(/=, *); }
|
Chris@49
|
872 }
|
Chris@49
|
873 else
|
Chris@49
|
874 {
|
Chris@49
|
875 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
876 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
877
|
Chris@49
|
878 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(/=, +); }
|
Chris@49
|
879 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(/=, -); }
|
Chris@49
|
880 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(/=, /); }
|
Chris@49
|
881 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(/=, *); }
|
Chris@49
|
882 }
|
Chris@49
|
883 }
|
Chris@49
|
884 else
|
Chris@49
|
885 {
|
Chris@49
|
886 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea();
|
Chris@49
|
887 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea();
|
Chris@49
|
888
|
Chris@49
|
889 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1u(/=, +); }
|
Chris@49
|
890 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1u(/=, -); }
|
Chris@49
|
891 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1u(/=, /); }
|
Chris@49
|
892 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1u(/=, *); }
|
Chris@49
|
893 }
|
Chris@49
|
894 }
|
Chris@49
|
895 else
|
Chris@49
|
896 {
|
Chris@49
|
897 const ProxyCube<T1>& P1 = x.P1;
|
Chris@49
|
898 const ProxyCube<T2>& P2 = x.P2;
|
Chris@49
|
899
|
Chris@49
|
900 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(/=, +); }
|
Chris@49
|
901 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(/=, -); }
|
Chris@49
|
902 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(/=, /); }
|
Chris@49
|
903 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(/=, *); }
|
Chris@49
|
904 }
|
Chris@49
|
905 }
|
Chris@49
|
906
|
Chris@49
|
907
|
Chris@49
|
908
|
Chris@49
|
909 #undef arma_applier_1u
|
Chris@49
|
910 #undef arma_applier_1a
|
Chris@49
|
911 #undef arma_applier_2
|
Chris@49
|
912 #undef arma_applier_3
|
Chris@49
|
913
|
Chris@49
|
914
|
Chris@49
|
915
|
Chris@49
|
916 //! @}
|