annotate armadillo-2.4.4/include/armadillo_bits/traits.hpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
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 traits
max@0 15 //! @{
max@0 16
max@0 17
max@0 18 template<typename T1>
max@0 19 struct get_pod_type
max@0 20 { typedef T1 result; };
max@0 21
max@0 22 template<typename T2>
max@0 23 struct get_pod_type< std::complex<T2> >
max@0 24 { typedef T2 result; };
max@0 25
max@0 26
max@0 27
max@0 28 template<typename T>
max@0 29 struct is_Mat_only
max@0 30 { static const bool value = false; };
max@0 31
max@0 32 template<typename eT>
max@0 33 struct is_Mat_only< Mat<eT> >
max@0 34 { static const bool value = true; };
max@0 35
max@0 36
max@0 37
max@0 38 template<typename T>
max@0 39 struct is_Mat
max@0 40 { static const bool value = false; };
max@0 41
max@0 42 template<typename eT>
max@0 43 struct is_Mat< Mat<eT> >
max@0 44 { static const bool value = true; };
max@0 45
max@0 46 template<typename eT>
max@0 47 struct is_Mat< Row<eT> >
max@0 48 { static const bool value = true; };
max@0 49
max@0 50 template<typename eT>
max@0 51 struct is_Mat< Col<eT> >
max@0 52 { static const bool value = true; };
max@0 53
max@0 54
max@0 55
max@0 56 template<typename T>
max@0 57 struct is_Row
max@0 58 { static const bool value = false; };
max@0 59
max@0 60 template<typename eT>
max@0 61 struct is_Row< Row<eT> >
max@0 62 { static const bool value = true; };
max@0 63
max@0 64
max@0 65
max@0 66 template<typename T>
max@0 67 struct is_Col
max@0 68 { static const bool value = false; };
max@0 69
max@0 70 template<typename eT>
max@0 71 struct is_Col< Col<eT> >
max@0 72 { static const bool value = true; };
max@0 73
max@0 74
max@0 75
max@0 76
max@0 77
max@0 78
max@0 79 template<typename T>
max@0 80 struct is_subview
max@0 81 { static const bool value = false; };
max@0 82
max@0 83 template<typename eT>
max@0 84 struct is_subview< subview<eT> >
max@0 85 { static const bool value = true; };
max@0 86
max@0 87
max@0 88 template<typename T>
max@0 89 struct is_diagview
max@0 90 { static const bool value = false; };
max@0 91
max@0 92 template<typename eT>
max@0 93 struct is_diagview< diagview<eT> >
max@0 94 { static const bool value = true; };
max@0 95
max@0 96
max@0 97 //
max@0 98 //
max@0 99 //
max@0 100
max@0 101
max@0 102
max@0 103 template<typename T>
max@0 104 struct is_Cube
max@0 105 { static const bool value = false; };
max@0 106
max@0 107 template<typename eT>
max@0 108 struct is_Cube< Cube<eT> >
max@0 109 { static const bool value = true; };
max@0 110
max@0 111 template<typename T>
max@0 112 struct is_subview_cube
max@0 113 { static const bool value = false; };
max@0 114
max@0 115 template<typename eT>
max@0 116 struct is_subview_cube< subview_cube<eT> >
max@0 117 { static const bool value = true; };
max@0 118
max@0 119
max@0 120
max@0 121 //
max@0 122 //
max@0 123 //
max@0 124
max@0 125
max@0 126 template<typename T>
max@0 127 struct is_Gen
max@0 128 { static const bool value = false; };
max@0 129
max@0 130 template<typename eT, typename gen_type>
max@0 131 struct is_Gen< Gen<eT,gen_type> >
max@0 132 { static const bool value = true; };
max@0 133
max@0 134
max@0 135 template<typename T>
max@0 136 struct is_Op
max@0 137 { static const bool value = false; };
max@0 138
max@0 139 template<typename T1, typename op_type>
max@0 140 struct is_Op< Op<T1,op_type> >
max@0 141 { static const bool value = true; };
max@0 142
max@0 143
max@0 144 template<typename T>
max@0 145 struct is_eOp
max@0 146 { static const bool value = false; };
max@0 147
max@0 148 template<typename T1, typename eop_type>
max@0 149 struct is_eOp< eOp<T1,eop_type> >
max@0 150 { static const bool value = true; };
max@0 151
max@0 152
max@0 153 template<typename T>
max@0 154 struct is_mtOp
max@0 155 { static const bool value = false; };
max@0 156
max@0 157 template<typename eT, typename T1, typename op_type>
max@0 158 struct is_mtOp< mtOp<eT, T1, op_type> >
max@0 159 { static const bool value = true; };
max@0 160
max@0 161
max@0 162 template<typename T>
max@0 163 struct is_Glue
max@0 164 { static const bool value = false; };
max@0 165
max@0 166 template<typename T1, typename T2, typename glue_type>
max@0 167 struct is_Glue< Glue<T1,T2,glue_type> >
max@0 168 { static const bool value = true; };
max@0 169
max@0 170
max@0 171 template<typename T>
max@0 172 struct is_eGlue
max@0 173 { static const bool value = false; };
max@0 174
max@0 175 template<typename T1, typename T2, typename eglue_type>
max@0 176 struct is_eGlue< eGlue<T1,T2,eglue_type> >
max@0 177 { static const bool value = true; };
max@0 178
max@0 179
max@0 180 template<typename T>
max@0 181 struct is_mtGlue
max@0 182 { static const bool value = false; };
max@0 183
max@0 184 template<typename eT, typename T1, typename T2, typename glue_type>
max@0 185 struct is_mtGlue< mtGlue<eT, T1, T2, glue_type> >
max@0 186 { static const bool value = true; };
max@0 187
max@0 188
max@0 189 //
max@0 190 //
max@0 191
max@0 192
max@0 193 template<typename T>
max@0 194 struct is_glue_times
max@0 195 { static const bool value = false; };
max@0 196
max@0 197 template<typename T1, typename T2>
max@0 198 struct is_glue_times< Glue<T1,T2,glue_times> >
max@0 199 { static const bool value = true; };
max@0 200
max@0 201
max@0 202 template<typename T>
max@0 203 struct is_glue_times_diag
max@0 204 { static const bool value = false; };
max@0 205
max@0 206 template<typename T1, typename T2>
max@0 207 struct is_glue_times_diag< Glue<T1,T2,glue_times_diag> >
max@0 208 { static const bool value = true; };
max@0 209
max@0 210
max@0 211 template<typename T>
max@0 212 struct is_op_diagmat
max@0 213 { static const bool value = false; };
max@0 214
max@0 215 template<typename T1>
max@0 216 struct is_op_diagmat< Op<T1,op_diagmat> >
max@0 217 { static const bool value = true; };
max@0 218
max@0 219
max@0 220 //
max@0 221 //
max@0 222
max@0 223
max@0 224 template<typename T>
max@0 225 struct is_GenCube
max@0 226 { static const bool value = false; };
max@0 227
max@0 228 template<typename eT, typename gen_type>
max@0 229 struct is_GenCube< GenCube<eT,gen_type> >
max@0 230 { static const bool value = true; };
max@0 231
max@0 232
max@0 233 template<typename T>
max@0 234 struct is_OpCube
max@0 235 { static const bool value = false; };
max@0 236
max@0 237 template<typename T1, typename op_type>
max@0 238 struct is_OpCube< OpCube<T1,op_type> >
max@0 239 { static const bool value = true; };
max@0 240
max@0 241
max@0 242 template<typename T>
max@0 243 struct is_eOpCube
max@0 244 { static const bool value = false; };
max@0 245
max@0 246 template<typename T1, typename eop_type>
max@0 247 struct is_eOpCube< eOpCube<T1,eop_type> >
max@0 248 { static const bool value = true; };
max@0 249
max@0 250
max@0 251 template<typename T>
max@0 252 struct is_mtOpCube
max@0 253 { static const bool value = false; };
max@0 254
max@0 255 template<typename eT, typename T1, typename op_type>
max@0 256 struct is_mtOpCube< mtOpCube<eT, T1, op_type> >
max@0 257 { static const bool value = true; };
max@0 258
max@0 259
max@0 260 template<typename T>
max@0 261 struct is_GlueCube
max@0 262 { static const bool value = false; };
max@0 263
max@0 264 template<typename T1, typename T2, typename glue_type>
max@0 265 struct is_GlueCube< GlueCube<T1,T2,glue_type> >
max@0 266 { static const bool value = true; };
max@0 267
max@0 268
max@0 269 template<typename T>
max@0 270 struct is_eGlueCube
max@0 271 { static const bool value = false; };
max@0 272
max@0 273 template<typename T1, typename T2, typename eglue_type>
max@0 274 struct is_eGlueCube< eGlueCube<T1,T2,eglue_type> >
max@0 275 { static const bool value = true; };
max@0 276
max@0 277
max@0 278 template<typename T>
max@0 279 struct is_mtGlueCube
max@0 280 { static const bool value = false; };
max@0 281
max@0 282 template<typename eT, typename T1, typename T2, typename glue_type>
max@0 283 struct is_mtGlueCube< mtGlueCube<eT, T1, T2, glue_type> >
max@0 284 { static const bool value = true; };
max@0 285
max@0 286
max@0 287 //
max@0 288 //
max@0 289 //
max@0 290
max@0 291
max@0 292 template<typename T>
max@0 293 struct is_op_rel
max@0 294 { static const bool value = false; };
max@0 295
max@0 296 template<typename out_eT, typename T1>
max@0 297 struct is_op_rel< mtOp<out_eT, T1, op_rel_lt_pre> >
max@0 298 { static const bool value = true; };
max@0 299
max@0 300 template<typename out_eT, typename T1>
max@0 301 struct is_op_rel< mtOp<out_eT, T1, op_rel_lt_post> >
max@0 302 { static const bool value = true; };
max@0 303
max@0 304 template<typename out_eT, typename T1>
max@0 305 struct is_op_rel< mtOp<out_eT, T1, op_rel_gt_pre> >
max@0 306 { static const bool value = true; };
max@0 307
max@0 308 template<typename out_eT, typename T1>
max@0 309 struct is_op_rel< mtOp<out_eT, T1, op_rel_gt_post> >
max@0 310 { static const bool value = true; };
max@0 311
max@0 312 template<typename out_eT, typename T1>
max@0 313 struct is_op_rel< mtOp<out_eT, T1, op_rel_lteq_pre> >
max@0 314 { static const bool value = true; };
max@0 315
max@0 316 template<typename out_eT, typename T1>
max@0 317 struct is_op_rel< mtOp<out_eT, T1, op_rel_lteq_post> >
max@0 318 { static const bool value = true; };
max@0 319
max@0 320 template<typename out_eT, typename T1>
max@0 321 struct is_op_rel< mtOp<out_eT, T1, op_rel_gteq_pre> >
max@0 322 { static const bool value = true; };
max@0 323
max@0 324 template<typename out_eT, typename T1>
max@0 325 struct is_op_rel< mtOp<out_eT, T1, op_rel_gteq_post> >
max@0 326 { static const bool value = true; };
max@0 327
max@0 328 template<typename out_eT, typename T1>
max@0 329 struct is_op_rel< mtOp<out_eT, T1, op_rel_eq> >
max@0 330 { static const bool value = true; };
max@0 331
max@0 332 template<typename out_eT, typename T1>
max@0 333 struct is_op_rel< mtOp<out_eT, T1, op_rel_noteq> >
max@0 334 { static const bool value = true; };
max@0 335
max@0 336
max@0 337
max@0 338 //
max@0 339 //
max@0 340 //
max@0 341
max@0 342
max@0 343
max@0 344 template<typename T1>
max@0 345 struct is_arma_type
max@0 346 {
max@0 347 static const bool value
max@0 348 = is_Mat<T1>::value
max@0 349 || is_Gen<T1>::value
max@0 350 || is_Op<T1>::value
max@0 351 || is_eOp<T1>::value
max@0 352 || is_mtOp<T1>::value
max@0 353 || is_Glue<T1>::value
max@0 354 || is_eGlue<T1>::value
max@0 355 || is_mtGlue<T1>::value
max@0 356 || is_subview<T1>::value
max@0 357 || is_diagview<T1>::value
max@0 358 ;
max@0 359 };
max@0 360
max@0 361
max@0 362
max@0 363 template<typename T1>
max@0 364 struct is_arma_cube_type
max@0 365 {
max@0 366 static const bool value
max@0 367 = is_Cube<T1>::value
max@0 368 || is_GenCube<T1>::value
max@0 369 || is_OpCube<T1>::value
max@0 370 || is_eOpCube<T1>::value
max@0 371 || is_mtOpCube<T1>::value
max@0 372 || is_GlueCube<T1>::value
max@0 373 || is_eGlueCube<T1>::value
max@0 374 || is_mtGlueCube<T1>::value
max@0 375 || is_subview_cube<T1>::value
max@0 376 ;
max@0 377 };
max@0 378
max@0 379
max@0 380
max@0 381 //
max@0 382 //
max@0 383 //
max@0 384
max@0 385
max@0 386 template<typename T1, typename T2>
max@0 387 struct is_same_type
max@0 388 { static const bool value = false; };
max@0 389
max@0 390
max@0 391 template<typename T1>
max@0 392 struct is_same_type<T1,T1>
max@0 393 { static const bool value = true; };
max@0 394
max@0 395
max@0 396
max@0 397 //
max@0 398 //
max@0 399 //
max@0 400
max@0 401
max@0 402 template<typename T1>
max@0 403 struct is_u8
max@0 404 { static const bool value = false; };
max@0 405
max@0 406 template<>
max@0 407 struct is_u8<u8>
max@0 408 { static const bool value = true; };
max@0 409
max@0 410
max@0 411
max@0 412 template<typename T1>
max@0 413 struct is_s8
max@0 414 { static const bool value = false; };
max@0 415
max@0 416 template<>
max@0 417 struct is_s8<s8>
max@0 418 { static const bool value = true; };
max@0 419
max@0 420
max@0 421
max@0 422 template<typename T1>
max@0 423 struct is_u16
max@0 424 { static const bool value = false; };
max@0 425
max@0 426 template<>
max@0 427 struct is_u16<u16>
max@0 428 { static const bool value = true; };
max@0 429
max@0 430
max@0 431
max@0 432 template<typename T1>
max@0 433 struct is_s16
max@0 434 { static const bool value = false; };
max@0 435
max@0 436 template<>
max@0 437 struct is_s16<s16>
max@0 438 { static const bool value = true; };
max@0 439
max@0 440
max@0 441
max@0 442 template<typename T1>
max@0 443 struct is_u32
max@0 444 { static const bool value = false; };
max@0 445
max@0 446 template<>
max@0 447 struct is_u32<u32>
max@0 448 { static const bool value = true; };
max@0 449
max@0 450
max@0 451
max@0 452 template<typename T1>
max@0 453 struct is_s32
max@0 454 { static const bool value = false; };
max@0 455
max@0 456 template<>
max@0 457 struct is_s32<s32>
max@0 458 { static const bool value = true; };
max@0 459
max@0 460
max@0 461
max@0 462 #if defined(ARMA_64BIT_WORD)
max@0 463 template<typename T1>
max@0 464 struct is_u64
max@0 465 { static const bool value = false; };
max@0 466
max@0 467 template<>
max@0 468 struct is_u64<u64>
max@0 469 { static const bool value = true; };
max@0 470
max@0 471
max@0 472 template<typename T1>
max@0 473 struct is_s64
max@0 474 { static const bool value = false; };
max@0 475
max@0 476 template<>
max@0 477 struct is_s64<s64>
max@0 478 { static const bool value = true; };
max@0 479 #endif
max@0 480
max@0 481
max@0 482
max@0 483 template<typename T1>
max@0 484 struct is_uword
max@0 485 { static const bool value = false; };
max@0 486
max@0 487 template<>
max@0 488 struct is_uword<uword>
max@0 489 { static const bool value = true; };
max@0 490
max@0 491
max@0 492
max@0 493 template<typename T1>
max@0 494 struct is_sword
max@0 495 { static const bool value = false; };
max@0 496
max@0 497 template<>
max@0 498 struct is_sword<sword>
max@0 499 { static const bool value = true; };
max@0 500
max@0 501
max@0 502
max@0 503 template<typename T1>
max@0 504 struct is_float
max@0 505 { static const bool value = false; };
max@0 506
max@0 507 template<>
max@0 508 struct is_float<float>
max@0 509 { static const bool value = true; };
max@0 510
max@0 511
max@0 512
max@0 513 template<typename T1>
max@0 514 struct is_double
max@0 515 { static const bool value = false; };
max@0 516
max@0 517 template<>
max@0 518 struct is_double<double>
max@0 519 { static const bool value = true; };
max@0 520
max@0 521
max@0 522
max@0 523 template<typename T1>
max@0 524 struct is_complex
max@0 525 { static const bool value = false; };
max@0 526
max@0 527 // template<>
max@0 528 template<typename eT>
max@0 529 struct is_complex< std::complex<eT> >
max@0 530 { static const bool value = true; };
max@0 531
max@0 532
max@0 533
max@0 534 template<typename T1>
max@0 535 struct is_complex_float
max@0 536 { static const bool value = false; };
max@0 537
max@0 538 template<>
max@0 539 struct is_complex_float< std::complex<float> >
max@0 540 { static const bool value = true; };
max@0 541
max@0 542
max@0 543
max@0 544 template<typename T1>
max@0 545 struct is_complex_double
max@0 546 { static const bool value = false; };
max@0 547
max@0 548 template<>
max@0 549 struct is_complex_double< std::complex<double> >
max@0 550 { static const bool value = true; };
max@0 551
max@0 552
max@0 553
max@0 554
max@0 555 //! check for a weird implementation of the std::complex class
max@0 556 template<typename T1>
max@0 557 struct is_supported_complex
max@0 558 { static const bool value = false; };
max@0 559
max@0 560 //template<>
max@0 561 template<typename eT>
max@0 562 struct is_supported_complex< std::complex<eT> >
max@0 563 { static const bool value = ( sizeof(std::complex<eT>) == 2*sizeof(eT) ); };
max@0 564
max@0 565
max@0 566
max@0 567 template<typename T1>
max@0 568 struct is_supported_complex_float
max@0 569 { static const bool value = false; };
max@0 570
max@0 571 template<>
max@0 572 struct is_supported_complex_float< std::complex<float> >
max@0 573 { static const bool value = ( sizeof(std::complex<float>) == 2*sizeof(float) ); };
max@0 574
max@0 575
max@0 576
max@0 577 template<typename T1>
max@0 578 struct is_supported_complex_double
max@0 579 { static const bool value = false; };
max@0 580
max@0 581 template<>
max@0 582 struct is_supported_complex_double< std::complex<double> >
max@0 583 { static const bool value = ( sizeof(std::complex<double>) == 2*sizeof(double) ); };
max@0 584
max@0 585
max@0 586
max@0 587 template<typename T1>
max@0 588 struct is_supported_elem_type
max@0 589 {
max@0 590 static const bool value = \
max@0 591 is_u8<T1>::value ||
max@0 592 is_s8<T1>::value ||
max@0 593 is_u16<T1>::value ||
max@0 594 is_s16<T1>::value ||
max@0 595 is_u32<T1>::value ||
max@0 596 is_s32<T1>::value ||
max@0 597 #if defined(ARMA_64BIT_WORD)
max@0 598 is_u64<T1>::value ||
max@0 599 is_s64<T1>::value ||
max@0 600 #endif
max@0 601 is_float<T1>::value ||
max@0 602 is_double<T1>::value ||
max@0 603 is_supported_complex_float<T1>::value ||
max@0 604 is_supported_complex_double<T1>::value;
max@0 605 };
max@0 606
max@0 607
max@0 608
max@0 609 template<typename T1>
max@0 610 struct is_supported_blas_type
max@0 611 {
max@0 612 static const bool value = \
max@0 613 is_float<T1>::value ||
max@0 614 is_double<T1>::value ||
max@0 615 is_supported_complex_float<T1>::value ||
max@0 616 is_supported_complex_double<T1>::value;
max@0 617 };
max@0 618
max@0 619
max@0 620
max@0 621 template<typename T>
max@0 622 struct is_signed
max@0 623 {
max@0 624 static const bool value = true;
max@0 625 };
max@0 626
max@0 627
max@0 628 template<> struct is_signed<u8> { static const bool value = false; };
max@0 629 template<> struct is_signed<u16> { static const bool value = false; };
max@0 630 template<> struct is_signed<u32> { static const bool value = false; };
max@0 631 #if defined(ARMA_64BIT_WORD)
max@0 632 template<> struct is_signed<u64> { static const bool value = false; };
max@0 633 #endif
max@0 634
max@0 635
max@0 636 template<typename T>
max@0 637 struct is_non_integral
max@0 638 {
max@0 639 static const bool value = false;
max@0 640 };
max@0 641
max@0 642
max@0 643 template<> struct is_non_integral< float > { static const bool value = true; };
max@0 644 template<> struct is_non_integral< double > { static const bool value = true; };
max@0 645 template<> struct is_non_integral< std::complex<float> > { static const bool value = true; };
max@0 646 template<> struct is_non_integral< std::complex<double> > { static const bool value = true; };
max@0 647
max@0 648
max@0 649
max@0 650
max@0 651 //
max@0 652
max@0 653 class arma_junk_class;
max@0 654
max@0 655 template<typename T1, typename T2>
max@0 656 struct force_different_type
max@0 657 {
max@0 658 typedef T1 T1_result;
max@0 659 typedef T2 T2_result;
max@0 660 };
max@0 661
max@0 662
max@0 663 template<typename T1>
max@0 664 struct force_different_type<T1,T1>
max@0 665 {
max@0 666 typedef T1 T1_result;
max@0 667 typedef arma_junk_class T2_result;
max@0 668 };
max@0 669
max@0 670
max@0 671
max@0 672 //! @}