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