OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
IpplTypeComputations.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 
13 //
14 // FILE NAME
15 // IpplTypeComputations.h
16 //
17 // CREATED
18 // July 11, 1997
19 //
20 // DESCRIPTION
21 // PETE: Portable Expression Template Engine.
22 //
23 // This header file contains IPPL-specific type computations.
24 //
26 
27 #ifndef IPPL_TYPE_COMPUTATIONS_H
28 #define IPPL_TYPE_COMPUTATIONS_H
29 
30 
31 // include files
32 #include "PETE/TypeComputations.h"
33 #include <complex>
34 
35 
36 // forward declarations
37 template<class T, unsigned D> class Vektor;
38 template<class T, unsigned D> class Tenzor;
39 template<class T, unsigned D> class AntiSymTenzor;
40 template<class T, unsigned D> class SymTenzor;
41 template <class T> class RNGLattice;
42 class RNGXDiv;
43 
44 
45 // definition of global sign function
46 template<class T>
47 inline int sign(T a) { return ((a > 0) ? 1 : (a == 0 ? 0 : -1)); }
48 
49 
51 //
52 // PETE_Type2Index FOR USER TYPES
53 //
55 
56 // Complex numbers.
57 
58 template<> struct PETE_Type2Index<std::complex<double>> {
59  enum { val = 8 };
60 };
61 
62 // Return types for scalar ops with RNGs.
63 
64 #define _SCALAR_RNG_OP_RETURNS_(GEN,SCA,OP) \
65 template <> \
66 struct PETEBinaryReturn<GEN,SCA,OP> { \
67  typedef PETEBinaryReturn<double,SCA,OP>::type type; \
68 }; \
69 template <> \
70 struct PETEBinaryReturn<SCA,GEN,OP> { \
71  typedef PETEBinaryReturn<SCA,double,OP>::type type; \
72 };
73 
74 #define _SCALAR_RNG_RETURNS_(GEN,SCA) \
75 _SCALAR_RNG_OP_RETURNS_(GEN,SCA,OpAdd) \
76 _SCALAR_RNG_OP_RETURNS_(GEN,SCA,OpSubtract) \
77 _SCALAR_RNG_OP_RETURNS_(GEN,SCA,OpMultipply) \
78 _SCALAR_RNG_OP_RETURNS_(GEN,SCA,OpDivide)
79 
80 #define _PETE_RNG_RETURNS_(GEN) \
81  \
82 template <> struct PETE_Type2Index< GEN > { \
83  enum { val = PETE_Type2Index<double>::val }; \
84 }; \
85  \
86 _SCALAR_RNG_RETURNS_(GEN,short) \
87 _SCALAR_RNG_RETURNS_(GEN,int) \
88 _SCALAR_RNG_RETURNS_(GEN,long) \
89 _SCALAR_RNG_RETURNS_(GEN,float) \
90 _SCALAR_RNG_RETURNS_(GEN,double) \
91 _SCALAR_RNG_RETURNS_(GEN,std::complex<double>)
92 
96 
97 // Life is way easier with this feature.
98 
99 template<class T, unsigned Dim>
101  enum { val = 20 + 10 * Dim + PETE_Type2Index<T>::val };
102 };
103 
104 template<class T, unsigned Dim>
106  enum { val = 120 + 10 * Dim + PETE_Type2Index<T>::val };
107 };
108 
109 template<class T, unsigned Dim>
111  enum { val = 220 + 10 * Dim + PETE_Type2Index<T>::val };
112 };
113 
114 template<class T, unsigned Dim>
116  enum { val = 320 + 10 * Dim + PETE_Type2Index<T>::val };
117 };
118 
119 
121 //
122 // SPECIAL CASES FOR UNARY FUNCTIONS
123 //
125 
126 // Abs function: special return for complex numbers.
127 
128 struct FnAbs {
130 };
131 
132 template<> struct PETEUnaryReturn<std::complex<double>, FnAbs> {
133  typedef double type;
134 };
135 
136 // The conj, norm, arg, real, and imag functions for complex numbers.
137 
138 struct FnConj {
140 };
141 
142 struct FnNorm {
143  typedef double type;
145 };
146 
147 template<> struct PETEUnaryReturn<std::complex<double>, FnNorm> {
148  typedef double type;
149 };
150 
151 struct FnArg {
152  typedef double type;
154 };
155 
156 template<> struct PETEUnaryReturn<std::complex<double>, FnArg> {
157  typedef double type;
158 };
159 
160 struct FnReal {
161  typedef double type;
163 };
164 
165 template<> struct PETEUnaryReturn<std::complex<double>, FnReal> {
166  typedef double type;
167 };
168 
169 struct FnImag {
170  typedef double type;
172 };
173 
174 template<> struct PETEUnaryReturn<std::complex<double>, FnImag> {
175  typedef double type;
176 };
177 
178 // The sign function.
179 
180 struct FnSign {
181  typedef int type;
183 };
184 
185 template<class TP>
186 struct OpParens
187 {
189  TP Arg;
190  OpParens() { Arg = TP(); }
191  OpParens(const TP& a) : Arg(a) {}
192 };
193 
194 // Tensor functions: trace, det (determinant), and transpose
195 
196 struct FnTrace {
198 };
199 
200 struct FnDet {
202 };
203 
204 struct FnTranspose {
206 };
207 
208 struct FnCofactors {
210 };
211 
212 // Life is pretty simple if we have partial specialization.
213 
214 template<class T, unsigned Dim>
216  typedef T type;
217 };
218 
219 template<class T, unsigned Dim>
221  typedef T type;
222 };
223 
224 template<class T, unsigned Dim>
226  typedef T type;
227 };
228 
229 template<class T, unsigned Dim>
231  typedef T type;
232 };
233 
234 template<class T, unsigned Dim>
236  typedef T type;
237 };
238 
239 template<class T, unsigned Dim>
241  typedef T type;
242 };
243 
244 template<class T, unsigned Dim>
247 };
248 
249 template<class T, unsigned Dim>
252 };
253 
254 template<class T, unsigned Dim>
257 };
258 
259 template<class T, unsigned Dim>
262 };
263 
264 template<class T, unsigned Dim>
267 };
268 
269 template<class T, unsigned Dim>
272 };
273 
274 
276 //
277 // SPECIAL CASES FOR BINARY FUNCTIONS
278 //
280 
281 // Min and Max functions.
282 
283 struct FnMin {
285 };
286 
287 struct FnMax {
289 };
290 
291 // Dot, dot-dot, and outerProduct functions.
292 
293 struct FnDot {
295 };
296 
297 struct FnDotDot {
299 };
300 
303 };
304 
305 // Cross-product:
306 
307 struct FnCross {
309 };
310 
311 // Involving Vektors:
312 
313 template<class T1, class T2, unsigned Dim>
316 };
317 
318 template<class T1, class T2, unsigned Dim>
321 };
322 
323 template<class T1, class T2, unsigned Dim>
326 };
327 
328 // Involving Tenzors, but no combination with SymTenzors or AntiSymTenzors:
329 
330 template<class T1, class T2, unsigned Dim>
333 };
334 
335 template<class T1, class T2, unsigned Dim>
338 };
339 
340 template<class T1, class T2, unsigned Dim>
343 };
344 
345 template<class T1, class T2, unsigned Dim>
348 };
349 
350 // Involving SymTenzors, possibly combined with Tenzors:
351 
352 template<class T1, class T2, unsigned Dim>
356 };
357 
358 template<class T1, class T2, unsigned Dim>
361 };
362 
363 template<class T1, class T2, unsigned Dim>
366 };
367 
368 template<class T1, class T2, unsigned Dim>
371 };
372 
373 template<class T1, class T2, unsigned Dim>
376 };
377 
378 template<class T1, class T2, unsigned Dim>
381 };
382 
383 template<class T1, class T2, unsigned Dim>
386 };
387 
388 template<class T1, class T2, unsigned Dim>
391 };
392 
393 template<class T1, class T2, unsigned Dim>
396 };
397 
398 template<class T1, class T2, unsigned Dim>
401 };
402 
403 template<class T1, class T2, unsigned Dim>
406 };
407 
408 template<class T1, class T2, unsigned Dim>
411 };
412 
413 template<class T1, class T2, unsigned Dim>
416 };
417 
418 // Involving AntiSymTenzors, possibly combined with Tenzors or SymTenzors:
419 
420 template<class T1, class T2, unsigned Dim>
424 };
425 
426 template<class T1, class T2, unsigned Dim>
428 {
430 };
431 
432 template<class T1, class T2, unsigned Dim>
435 };
436 
437 template<class T1, class T2, unsigned Dim>
440 };
441 
442 template<class T1, class T2, unsigned Dim>
445 };
446 
447 template<class T1, class T2, unsigned Dim>
450 };
451 
452 template<class T1, class T2, unsigned Dim>
455 };
456 
457 template<class T1, class T2, unsigned Dim>
460 };
461 
462 template<class T1, class T2, unsigned Dim>
465 };
466 
467 template<class T1, class T2, unsigned Dim>
470 };
471 
472 template<class T1, class T2, unsigned Dim>
475 };
476 
477 template<class T1, class T2, unsigned Dim>
480 };
481 
482 template<class T1, class T2, unsigned Dim>
485 };
486 
487 template<class T1, class T2, unsigned Dim>
490 };
491 
492 template<class T1, class T2, unsigned Dim>
495 };
496 
497 template<class T1, class T2, unsigned Dim>
500 };
501 
502 template<class T1, class T2, unsigned Dim>
505 };
506 
507 template<class T1, class T2, unsigned Dim>
510 };
511 
512 template<class T1, class T2, unsigned Dim>
515 };
516 
517 template<class T1, class T2, unsigned Dim>
520 };
521 
522 template<class T1, class T2, unsigned Dim>
525 };
526 
527 template<class T1, class T2, unsigned Dim>
530 };
531 
532 // Need to specify scalar operations directly.
533 
534 #define _SCALAR_VST_RETURNS_(Sca) \
535 template<class T1, unsigned Dim> \
536 struct PETEBinaryReturn<Vektor<T1,Dim>,Sca,OpMultipply> { \
537  typedef Vektor<typename PETEBinaryReturn<T1,Sca,OpMultipply>::type,Dim> \
538  type; \
539 }; \
540 template<class T2, unsigned Dim> \
541 struct PETEBinaryReturn<Sca,Vektor<T2,Dim>,OpMultipply> { \
542  typedef Vektor<typename PETEBinaryReturn<Sca,T2,OpMultipply>::type,Dim> \
543  type; \
544 }; \
545 template<class T1, unsigned Dim> \
546 struct PETEBinaryReturn<Vektor<T1,Dim>,Sca,OpDivide> { \
547  typedef Vektor<typename PETEBinaryReturn<T1,Sca,OpDivide>::type,Dim> \
548  type; \
549 }; \
550 template<class T1, unsigned Dim> \
551 struct PETEBinaryReturn<Tenzor<T1,Dim>,Sca,OpMultipply> { \
552  typedef Tenzor<typename PETEBinaryReturn<T1,Sca,OpMultipply>::type,Dim> \
553  type; \
554 }; \
555 template<class T2, unsigned Dim> \
556 struct PETEBinaryReturn<Sca,Tenzor<T2,Dim>,OpMultipply> { \
557  typedef Tenzor<typename PETEBinaryReturn<Sca,T2,OpMultipply>::type,Dim> \
558  type; \
559 }; \
560 template<class T1, unsigned Dim> \
561 struct PETEBinaryReturn<Tenzor<T1,Dim>,Sca,OpDivide> { \
562  typedef Tenzor<typename PETEBinaryReturn<T1,Sca,OpDivide>::type,Dim> \
563  type; \
564 }; \
565 template<class T1, unsigned Dim> \
566 struct PETEBinaryReturn<SymTenzor<T1,Dim>,Sca,OpMultipply> { \
567  typedef SymTenzor<typename PETEBinaryReturn<T1,Sca,OpMultipply>::type,Dim> \
568  type; \
569 }; \
570 template<class T2, unsigned Dim> \
571 struct PETEBinaryReturn<Sca,SymTenzor<T2,Dim>,OpMultipply> { \
572  typedef SymTenzor<typename PETEBinaryReturn<Sca,T2,OpMultipply>::type,Dim> \
573  type; \
574 }; \
575 template<class T1, unsigned Dim> \
576 struct PETEBinaryReturn<SymTenzor<T1,Dim>,Sca,OpDivide> { \
577  typedef SymTenzor<typename PETEBinaryReturn<T1,Sca,OpDivide>::type,Dim> \
578  type; \
579 }; \
580 template<class T1, unsigned Dim> \
581 struct PETEBinaryReturn<AntiSymTenzor<T1,Dim>,Sca,OpMultipply> { \
582  typedef \
583  AntiSymTenzor<typename PETEBinaryReturn<T1,Sca,OpMultipply>::type,Dim> \
584  type; \
585 }; \
586 template<class T2, unsigned Dim> \
587 struct PETEBinaryReturn<Sca,AntiSymTenzor<T2,Dim>,OpMultipply> { \
588  typedef \
589  AntiSymTenzor<typename PETEBinaryReturn<Sca,T2,OpMultipply>::type,Dim> \
590  type; \
591 }; \
592 template<class T1, unsigned Dim> \
593 struct PETEBinaryReturn<AntiSymTenzor<T1,Dim>,Sca,OpDivide> { \
594  typedef \
595  AntiSymTenzor<typename PETEBinaryReturn<T1,Sca,OpDivide>::type,Dim> \
596  type; \
597 };
598 
605 
606 #undef _SCALAR_VST_RETURNS_
607 
608 
610 //
611 // ASSIGNMENT OPERATORS: min=, max=, &&=, ||=
612 //
614 
615 struct OpMinAssign {
617 };
618 
619 struct OpMaxAssign {
621 };
622 
623 struct OpAndAssign {
625 };
626 
627 struct OpOrAssign {
629 };
630 
631 
633 //
634 // OPERATOR()
635 //
637 
638 template<class T, class TP, unsigned Dim>
639 struct PETEUnaryReturn< Vektor<T, Dim>, OpParens<TP> > {
640  typedef T type;
641 };
642 
643 template<class T, class TP, unsigned Dim>
645  typedef T type;
646 };
647 
648 template<class T, class TP, unsigned Dim>
650  typedef T type;
651 };
652 
653 template<class T, class TP, unsigned Dim>
654 struct PETEUnaryReturn< Tenzor<T, Dim>, OpParens<TP> > {
655  typedef T type;
656 };
657 
658 #endif // IPPL_TYPE_COMPUTATIONS_H
659 
const unsigned Dim
std::complex< double > a
#define _PETE_RNG_RETURNS_(GEN)
int sign(T a)
#define _SCALAR_VST_RETURNS_(Sca)
const int PETE_BinaryUseLeftTag
const int PETE_UnaryPassThruTag
const int PETE_BinaryPromoteTag
MMatrix< m_complex > complex(MMatrix< double > real)
Definition: MMatrix.cpp:396
Definition: Tenzor.h:35
Definition: Vektor.h:32
OpParens(const TP &a)
Vektor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Vektor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Vektor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Vektor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Vektor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpAdd >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpSubtract >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpAdd >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpSubtract >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Vektor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Vektor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpAdd >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpSubtract >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpAdd >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpSubtract >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpAdd >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpSubtract >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpAdd >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpSubtract >::type, Dim > type
Tenzor< typename PETEBinaryReturn< T1, T2, OpMultipply >::type, Dim > type
PETE_ComputeBinaryType< T1, T2, Op, Op::tag >::type type