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