annotate armadillo-2.4.4/include/armadillo_bits/fn_elem.hpp @ 5:79b343f3e4b8

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