OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
33#include <complex>
34
35
36// forward declarations
37template<class T, unsigned D> class Vektor;
38template<class T, unsigned D> class Tenzor;
39template<class T, unsigned D> class AntiSymTenzor;
40template<class T, unsigned D> class SymTenzor;
41template <class T> class RNGLattice;
42class RNGXDiv;
43
44
45// definition of global sign function
46template<class T>
47inline 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
58template<> 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) \
65template <> \
66struct PETEBinaryReturn<GEN,SCA,OP> { \
67 typedef PETEBinaryReturn<double,SCA,OP>::type type; \
68}; \
69template <> \
70struct 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 \
82template <> 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
99template<class T, unsigned Dim>
101 enum { val = 20 + 10 * Dim + PETE_Type2Index<T>::val };
102};
103
104template<class T, unsigned Dim>
106 enum { val = 120 + 10 * Dim + PETE_Type2Index<T>::val };
107};
108
109template<class T, unsigned Dim>
111 enum { val = 220 + 10 * Dim + PETE_Type2Index<T>::val };
112};
113
114template<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
128struct FnAbs {
130};
131
132template<> 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
138struct FnConj {
140};
141
142struct FnNorm {
143 typedef double type;
145};
146
147template<> struct PETEUnaryReturn<std::complex<double>, FnNorm> {
148 typedef double type;
149};
150
151struct FnArg {
152 typedef double type;
154};
155
156template<> struct PETEUnaryReturn<std::complex<double>, FnArg> {
157 typedef double type;
158};
159
160struct FnReal {
161 typedef double type;
163};
164
165template<> struct PETEUnaryReturn<std::complex<double>, FnReal> {
166 typedef double type;
167};
168
169struct FnImag {
170 typedef double type;
172};
173
174template<> struct PETEUnaryReturn<std::complex<double>, FnImag> {
175 typedef double type;
176};
177
178// The sign function.
179
180struct FnSign {
181 typedef int type;
183};
184
185template<class TP>
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
196struct FnTrace {
198};
199
200struct FnDet {
202};
203
206};
207
210};
211
212// Life is pretty simple if we have partial specialization.
213
214template<class T, unsigned Dim>
216 typedef T type;
217};
218
219template<class T, unsigned Dim>
221 typedef T type;
222};
223
224template<class T, unsigned Dim>
226 typedef T type;
227};
228
229template<class T, unsigned Dim>
231 typedef T type;
232};
233
234template<class T, unsigned Dim>
236 typedef T type;
237};
238
239template<class T, unsigned Dim>
241 typedef T type;
242};
243
244template<class T, unsigned Dim>
247};
248
249template<class T, unsigned Dim>
252};
253
254template<class T, unsigned Dim>
257};
258
259template<class T, unsigned Dim>
262};
263
264template<class T, unsigned Dim>
267};
268
269template<class T, unsigned Dim>
272};
273
274
276//
277// SPECIAL CASES FOR BINARY FUNCTIONS
278//
280
281// Min and Max functions.
282
283struct FnMin {
285};
286
287struct FnMax {
289};
290
291// Dot, dot-dot, and outerProduct functions.
292
293struct FnDot {
295};
296
297struct FnDotDot {
299};
300
303};
304
305// Cross-product:
306
307struct FnCross {
309};
310
311// Involving Vektors:
312
313template<class T1, class T2, unsigned Dim>
316};
317
318template<class T1, class T2, unsigned Dim>
321};
322
323template<class T1, class T2, unsigned Dim>
326};
327
328// Involving Tenzors, but no combination with SymTenzors or AntiSymTenzors:
329
330template<class T1, class T2, unsigned Dim>
333};
334
335template<class T1, class T2, unsigned Dim>
338};
339
340template<class T1, class T2, unsigned Dim>
343};
344
345template<class T1, class T2, unsigned Dim>
348};
349
350// Involving SymTenzors, possibly combined with Tenzors:
351
352template<class T1, class T2, unsigned Dim>
356};
357
358template<class T1, class T2, unsigned Dim>
361};
362
363template<class T1, class T2, unsigned Dim>
366};
367
368template<class T1, class T2, unsigned Dim>
371};
372
373template<class T1, class T2, unsigned Dim>
376};
377
378template<class T1, class T2, unsigned Dim>
381};
382
383template<class T1, class T2, unsigned Dim>
386};
387
388template<class T1, class T2, unsigned Dim>
391};
392
393template<class T1, class T2, unsigned Dim>
396};
397
398template<class T1, class T2, unsigned Dim>
401};
402
403template<class T1, class T2, unsigned Dim>
406};
407
408template<class T1, class T2, unsigned Dim>
411};
412
413template<class T1, class T2, unsigned Dim>
416};
417
418// Involving AntiSymTenzors, possibly combined with Tenzors or SymTenzors:
419
420template<class T1, class T2, unsigned Dim>
424};
425
426template<class T1, class T2, unsigned Dim>
428{
430};
431
432template<class T1, class T2, unsigned Dim>
435};
436
437template<class T1, class T2, unsigned Dim>
440};
441
442template<class T1, class T2, unsigned Dim>
445};
446
447template<class T1, class T2, unsigned Dim>
450};
451
452template<class T1, class T2, unsigned Dim>
455};
456
457template<class T1, class T2, unsigned Dim>
460};
461
462template<class T1, class T2, unsigned Dim>
465};
466
467template<class T1, class T2, unsigned Dim>
470};
471
472template<class T1, class T2, unsigned Dim>
475};
476
477template<class T1, class T2, unsigned Dim>
480};
481
482template<class T1, class T2, unsigned Dim>
485};
486
487template<class T1, class T2, unsigned Dim>
490};
491
492template<class T1, class T2, unsigned Dim>
495};
496
497template<class T1, class T2, unsigned Dim>
500};
501
502template<class T1, class T2, unsigned Dim>
505};
506
507template<class T1, class T2, unsigned Dim>
510};
511
512template<class T1, class T2, unsigned Dim>
515};
516
517template<class T1, class T2, unsigned Dim>
520};
521
522template<class T1, class T2, unsigned Dim>
525};
526
527template<class T1, class T2, unsigned Dim>
530};
531
532// Need to specify scalar operations directly.
533
534#define _SCALAR_VST_RETURNS_(Sca) \
535template<class T1, unsigned Dim> \
536struct PETEBinaryReturn<Vektor<T1,Dim>,Sca,OpMultipply> { \
537 typedef Vektor<typename PETEBinaryReturn<T1,Sca,OpMultipply>::type,Dim> \
538 type; \
539}; \
540template<class T2, unsigned Dim> \
541struct PETEBinaryReturn<Sca,Vektor<T2,Dim>,OpMultipply> { \
542 typedef Vektor<typename PETEBinaryReturn<Sca,T2,OpMultipply>::type,Dim> \
543 type; \
544}; \
545template<class T1, unsigned Dim> \
546struct PETEBinaryReturn<Vektor<T1,Dim>,Sca,OpDivide> { \
547 typedef Vektor<typename PETEBinaryReturn<T1,Sca,OpDivide>::type,Dim> \
548 type; \
549}; \
550template<class T1, unsigned Dim> \
551struct PETEBinaryReturn<Tenzor<T1,Dim>,Sca,OpMultipply> { \
552 typedef Tenzor<typename PETEBinaryReturn<T1,Sca,OpMultipply>::type,Dim> \
553 type; \
554}; \
555template<class T2, unsigned Dim> \
556struct PETEBinaryReturn<Sca,Tenzor<T2,Dim>,OpMultipply> { \
557 typedef Tenzor<typename PETEBinaryReturn<Sca,T2,OpMultipply>::type,Dim> \
558 type; \
559}; \
560template<class T1, unsigned Dim> \
561struct PETEBinaryReturn<Tenzor<T1,Dim>,Sca,OpDivide> { \
562 typedef Tenzor<typename PETEBinaryReturn<T1,Sca,OpDivide>::type,Dim> \
563 type; \
564}; \
565template<class T1, unsigned Dim> \
566struct PETEBinaryReturn<SymTenzor<T1,Dim>,Sca,OpMultipply> { \
567 typedef SymTenzor<typename PETEBinaryReturn<T1,Sca,OpMultipply>::type,Dim> \
568 type; \
569}; \
570template<class T2, unsigned Dim> \
571struct PETEBinaryReturn<Sca,SymTenzor<T2,Dim>,OpMultipply> { \
572 typedef SymTenzor<typename PETEBinaryReturn<Sca,T2,OpMultipply>::type,Dim> \
573 type; \
574}; \
575template<class T1, unsigned Dim> \
576struct PETEBinaryReturn<SymTenzor<T1,Dim>,Sca,OpDivide> { \
577 typedef SymTenzor<typename PETEBinaryReturn<T1,Sca,OpDivide>::type,Dim> \
578 type; \
579}; \
580template<class T1, unsigned Dim> \
581struct PETEBinaryReturn<AntiSymTenzor<T1,Dim>,Sca,OpMultipply> { \
582 typedef \
583 AntiSymTenzor<typename PETEBinaryReturn<T1,Sca,OpMultipply>::type,Dim> \
584 type; \
585}; \
586template<class T2, unsigned Dim> \
587struct PETEBinaryReturn<Sca,AntiSymTenzor<T2,Dim>,OpMultipply> { \
588 typedef \
589 AntiSymTenzor<typename PETEBinaryReturn<Sca,T2,OpMultipply>::type,Dim> \
590 type; \
591}; \
592template<class T1, unsigned Dim> \
593struct 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
617};
618
621};
622
625};
626
629};
630
631
633//
634// OPERATOR()
635//
637
638template<class T, class TP, unsigned Dim>
640 typedef T type;
641};
642
643template<class T, class TP, unsigned Dim>
645 typedef T type;
646};
647
648template<class T, class TP, unsigned Dim>
650 typedef T type;
651};
652
653template<class T, class TP, unsigned Dim>
655 typedef T type;
656};
657
658#endif // IPPL_TYPE_COMPUTATIONS_H
659
const unsigned Dim
const int PETE_BinaryUseLeftTag
const int PETE_UnaryPassThruTag
const int PETE_BinaryPromoteTag
#define _PETE_RNG_RETURNS_(GEN)
int sign(T a)
#define _SCALAR_VST_RETURNS_(Sca)
std::complex< double > a
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