Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-3.900.4/include/armadillo_bits/glue_mixed_meat.hpp @ 49:1ec0e2823891
Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author | Chris Cannam |
---|---|
date | Thu, 13 Jun 2013 10:25:24 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
48:69251e11a913 | 49:1ec0e2823891 |
---|---|
1 // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) | |
2 // Copyright (C) 2009-2013 Conrad Sanderson | |
3 // | |
4 // This Source Code Form is subject to the terms of the Mozilla Public | |
5 // License, v. 2.0. If a copy of the MPL was not distributed with this | |
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
7 | |
8 | |
9 //! \addtogroup glue_mixed | |
10 //! @{ | |
11 | |
12 | |
13 | |
14 //! matrix multiplication with different element types | |
15 template<typename T1, typename T2> | |
16 inline | |
17 void | |
18 glue_mixed_times::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_times>& X) | |
19 { | |
20 arma_extra_debug_sigprint(); | |
21 | |
22 typedef typename T1::elem_type eT1; | |
23 typedef typename T2::elem_type eT2; | |
24 | |
25 const unwrap_check_mixed<T1> tmp1(X.A, out); | |
26 const unwrap_check_mixed<T2> tmp2(X.B, out); | |
27 | |
28 const Mat<eT1>& A = tmp1.M; | |
29 const Mat<eT2>& B = tmp2.M; | |
30 | |
31 arma_debug_assert_mul_size(A, B, "matrix multiplication"); | |
32 | |
33 out.set_size(A.n_rows, B.n_cols); | |
34 | |
35 gemm_mixed<>::apply(out, A, B); | |
36 } | |
37 | |
38 | |
39 | |
40 //! matrix addition with different element types | |
41 template<typename T1, typename T2> | |
42 inline | |
43 void | |
44 glue_mixed_plus::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_plus>& X) | |
45 { | |
46 arma_extra_debug_sigprint(); | |
47 | |
48 typedef typename T1::elem_type eT1; | |
49 typedef typename T2::elem_type eT2; | |
50 | |
51 typedef typename promote_type<eT1,eT2>::result out_eT; | |
52 | |
53 promote_type<eT1,eT2>::check(); | |
54 | |
55 const Proxy<T1> A(X.A); | |
56 const Proxy<T2> B(X.B); | |
57 | |
58 arma_debug_assert_same_size(A, B, "addition"); | |
59 | |
60 const uword n_rows = A.get_n_rows(); | |
61 const uword n_cols = A.get_n_cols(); | |
62 | |
63 out.set_size(n_rows, n_cols); | |
64 | |
65 out_eT* out_mem = out.memptr(); | |
66 const uword n_elem = out.n_elem; | |
67 | |
68 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
69 | |
70 if(prefer_at_accessor == false) | |
71 { | |
72 typename Proxy<T1>::ea_type AA = A.get_ea(); | |
73 typename Proxy<T2>::ea_type BB = B.get_ea(); | |
74 | |
75 if(memory::is_aligned(out_mem)) | |
76 { | |
77 memory::mark_as_aligned(out_mem); | |
78 | |
79 for(uword i=0; i<n_elem; ++i) | |
80 { | |
81 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) + upgrade_val<eT1,eT2>::apply(BB[i]); | |
82 } | |
83 } | |
84 else | |
85 { | |
86 for(uword i=0; i<n_elem; ++i) | |
87 { | |
88 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) + upgrade_val<eT1,eT2>::apply(BB[i]); | |
89 } | |
90 } | |
91 } | |
92 else | |
93 { | |
94 uword i = 0; | |
95 | |
96 for(uword col=0; col < n_cols; ++col) | |
97 for(uword row=0; row < n_rows; ++row) | |
98 { | |
99 out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col)) + upgrade_val<eT1,eT2>::apply(B.at(row,col)); | |
100 ++i; | |
101 } | |
102 } | |
103 } | |
104 | |
105 | |
106 | |
107 //! matrix subtraction with different element types | |
108 template<typename T1, typename T2> | |
109 inline | |
110 void | |
111 glue_mixed_minus::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_minus>& X) | |
112 { | |
113 arma_extra_debug_sigprint(); | |
114 | |
115 typedef typename T1::elem_type eT1; | |
116 typedef typename T2::elem_type eT2; | |
117 | |
118 typedef typename promote_type<eT1,eT2>::result out_eT; | |
119 | |
120 promote_type<eT1,eT2>::check(); | |
121 | |
122 const Proxy<T1> A(X.A); | |
123 const Proxy<T2> B(X.B); | |
124 | |
125 arma_debug_assert_same_size(A, B, "subtraction"); | |
126 | |
127 const uword n_rows = A.get_n_rows(); | |
128 const uword n_cols = A.get_n_cols(); | |
129 | |
130 out.set_size(n_rows, n_cols); | |
131 | |
132 out_eT* out_mem = out.memptr(); | |
133 const uword n_elem = out.n_elem; | |
134 | |
135 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
136 | |
137 if(prefer_at_accessor == false) | |
138 { | |
139 typename Proxy<T1>::ea_type AA = A.get_ea(); | |
140 typename Proxy<T2>::ea_type BB = B.get_ea(); | |
141 | |
142 if(memory::is_aligned(out_mem)) | |
143 { | |
144 memory::mark_as_aligned(out_mem); | |
145 | |
146 for(uword i=0; i<n_elem; ++i) | |
147 { | |
148 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) - upgrade_val<eT1,eT2>::apply(BB[i]); | |
149 } | |
150 } | |
151 else | |
152 { | |
153 for(uword i=0; i<n_elem; ++i) | |
154 { | |
155 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) - upgrade_val<eT1,eT2>::apply(BB[i]); | |
156 } | |
157 } | |
158 } | |
159 else | |
160 { | |
161 uword i = 0; | |
162 | |
163 for(uword col=0; col < n_cols; ++col) | |
164 for(uword row=0; row < n_rows; ++row) | |
165 { | |
166 out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col)) - upgrade_val<eT1,eT2>::apply(B.at(row,col)); | |
167 ++i; | |
168 } | |
169 } | |
170 } | |
171 | |
172 | |
173 | |
174 //! element-wise matrix division with different element types | |
175 template<typename T1, typename T2> | |
176 inline | |
177 void | |
178 glue_mixed_div::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_div>& X) | |
179 { | |
180 arma_extra_debug_sigprint(); | |
181 | |
182 typedef typename T1::elem_type eT1; | |
183 typedef typename T2::elem_type eT2; | |
184 | |
185 typedef typename promote_type<eT1,eT2>::result out_eT; | |
186 | |
187 promote_type<eT1,eT2>::check(); | |
188 | |
189 const Proxy<T1> A(X.A); | |
190 const Proxy<T2> B(X.B); | |
191 | |
192 arma_debug_assert_same_size(A, B, "element-wise division"); | |
193 | |
194 const uword n_rows = A.get_n_rows(); | |
195 const uword n_cols = A.get_n_cols(); | |
196 | |
197 out.set_size(n_rows, n_cols); | |
198 | |
199 out_eT* out_mem = out.memptr(); | |
200 const uword n_elem = out.n_elem; | |
201 | |
202 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
203 | |
204 if(prefer_at_accessor == false) | |
205 { | |
206 typename Proxy<T1>::ea_type AA = A.get_ea(); | |
207 typename Proxy<T2>::ea_type BB = B.get_ea(); | |
208 | |
209 if(memory::is_aligned(out_mem)) | |
210 { | |
211 memory::mark_as_aligned(out_mem); | |
212 | |
213 for(uword i=0; i<n_elem; ++i) | |
214 { | |
215 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) / upgrade_val<eT1,eT2>::apply(BB[i]); | |
216 } | |
217 } | |
218 else | |
219 { | |
220 for(uword i=0; i<n_elem; ++i) | |
221 { | |
222 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) / upgrade_val<eT1,eT2>::apply(BB[i]); | |
223 } | |
224 } | |
225 } | |
226 else | |
227 { | |
228 uword i = 0; | |
229 | |
230 for(uword col=0; col < n_cols; ++col) | |
231 for(uword row=0; row < n_rows; ++row) | |
232 { | |
233 out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col)) / upgrade_val<eT1,eT2>::apply(B.at(row,col)); | |
234 ++i; | |
235 } | |
236 } | |
237 } | |
238 | |
239 | |
240 | |
241 //! element-wise matrix multiplication with different element types | |
242 template<typename T1, typename T2> | |
243 inline | |
244 void | |
245 glue_mixed_schur::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_schur>& X) | |
246 { | |
247 arma_extra_debug_sigprint(); | |
248 | |
249 typedef typename T1::elem_type eT1; | |
250 typedef typename T2::elem_type eT2; | |
251 | |
252 typedef typename promote_type<eT1,eT2>::result out_eT; | |
253 | |
254 promote_type<eT1,eT2>::check(); | |
255 | |
256 const Proxy<T1> A(X.A); | |
257 const Proxy<T2> B(X.B); | |
258 | |
259 arma_debug_assert_same_size(A, B, "element-wise multiplication"); | |
260 | |
261 const uword n_rows = A.get_n_rows(); | |
262 const uword n_cols = A.get_n_cols(); | |
263 | |
264 out.set_size(n_rows, n_cols); | |
265 | |
266 out_eT* out_mem = out.memptr(); | |
267 const uword n_elem = out.n_elem; | |
268 | |
269 const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); | |
270 | |
271 if(prefer_at_accessor == false) | |
272 { | |
273 typename Proxy<T1>::ea_type AA = A.get_ea(); | |
274 typename Proxy<T2>::ea_type BB = B.get_ea(); | |
275 | |
276 if(memory::is_aligned(out_mem)) | |
277 { | |
278 memory::mark_as_aligned(out_mem); | |
279 | |
280 for(uword i=0; i<n_elem; ++i) | |
281 { | |
282 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) * upgrade_val<eT1,eT2>::apply(BB[i]); | |
283 } | |
284 } | |
285 else | |
286 { | |
287 for(uword i=0; i<n_elem; ++i) | |
288 { | |
289 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) * upgrade_val<eT1,eT2>::apply(BB[i]); | |
290 } | |
291 } | |
292 } | |
293 else | |
294 { | |
295 uword i = 0; | |
296 | |
297 for(uword col=0; col < n_cols; ++col) | |
298 for(uword row=0; row < n_rows; ++row) | |
299 { | |
300 out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col)) * upgrade_val<eT1,eT2>::apply(B.at(row,col)); | |
301 ++i; | |
302 } | |
303 } | |
304 } | |
305 | |
306 | |
307 | |
308 // | |
309 // | |
310 // | |
311 | |
312 | |
313 | |
314 //! cube addition with different element types | |
315 template<typename T1, typename T2> | |
316 inline | |
317 void | |
318 glue_mixed_plus::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_plus>& X) | |
319 { | |
320 arma_extra_debug_sigprint(); | |
321 | |
322 typedef typename T1::elem_type eT1; | |
323 typedef typename T2::elem_type eT2; | |
324 | |
325 typedef typename promote_type<eT1,eT2>::result out_eT; | |
326 | |
327 promote_type<eT1,eT2>::check(); | |
328 | |
329 const ProxyCube<T1> A(X.A); | |
330 const ProxyCube<T2> B(X.B); | |
331 | |
332 arma_debug_assert_same_size(A, B, "addition"); | |
333 | |
334 const uword n_rows = A.get_n_rows(); | |
335 const uword n_cols = A.get_n_cols(); | |
336 const uword n_slices = A.get_n_slices(); | |
337 | |
338 out.set_size(n_rows, n_cols, n_slices); | |
339 | |
340 out_eT* out_mem = out.memptr(); | |
341 const uword n_elem = out.n_elem; | |
342 | |
343 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor); | |
344 | |
345 if(prefer_at_accessor == false) | |
346 { | |
347 typename ProxyCube<T1>::ea_type AA = A.get_ea(); | |
348 typename ProxyCube<T2>::ea_type BB = B.get_ea(); | |
349 | |
350 for(uword i=0; i<n_elem; ++i) | |
351 { | |
352 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) + upgrade_val<eT1,eT2>::apply(BB[i]); | |
353 } | |
354 } | |
355 else | |
356 { | |
357 uword i = 0; | |
358 | |
359 for(uword slice = 0; slice < n_slices; ++slice) | |
360 for(uword col = 0; col < n_cols; ++col ) | |
361 for(uword row = 0; row < n_rows; ++row ) | |
362 { | |
363 out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col,slice)) + upgrade_val<eT1,eT2>::apply(B.at(row,col,slice)); | |
364 ++i; | |
365 } | |
366 } | |
367 } | |
368 | |
369 | |
370 | |
371 //! cube subtraction with different element types | |
372 template<typename T1, typename T2> | |
373 inline | |
374 void | |
375 glue_mixed_minus::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_minus>& X) | |
376 { | |
377 arma_extra_debug_sigprint(); | |
378 | |
379 typedef typename T1::elem_type eT1; | |
380 typedef typename T2::elem_type eT2; | |
381 | |
382 typedef typename promote_type<eT1,eT2>::result out_eT; | |
383 | |
384 promote_type<eT1,eT2>::check(); | |
385 | |
386 const ProxyCube<T1> A(X.A); | |
387 const ProxyCube<T2> B(X.B); | |
388 | |
389 arma_debug_assert_same_size(A, B, "subtraction"); | |
390 | |
391 const uword n_rows = A.get_n_rows(); | |
392 const uword n_cols = A.get_n_cols(); | |
393 const uword n_slices = A.get_n_slices(); | |
394 | |
395 out.set_size(n_rows, n_cols, n_slices); | |
396 | |
397 out_eT* out_mem = out.memptr(); | |
398 const uword n_elem = out.n_elem; | |
399 | |
400 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor); | |
401 | |
402 if(prefer_at_accessor == false) | |
403 { | |
404 typename ProxyCube<T1>::ea_type AA = A.get_ea(); | |
405 typename ProxyCube<T2>::ea_type BB = B.get_ea(); | |
406 | |
407 for(uword i=0; i<n_elem; ++i) | |
408 { | |
409 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) - upgrade_val<eT1,eT2>::apply(BB[i]); | |
410 } | |
411 } | |
412 else | |
413 { | |
414 uword i = 0; | |
415 | |
416 for(uword slice = 0; slice < n_slices; ++slice) | |
417 for(uword col = 0; col < n_cols; ++col ) | |
418 for(uword row = 0; row < n_rows; ++row ) | |
419 { | |
420 out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col,slice)) - upgrade_val<eT1,eT2>::apply(B.at(row,col,slice)); | |
421 ++i; | |
422 } | |
423 } | |
424 } | |
425 | |
426 | |
427 | |
428 //! element-wise cube division with different element types | |
429 template<typename T1, typename T2> | |
430 inline | |
431 void | |
432 glue_mixed_div::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_div>& X) | |
433 { | |
434 arma_extra_debug_sigprint(); | |
435 | |
436 typedef typename T1::elem_type eT1; | |
437 typedef typename T2::elem_type eT2; | |
438 | |
439 typedef typename promote_type<eT1,eT2>::result out_eT; | |
440 | |
441 promote_type<eT1,eT2>::check(); | |
442 | |
443 const ProxyCube<T1> A(X.A); | |
444 const ProxyCube<T2> B(X.B); | |
445 | |
446 arma_debug_assert_same_size(A, B, "element-wise division"); | |
447 | |
448 const uword n_rows = A.get_n_rows(); | |
449 const uword n_cols = A.get_n_cols(); | |
450 const uword n_slices = A.get_n_slices(); | |
451 | |
452 out.set_size(n_rows, n_cols, n_slices); | |
453 | |
454 out_eT* out_mem = out.memptr(); | |
455 const uword n_elem = out.n_elem; | |
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 typename ProxyCube<T1>::ea_type AA = A.get_ea(); | |
462 typename ProxyCube<T2>::ea_type BB = B.get_ea(); | |
463 | |
464 for(uword i=0; i<n_elem; ++i) | |
465 { | |
466 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) / upgrade_val<eT1,eT2>::apply(BB[i]); | |
467 } | |
468 } | |
469 else | |
470 { | |
471 uword i = 0; | |
472 | |
473 for(uword slice = 0; slice < n_slices; ++slice) | |
474 for(uword col = 0; col < n_cols; ++col ) | |
475 for(uword row = 0; row < n_rows; ++row ) | |
476 { | |
477 out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col,slice)) / upgrade_val<eT1,eT2>::apply(B.at(row,col,slice)); | |
478 ++i; | |
479 } | |
480 } | |
481 } | |
482 | |
483 | |
484 | |
485 //! element-wise cube multiplication with different element types | |
486 template<typename T1, typename T2> | |
487 inline | |
488 void | |
489 glue_mixed_schur::apply(Cube<typename eT_promoter<T1,T2>::eT>& out, const mtGlueCube<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_schur>& X) | |
490 { | |
491 arma_extra_debug_sigprint(); | |
492 | |
493 typedef typename T1::elem_type eT1; | |
494 typedef typename T2::elem_type eT2; | |
495 | |
496 typedef typename promote_type<eT1,eT2>::result out_eT; | |
497 | |
498 promote_type<eT1,eT2>::check(); | |
499 | |
500 const ProxyCube<T1> A(X.A); | |
501 const ProxyCube<T2> B(X.B); | |
502 | |
503 arma_debug_assert_same_size(A, B, "element-wise multiplication"); | |
504 | |
505 const uword n_rows = A.get_n_rows(); | |
506 const uword n_cols = A.get_n_cols(); | |
507 const uword n_slices = A.get_n_slices(); | |
508 | |
509 out.set_size(n_rows, n_cols, n_slices); | |
510 | |
511 out_eT* out_mem = out.memptr(); | |
512 const uword n_elem = out.n_elem; | |
513 | |
514 const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || ProxyCube<T2>::prefer_at_accessor); | |
515 | |
516 if(prefer_at_accessor == false) | |
517 { | |
518 typename ProxyCube<T1>::ea_type AA = A.get_ea(); | |
519 typename ProxyCube<T2>::ea_type BB = B.get_ea(); | |
520 | |
521 for(uword i=0; i<n_elem; ++i) | |
522 { | |
523 out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) * upgrade_val<eT1,eT2>::apply(BB[i]); | |
524 } | |
525 } | |
526 else | |
527 { | |
528 uword i = 0; | |
529 | |
530 for(uword slice = 0; slice < n_slices; ++slice) | |
531 for(uword col = 0; col < n_cols; ++col ) | |
532 for(uword row = 0; row < n_rows; ++row ) | |
533 { | |
534 out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col,slice)) * upgrade_val<eT1,eT2>::apply(B.at(row,col,slice)); | |
535 ++i; | |
536 } | |
537 } | |
538 } | |
539 | |
540 | |
541 | |
542 //! @} |