comparison armadillo-3.900.4/include/armadillo_bits/fn_elem.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) 2008-2013 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-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 fn_elem
10 //! @{
11
12
13
14 //
15 // find
16
17 template<typename eT, typename T1>
18 inline
19 const mtOp<uword, T1, op_find>
20 find(const Base<eT,T1>& X, const uword k = 0, const char* direction = "first")
21 {
22 arma_extra_debug_sigprint();
23
24 const char sig = direction[0];
25
26 arma_debug_check
27 (
28 (sig != 'f' && sig != 'F' && sig != 'l' && sig != 'L'),
29 "find(): 3rd input argument must be \"first\" or \"last\""
30 );
31
32 const uword type = (sig == 'f' || sig == 'F') ? 0 : 1;
33
34 return mtOp<uword, T1, op_find>(X.get_ref(), k, type);
35 }
36
37
38
39 //
40 // real
41
42 template<typename T1>
43 arma_inline
44 const T1&
45 real(const Base<typename T1::pod_type, T1>& X)
46 {
47 arma_extra_debug_sigprint();
48
49 return X.get_ref();
50 }
51
52
53
54 template<typename T1>
55 arma_inline
56 const T1&
57 real(const BaseCube<typename T1::pod_type, T1>& X)
58 {
59 arma_extra_debug_sigprint();
60
61 return X.get_ref();
62 }
63
64
65
66 template<typename T1>
67 inline
68 const mtOp<typename T1::pod_type, T1, op_real>
69 real(const Base<std::complex<typename T1::pod_type>, T1>& X)
70 {
71 arma_extra_debug_sigprint();
72
73 return mtOp<typename T1::pod_type, T1, op_real>( X.get_ref() );
74 }
75
76
77
78 template<typename T1>
79 inline
80 const mtOpCube<typename T1::pod_type, T1, op_real>
81 real(const BaseCube<std::complex<typename T1::pod_type>, T1>& X)
82 {
83 arma_extra_debug_sigprint();
84
85 return mtOpCube<typename T1::pod_type, T1, op_real>( X.get_ref() );
86 }
87
88
89
90 //
91 // imag
92
93 template<typename T1>
94 inline
95 const Gen< Mat<typename T1::pod_type>, gen_zeros >
96 imag(const Base<typename T1::pod_type,T1>& X)
97 {
98 arma_extra_debug_sigprint();
99
100 const Proxy<T1> A(X.get_ref());
101
102 return Gen< Mat<typename T1::pod_type>, gen_zeros>(A.get_n_rows(), A.get_n_cols());
103 }
104
105
106
107 template<typename T1>
108 inline
109 const GenCube<typename T1::pod_type, gen_zeros>
110 imag(const BaseCube<typename T1::pod_type,T1>& X)
111 {
112 arma_extra_debug_sigprint();
113
114 const ProxyCube<T1> A(X.get_ref());
115
116 return GenCube<typename T1::pod_type, gen_zeros>(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
117 }
118
119
120
121 template<typename T1>
122 inline
123 const mtOp<typename T1::pod_type, T1, op_imag>
124 imag(const Base<std::complex<typename T1::pod_type>, T1>& X)
125 {
126 arma_extra_debug_sigprint();
127
128 return mtOp<typename T1::pod_type, T1, op_imag>( X.get_ref() );
129 }
130
131
132
133 template<typename T1>
134 inline
135 const mtOpCube<typename T1::pod_type, T1, op_imag>
136 imag(const BaseCube<std::complex<typename T1::pod_type>,T1>& X)
137 {
138 arma_extra_debug_sigprint();
139
140 return mtOpCube<typename T1::pod_type, T1, op_imag>( X.get_ref() );
141 }
142
143
144
145 //
146 // log
147
148 template<typename T1>
149 arma_inline
150 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_log> >::result
151 log(const T1& A)
152 {
153 arma_extra_debug_sigprint();
154
155 return eOp<T1, eop_log>(A);
156 }
157
158
159
160 template<typename T1>
161 arma_inline
162 const eOpCube<T1, eop_log>
163 log(const BaseCube<typename T1::elem_type,T1>& A)
164 {
165 arma_extra_debug_sigprint();
166
167 return eOpCube<T1, eop_log>(A.get_ref());
168 }
169
170
171
172 //
173 // log2
174
175 template<typename T1>
176 arma_inline
177 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_log2> >::result
178 log2(const T1& A)
179 {
180 arma_extra_debug_sigprint();
181
182 return eOp<T1, eop_log2>(A);
183 }
184
185
186
187 template<typename T1>
188 arma_inline
189 const eOpCube<T1, eop_log2>
190 log2(const BaseCube<typename T1::elem_type,T1>& A)
191 {
192 arma_extra_debug_sigprint();
193
194 return eOpCube<T1, eop_log2>(A.get_ref());
195 }
196
197
198
199 //
200 // log10
201
202 template<typename T1>
203 arma_inline
204 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_log10> >::result
205 log10(const T1& A)
206 {
207 arma_extra_debug_sigprint();
208
209 return eOp<T1, eop_log10>(A);
210 }
211
212
213
214 template<typename T1>
215 arma_inline
216 const eOpCube<T1, eop_log10>
217 log10(const BaseCube<typename T1::elem_type,T1>& A)
218 {
219 arma_extra_debug_sigprint();
220
221 return eOpCube<T1, eop_log10>(A.get_ref());
222 }
223
224
225
226 //
227 // exp
228
229 template<typename T1>
230 arma_inline
231 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_exp> >::result
232 exp(const T1& A)
233 {
234 arma_extra_debug_sigprint();
235
236 return eOp<T1, eop_exp>(A);
237 }
238
239
240
241 template<typename T1>
242 arma_inline
243 const eOpCube<T1, eop_exp>
244 exp(const BaseCube<typename T1::elem_type,T1>& A)
245 {
246 arma_extra_debug_sigprint();
247
248 return eOpCube<T1, eop_exp>(A.get_ref());
249 }
250
251
252
253 // exp2
254
255 template<typename T1>
256 arma_inline
257 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_exp2> >::result
258 exp2(const T1& A)
259 {
260 arma_extra_debug_sigprint();
261
262 return eOp<T1, eop_exp2>(A);
263 }
264
265
266
267 template<typename T1>
268 arma_inline
269 const eOpCube<T1, eop_exp2>
270 exp2(const BaseCube<typename T1::elem_type,T1>& A)
271 {
272 arma_extra_debug_sigprint();
273
274 return eOpCube<T1, eop_exp2>(A.get_ref());
275 }
276
277
278
279 // exp10
280
281 template<typename T1>
282 arma_inline
283 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_exp10> >::result
284 exp10(const T1& A)
285 {
286 arma_extra_debug_sigprint();
287
288 return eOp<T1, eop_exp10>(A);
289 }
290
291
292
293 template<typename T1>
294 arma_inline
295 const eOpCube<T1, eop_exp10>
296 exp10(const BaseCube<typename T1::elem_type,T1>& A)
297 {
298 arma_extra_debug_sigprint();
299
300 return eOpCube<T1, eop_exp10>(A.get_ref());
301 }
302
303
304
305 //
306 // abs
307
308
309 template<typename T1>
310 arma_inline
311 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_abs> >::result
312 abs(const T1& X, const typename arma_not_cx<typename T1::elem_type>::result* junk = 0)
313 {
314 arma_extra_debug_sigprint();
315
316 arma_ignore(junk);
317
318 return eOp<T1, eop_abs>(X);
319 }
320
321
322
323 template<typename T1>
324 arma_inline
325 const eOpCube<T1, eop_abs>
326 abs(const BaseCube<typename T1::elem_type,T1>& X, const typename arma_not_cx<typename T1::elem_type>::result* junk = 0)
327 {
328 arma_extra_debug_sigprint();
329
330 arma_ignore(junk);
331
332 return eOpCube<T1, eop_abs>(X.get_ref());
333 }
334
335
336
337 template<typename T1>
338 inline
339 const mtOp<typename T1::pod_type, T1, op_abs>
340 abs(const Base<std::complex<typename T1::pod_type>, T1>& X, const typename arma_cx_only<typename T1::elem_type>::result* junk = 0)
341 {
342 arma_extra_debug_sigprint();
343
344 arma_ignore(junk);
345
346 return mtOp<typename T1::pod_type, T1, op_abs>( X.get_ref() );
347 }
348
349
350
351 template<typename T1>
352 inline
353 const mtOpCube<typename T1::pod_type, T1, op_abs>
354 abs(const BaseCube< std::complex<typename T1::pod_type>,T1>& X, const typename arma_cx_only<typename T1::elem_type>::result* junk = 0)
355 {
356 arma_extra_debug_sigprint();
357
358 arma_ignore(junk);
359
360 return mtOpCube<typename T1::pod_type, T1, op_abs>( X.get_ref() );
361 }
362
363
364
365 template<typename T1>
366 arma_inline
367 const SpOp<T1, spop_abs>
368 abs(const SpBase<typename T1::elem_type,T1>& X, const typename arma_not_cx<typename T1::elem_type>::result* junk = 0)
369 {
370 arma_extra_debug_sigprint();
371 arma_ignore(junk);
372
373 return SpOp<T1, spop_abs>(X.get_ref());
374 }
375
376
377
378 template<typename T1>
379 arma_inline
380 const mtSpOp<typename T1::pod_type, T1, spop_cx_abs>
381 abs(const SpBase< std::complex<typename T1::pod_type>, T1>& X, const typename arma_cx_only<typename T1::elem_type>::result* junk = 0)
382 {
383 arma_extra_debug_sigprint();
384 arma_ignore(junk);
385
386 return mtSpOp<typename T1::pod_type, T1, spop_cx_abs>(X.get_ref());
387 }
388
389
390
391 //
392 // square
393
394 template<typename T1>
395 arma_inline
396 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_square> >::result
397 square(const T1& A)
398 {
399 arma_extra_debug_sigprint();
400
401 return eOp<T1, eop_square>(A);
402 }
403
404
405
406 template<typename T1>
407 arma_inline
408 const eOpCube<T1, eop_square>
409 square(const BaseCube<typename T1::elem_type,T1>& A)
410 {
411 arma_extra_debug_sigprint();
412
413 return eOpCube<T1, eop_square>(A.get_ref());
414 }
415
416
417
418 template<typename T1>
419 arma_inline
420 const SpOp<T1, spop_square>
421 square(const SpBase<typename T1::elem_type,T1>& A)
422 {
423 arma_extra_debug_sigprint();
424
425 return SpOp<T1, spop_square>(A.get_ref());
426 }
427
428
429
430 //
431 // sqrt
432
433 template<typename T1>
434 arma_inline
435 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_sqrt> >::result
436 sqrt(const T1& A)
437 {
438 arma_extra_debug_sigprint();
439
440 return eOp<T1, eop_sqrt>(A);
441 }
442
443
444
445 template<typename T1>
446 arma_inline
447 const eOpCube<T1, eop_sqrt>
448 sqrt(const BaseCube<typename T1::elem_type,T1>& A)
449 {
450 arma_extra_debug_sigprint();
451
452 return eOpCube<T1, eop_sqrt>(A.get_ref());
453 }
454
455
456
457 template<typename T1>
458 arma_inline
459 const SpOp<T1, spop_sqrt>
460 sqrt(const SpBase<typename T1::elem_type,T1>& A)
461 {
462 arma_extra_debug_sigprint();
463
464 return SpOp<T1, spop_sqrt>(A.get_ref());
465 }
466
467
468
469 //
470 // conj
471
472 template<typename T1>
473 arma_inline
474 const T1&
475 conj(const Base<typename T1::pod_type,T1>& A)
476 {
477 arma_extra_debug_sigprint();
478
479 return A.get_ref();
480 }
481
482
483
484 template<typename T1>
485 arma_inline
486 const T1&
487 conj(const BaseCube<typename T1::pod_type,T1>& A)
488 {
489 arma_extra_debug_sigprint();
490
491 return A.get_ref();
492 }
493
494
495
496 template<typename T1>
497 arma_inline
498 const eOp<T1, eop_conj>
499 conj(const Base<std::complex<typename T1::pod_type>,T1>& A)
500 {
501 arma_extra_debug_sigprint();
502
503 return eOp<T1, eop_conj>(A.get_ref());
504 }
505
506
507
508 template<typename T1>
509 arma_inline
510 const eOpCube<T1, eop_conj>
511 conj(const BaseCube<std::complex<typename T1::pod_type>,T1>& A)
512 {
513 arma_extra_debug_sigprint();
514
515 return eOpCube<T1, eop_conj>(A.get_ref());
516 }
517
518
519
520 template<typename T1>
521 arma_inline
522 const T1&
523 conj(const eOp<T1, eop_conj>& A)
524 {
525 arma_extra_debug_sigprint();
526
527 return A.m;
528 }
529
530
531
532 template<typename T1>
533 arma_inline
534 const T1&
535 conj(const eOpCube<T1, eop_conj>& A)
536 {
537 arma_extra_debug_sigprint();
538
539 return A.m;
540 }
541
542
543
544 // TODO: this needs a more elaborate template restriction mechanism to work properly,
545 // i.e. an overloaded version of thus function should do nothing if the input type is non-complex
546 //
547 // //! the conjugate of the transpose of a complex matrix is the same as the hermitian transpose
548 // template<typename T1>
549 // arma_inline
550 // const Op<T1, op_htrans>
551 // conj(const Op<T1, op_strans>& A)
552 // {
553 // arma_extra_debug_sigprint();
554 //
555 // return Op<T1, op_htrans>(A.m);
556 // }
557
558
559
560 // pow
561
562 template<typename T1>
563 arma_inline
564 const eOp<T1, eop_pow>
565 pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type exponent)
566 {
567 arma_extra_debug_sigprint();
568
569 return eOp<T1, eop_pow>(A.get_ref(), exponent);
570 }
571
572
573
574 template<typename T1>
575 arma_inline
576 const eOpCube<T1, eop_pow>
577 pow(const BaseCube<typename T1::elem_type,T1>& A, const typename T1::elem_type exponent)
578 {
579 arma_extra_debug_sigprint();
580
581 return eOpCube<T1, eop_pow>(A.get_ref(), exponent);
582 }
583
584
585
586 // pow, specialised handling (non-complex exponent for complex matrices)
587
588 template<typename T1>
589 arma_inline
590 const eOp<T1, eop_pow>
591 pow(const Base<typename T1::elem_type,T1>& A, const typename T1::elem_type::value_type exponent)
592 {
593 arma_extra_debug_sigprint();
594
595 typedef typename T1::elem_type eT;
596
597 return eOp<T1, eop_pow>(A.get_ref(), eT(exponent));
598 }
599
600
601
602 template<typename T1>
603 arma_inline
604 const eOpCube<T1, eop_pow>
605 pow(const BaseCube<typename T1::elem_type,T1>& A, const typename T1::elem_type::value_type exponent)
606 {
607 arma_extra_debug_sigprint();
608
609 typedef typename T1::elem_type eT;
610
611 return eOpCube<T1, eop_pow>(A.get_ref(), eT(exponent));
612 }
613
614
615
616 //
617 // floor
618
619 template<typename T1>
620 arma_inline
621 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_floor> >::result
622 floor(const T1& A)
623 {
624 arma_extra_debug_sigprint();
625
626 return eOp<T1, eop_floor>(A);
627 }
628
629
630
631 template<typename T1>
632 arma_inline
633 const eOpCube<T1, eop_floor>
634 floor(const BaseCube<typename T1::elem_type,T1>& A)
635 {
636 arma_extra_debug_sigprint();
637
638 return eOpCube<T1, eop_floor>(A.get_ref());
639 }
640
641
642
643 //
644 // ceil
645
646 template<typename T1>
647 arma_inline
648 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_ceil> >::result
649 ceil(const T1& A)
650 {
651 arma_extra_debug_sigprint();
652
653 return eOp<T1, eop_ceil>(A);
654 }
655
656
657
658 template<typename T1>
659 arma_inline
660 const eOpCube<T1, eop_ceil>
661 ceil(const BaseCube<typename T1::elem_type,T1>& A)
662 {
663 arma_extra_debug_sigprint();
664
665 return eOpCube<T1, eop_ceil>(A.get_ref());
666 }
667
668
669
670 //
671 // round
672
673 template<typename T1>
674 arma_inline
675 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_round> >::result
676 round(const T1& A)
677 {
678 arma_extra_debug_sigprint();
679
680 return eOp<T1, eop_round>(A);
681 }
682
683
684
685 template<typename T1>
686 arma_inline
687 const eOpCube<T1, eop_round>
688 round(const BaseCube<typename T1::elem_type,T1>& A)
689 {
690 arma_extra_debug_sigprint();
691
692 return eOpCube<T1, eop_round>(A.get_ref());
693 }
694
695
696
697 //! @}