Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-2.4.4/include/armadillo_bits/eglue_core_meat.hpp @ 0:8b6102e2a9b0
Armadillo Library
author | maxzanoni76 <max.zanoni@eecs.qmul.ac.uk> |
---|---|
date | Wed, 11 Apr 2012 09:27:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8b6102e2a9b0 |
---|---|
1 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au) | |
2 // Copyright (C) 2010-2011 Conrad Sanderson | |
3 // | |
4 // This file is part of the Armadillo C++ library. | |
5 // It is provided without any warranty of fitness | |
6 // for any purpose. You can redistribute this file | |
7 // and/or modify it under the terms of the GNU | |
8 // Lesser General Public License (LGPL) as published | |
9 // by the Free Software Foundation, either version 3 | |
10 // of the License or (at your option) any later version. | |
11 // (see http://www.opensource.org/licenses for more info) | |
12 | |
13 | |
14 //! \addtogroup eglue_core | |
15 //! @{ | |
16 | |
17 | |
18 | |
19 class eglue_plus : public eglue_core<eglue_plus> | |
20 { | |
21 public: | |
22 | |
23 inline static const char* text() { return "addition"; } | |
24 }; | |
25 | |
26 | |
27 | |
28 class eglue_minus : public eglue_core<eglue_minus> | |
29 { | |
30 public: | |
31 | |
32 inline static const char* text() { return "subtraction"; } | |
33 }; | |
34 | |
35 | |
36 | |
37 class eglue_div : public eglue_core<eglue_div> | |
38 { | |
39 public: | |
40 | |
41 inline static const char* text() { return "element-wise division"; } | |
42 }; | |
43 | |
44 | |
45 | |
46 class eglue_schur : public eglue_core<eglue_schur> | |
47 { | |
48 public: | |
49 | |
50 inline static const char* text() { return "element-wise multiplication"; } | |
51 }; | |
52 | |
53 | |
54 | |
55 #undef arma_applier_1 | |
56 #undef arma_applier_2 | |
57 #undef arma_applier_3 | |
58 #undef operatorA | |
59 #undef operatorB | |
60 | |
61 #define arma_applier_1(operatorA, operatorB) \ | |
62 {\ | |
63 uword i,j;\ | |
64 \ | |
65 for(i=0, j=1; j<n_elem; i+=2, j+=2)\ | |
66 {\ | |
67 eT tmp_i = P1[i];\ | |
68 eT tmp_j = P1[j];\ | |
69 \ | |
70 tmp_i operatorB##= P2[i];\ | |
71 tmp_j operatorB##= P2[j];\ | |
72 \ | |
73 out_mem[i] operatorA tmp_i;\ | |
74 out_mem[j] operatorA tmp_j;\ | |
75 }\ | |
76 \ | |
77 if(i < n_elem)\ | |
78 {\ | |
79 out_mem[i] operatorA P1[i] operatorB P2[i];\ | |
80 }\ | |
81 } | |
82 | |
83 | |
84 | |
85 #define arma_applier_2(operatorA, operatorB) \ | |
86 {\ | |
87 uword count = 0;\ | |
88 \ | |
89 for(uword col=0; col<n_cols; ++col)\ | |
90 {\ | |
91 uword i,j;\ | |
92 \ | |
93 for(i=0, j=1; j<n_rows; i+=2, j+=2, count+=2)\ | |
94 {\ | |
95 eT tmp_i = P1.at(i,col);\ | |
96 eT tmp_j = P1.at(j,col);\ | |
97 \ | |
98 tmp_i operatorB##= P2.at(i,col);\ | |
99 tmp_j operatorB##= P2.at(j,col);\ | |
100 \ | |
101 out_mem[count ] operatorA tmp_i;\ | |
102 out_mem[count+1] operatorA tmp_j;\ | |
103 }\ | |
104 \ | |
105 if(i < n_rows)\ | |
106 {\ | |
107 out_mem[count] operatorA P1.at(i,col) operatorB P2.at(i,col);\ | |
108 ++count;\ | |
109 }\ | |
110 }\ | |
111 } | |
112 | |
113 | |
114 | |
115 #define arma_applier_3(operatorA, operatorB) \ | |
116 {\ | |
117 uword count = 0;\ | |
118 \ | |
119 for(uword slice=0; slice<n_slices; ++slice)\ | |
120 {\ | |
121 for(uword col=0; col<n_cols; ++col)\ | |
122 {\ | |
123 uword i,j;\ | |
124 \ | |
125 for(i=0, j=1; j<n_rows; i+=2, j+=2, count+=2)\ | |
126 {\ | |
127 eT tmp_i = P1.at(i,col,slice);\ | |
128 eT tmp_j = P1.at(j,col,slice);\ | |
129 \ | |
130 tmp_i operatorB##= P2.at(i,col,slice);\ | |
131 tmp_j operatorB##= P2.at(j,col,slice);\ | |
132 \ | |
133 out_mem[count ] operatorA tmp_i;\ | |
134 out_mem[count+1] operatorA tmp_j;\ | |
135 }\ | |
136 \ | |
137 if(i < n_rows)\ | |
138 {\ | |
139 out_mem[count] operatorA P1.at(i,col,slice) operatorB P2.at(i,col,slice);\ | |
140 ++count;\ | |
141 }\ | |
142 }\ | |
143 }\ | |
144 } | |
145 | |
146 | |
147 | |
148 // | |
149 // matrices | |
150 | |
151 | |
152 | |
153 template<typename eglue_type> | |
154 template<typename T1, typename T2> | |
155 arma_hot | |
156 inline | |
157 void | |
158 eglue_core<eglue_type>::apply(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x) | |
159 { | |
160 arma_extra_debug_sigprint(); | |
161 | |
162 typedef typename T1::elem_type eT; | |
163 | |
164 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
165 | |
166 // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; | |
167 // size setting and alias checking is done by either the Mat contructor or operator=() | |
168 | |
169 eT* out_mem = out.memptr(); | |
170 | |
171 if(prefer_at_accessor == false) | |
172 { | |
173 const uword n_elem = out.n_elem; | |
174 | |
175 typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
176 typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
177 | |
178 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(=, +); } | |
179 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(=, -); } | |
180 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(=, /); } | |
181 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(=, *); } | |
182 } | |
183 else | |
184 { | |
185 const uword n_rows = out.n_rows; | |
186 const uword n_cols = out.n_cols; | |
187 | |
188 const Proxy<T1>& P1 = x.P1; | |
189 const Proxy<T2>& P2 = x.P2; | |
190 | |
191 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(=, +); } | |
192 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(=, -); } | |
193 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(=, /); } | |
194 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(=, *); } | |
195 } | |
196 } | |
197 | |
198 | |
199 | |
200 template<typename eglue_type> | |
201 template<typename T1, typename T2> | |
202 arma_hot | |
203 inline | |
204 void | |
205 eglue_core<eglue_type>::apply_inplace_plus(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x) | |
206 { | |
207 arma_extra_debug_sigprint(); | |
208 | |
209 arma_debug_assert_same_size(out, x.P1, "addition"); | |
210 | |
211 typedef typename T1::elem_type eT; | |
212 | |
213 eT* out_mem = out.memptr(); | |
214 | |
215 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
216 | |
217 if(prefer_at_accessor == false) | |
218 { | |
219 const uword n_elem = out.n_elem; | |
220 | |
221 typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
222 typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
223 | |
224 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(+=, +); } | |
225 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(+=, -); } | |
226 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(+=, /); } | |
227 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(+=, *); } | |
228 } | |
229 else | |
230 { | |
231 const uword n_rows = out.n_rows; | |
232 const uword n_cols = out.n_cols; | |
233 | |
234 const Proxy<T1>& P1 = x.P1; | |
235 const Proxy<T2>& P2 = x.P2; | |
236 | |
237 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(+=, +); } | |
238 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(+=, -); } | |
239 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(+=, /); } | |
240 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(+=, *); } | |
241 } | |
242 } | |
243 | |
244 | |
245 | |
246 template<typename eglue_type> | |
247 template<typename T1, typename T2> | |
248 arma_hot | |
249 inline | |
250 void | |
251 eglue_core<eglue_type>::apply_inplace_minus(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x) | |
252 { | |
253 arma_extra_debug_sigprint(); | |
254 | |
255 arma_debug_assert_same_size(out, x.P1, "subtraction"); | |
256 | |
257 typedef typename T1::elem_type eT; | |
258 | |
259 eT* out_mem = out.memptr(); | |
260 | |
261 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
262 | |
263 if(prefer_at_accessor == false) | |
264 { | |
265 const uword n_elem = out.n_elem; | |
266 | |
267 typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
268 typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
269 | |
270 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(-=, +); } | |
271 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(-=, -); } | |
272 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(-=, /); } | |
273 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(-=, *); } | |
274 } | |
275 else | |
276 { | |
277 const uword n_rows = out.n_rows; | |
278 const uword n_cols = out.n_cols; | |
279 | |
280 const Proxy<T1>& P1 = x.P1; | |
281 const Proxy<T2>& P2 = x.P2; | |
282 | |
283 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(-=, +); } | |
284 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(-=, -); } | |
285 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(-=, /); } | |
286 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(-=, *); } | |
287 } | |
288 } | |
289 | |
290 | |
291 | |
292 template<typename eglue_type> | |
293 template<typename T1, typename T2> | |
294 arma_hot | |
295 inline | |
296 void | |
297 eglue_core<eglue_type>::apply_inplace_schur(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x) | |
298 { | |
299 arma_extra_debug_sigprint(); | |
300 | |
301 arma_debug_assert_same_size(out, x.P1, "element-wise multiplication"); | |
302 | |
303 typedef typename T1::elem_type eT; | |
304 | |
305 eT* out_mem = out.memptr(); | |
306 | |
307 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
308 | |
309 if(prefer_at_accessor == false) | |
310 { | |
311 const uword n_elem = out.n_elem; | |
312 | |
313 typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
314 typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
315 | |
316 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(*=, +); } | |
317 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(*=, -); } | |
318 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(*=, /); } | |
319 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(*=, *); } | |
320 } | |
321 else | |
322 { | |
323 const uword n_rows = out.n_rows; | |
324 const uword n_cols = out.n_cols; | |
325 | |
326 const Proxy<T1>& P1 = x.P1; | |
327 const Proxy<T2>& P2 = x.P2; | |
328 | |
329 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(*=, +); } | |
330 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(*=, -); } | |
331 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(*=, /); } | |
332 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(*=, *); } | |
333 } | |
334 } | |
335 | |
336 | |
337 | |
338 template<typename eglue_type> | |
339 template<typename T1, typename T2> | |
340 arma_hot | |
341 inline | |
342 void | |
343 eglue_core<eglue_type>::apply_inplace_div(Mat<typename T1::elem_type>& out, const eGlue<T1, T2, eglue_type>& x) | |
344 { | |
345 arma_extra_debug_sigprint(); | |
346 | |
347 arma_debug_assert_same_size(out, x.P1, "element-wise division"); | |
348 | |
349 typedef typename T1::elem_type eT; | |
350 | |
351 eT* out_mem = out.memptr(); | |
352 | |
353 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
354 | |
355 if(prefer_at_accessor == false) | |
356 { | |
357 const uword n_elem = out.n_elem; | |
358 | |
359 typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
360 typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
361 | |
362 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(/=, +); } | |
363 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(/=, -); } | |
364 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(/=, /); } | |
365 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(/=, *); } | |
366 } | |
367 else | |
368 { | |
369 const uword n_rows = out.n_rows; | |
370 const uword n_cols = out.n_cols; | |
371 | |
372 const Proxy<T1>& P1 = x.P1; | |
373 const Proxy<T2>& P2 = x.P2; | |
374 | |
375 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_2(*=, +); } | |
376 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_2(*=, -); } | |
377 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_2(*=, /); } | |
378 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_2(*=, *); } | |
379 } | |
380 } | |
381 | |
382 | |
383 | |
384 // | |
385 // cubes | |
386 | |
387 | |
388 | |
389 template<typename eglue_type> | |
390 template<typename T1, typename T2> | |
391 arma_hot | |
392 inline | |
393 void | |
394 eglue_core<eglue_type>::apply(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x) | |
395 { | |
396 arma_extra_debug_sigprint(); | |
397 | |
398 typedef typename T1::elem_type eT; | |
399 | |
400 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor); | |
401 | |
402 // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing; | |
403 // size setting and alias checking is done by either the Cube contructor or operator=() | |
404 | |
405 | |
406 eT* out_mem = out.memptr(); | |
407 | |
408 if(prefer_at_accessor == false) | |
409 { | |
410 const uword n_elem = out.n_elem; | |
411 | |
412 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
413 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
414 | |
415 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(=, +); } | |
416 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(=, -); } | |
417 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(=, /); } | |
418 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(=, *); } | |
419 } | |
420 else | |
421 { | |
422 const uword n_rows = x.get_n_rows(); | |
423 const uword n_cols = x.get_n_cols(); | |
424 const uword n_slices = x.get_n_slices(); | |
425 | |
426 const ProxyCube<T1>& P1 = x.P1; | |
427 const ProxyCube<T2>& P2 = x.P2; | |
428 | |
429 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(=, +); } | |
430 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(=, -); } | |
431 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(=, /); } | |
432 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(=, *); } | |
433 } | |
434 } | |
435 | |
436 | |
437 | |
438 template<typename eglue_type> | |
439 template<typename T1, typename T2> | |
440 arma_hot | |
441 inline | |
442 void | |
443 eglue_core<eglue_type>::apply_inplace_plus(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x) | |
444 { | |
445 arma_extra_debug_sigprint(); | |
446 | |
447 const uword n_rows = x.get_n_rows(); | |
448 const uword n_cols = x.get_n_cols(); | |
449 const uword n_slices = x.get_n_slices(); | |
450 | |
451 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); | |
452 | |
453 typedef typename T1::elem_type eT; | |
454 | |
455 eT* out_mem = out.memptr(); | |
456 | |
457 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor); | |
458 | |
459 if(prefer_at_accessor == false) | |
460 { | |
461 const uword n_elem = out.n_elem; | |
462 | |
463 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
464 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
465 | |
466 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(+=, +); } | |
467 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(+=, -); } | |
468 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(+=, /); } | |
469 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(+=, *); } | |
470 } | |
471 else | |
472 { | |
473 const ProxyCube<T1>& P1 = x.P1; | |
474 const ProxyCube<T2>& P2 = x.P2; | |
475 | |
476 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(+=, +); } | |
477 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(+=, -); } | |
478 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(+=, /); } | |
479 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(+=, *); } | |
480 } | |
481 } | |
482 | |
483 | |
484 | |
485 template<typename eglue_type> | |
486 template<typename T1, typename T2> | |
487 arma_hot | |
488 inline | |
489 void | |
490 eglue_core<eglue_type>::apply_inplace_minus(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x) | |
491 { | |
492 arma_extra_debug_sigprint(); | |
493 | |
494 const uword n_rows = x.get_n_rows(); | |
495 const uword n_cols = x.get_n_cols(); | |
496 const uword n_slices = x.get_n_slices(); | |
497 | |
498 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); | |
499 | |
500 typedef typename T1::elem_type eT; | |
501 | |
502 eT* out_mem = out.memptr(); | |
503 | |
504 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor); | |
505 | |
506 if(prefer_at_accessor == false) | |
507 { | |
508 const uword n_elem = out.n_elem; | |
509 | |
510 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
511 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
512 | |
513 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(-=, +); } | |
514 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(-=, -); } | |
515 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(-=, /); } | |
516 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(-=, *); } | |
517 } | |
518 else | |
519 { | |
520 const ProxyCube<T1>& P1 = x.P1; | |
521 const ProxyCube<T2>& P2 = x.P2; | |
522 | |
523 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(-=, +); } | |
524 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(-=, -); } | |
525 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(-=, /); } | |
526 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(-=, *); } | |
527 } | |
528 } | |
529 | |
530 | |
531 | |
532 template<typename eglue_type> | |
533 template<typename T1, typename T2> | |
534 arma_hot | |
535 inline | |
536 void | |
537 eglue_core<eglue_type>::apply_inplace_schur(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x) | |
538 { | |
539 arma_extra_debug_sigprint(); | |
540 | |
541 const uword n_rows = x.get_n_rows(); | |
542 const uword n_cols = x.get_n_cols(); | |
543 const uword n_slices = x.get_n_slices(); | |
544 | |
545 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); | |
546 | |
547 typedef typename T1::elem_type eT; | |
548 | |
549 eT* out_mem = out.memptr(); | |
550 | |
551 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor); | |
552 | |
553 if(prefer_at_accessor == false) | |
554 { | |
555 const uword n_elem = out.n_elem; | |
556 | |
557 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
558 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
559 | |
560 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(*=, +); } | |
561 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(*=, -); } | |
562 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(*=, /); } | |
563 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(*=, *); } | |
564 } | |
565 else | |
566 { | |
567 const ProxyCube<T1>& P1 = x.P1; | |
568 const ProxyCube<T2>& P2 = x.P2; | |
569 | |
570 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(*=, +); } | |
571 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(*=, -); } | |
572 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(*=, /); } | |
573 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(*=, *); } | |
574 } | |
575 } | |
576 | |
577 | |
578 | |
579 template<typename eglue_type> | |
580 template<typename T1, typename T2> | |
581 arma_hot | |
582 inline | |
583 void | |
584 eglue_core<eglue_type>::apply_inplace_div(Cube<typename T1::elem_type>& out, const eGlueCube<T1, T2, eglue_type>& x) | |
585 { | |
586 arma_extra_debug_sigprint(); | |
587 | |
588 const uword n_rows = x.get_n_rows(); | |
589 const uword n_cols = x.get_n_cols(); | |
590 const uword n_slices = x.get_n_slices(); | |
591 | |
592 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); | |
593 | |
594 typedef typename T1::elem_type eT; | |
595 | |
596 eT* out_mem = out.memptr(); | |
597 | |
598 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor); | |
599 | |
600 if(prefer_at_accessor == false) | |
601 { | |
602 const uword n_elem = out.n_elem; | |
603 | |
604 typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
605 typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
606 | |
607 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_1(/=, +); } | |
608 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_1(/=, -); } | |
609 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_1(/=, /); } | |
610 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_1(/=, *); } | |
611 } | |
612 else | |
613 { | |
614 const ProxyCube<T1>& P1 = x.P1; | |
615 const ProxyCube<T2>& P2 = x.P2; | |
616 | |
617 if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_applier_3(/=, +); } | |
618 else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_applier_3(/=, -); } | |
619 else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_applier_3(/=, /); } | |
620 else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_applier_3(/=, *); } | |
621 } | |
622 } | |
623 | |
624 | |
625 | |
626 #undef arma_applier_1 | |
627 #undef arma_applier_2 | |
628 #undef arma_applier_3 | |
629 | |
630 | |
631 | |
632 //! @} |