NeoPZ
promote.h
Go to the documentation of this file.
1 // Emacs will be in -*- Mode: c++ -*-
2 //
3 // ************ DO NOT REMOVE THIS BANNER ****************
4 //
5 // Nicolas Di Cesare <Nicolas.Dicesare@ann.jussieu.fr>
6 // http://www.ann.jussieu.fr/~dicesare
7 //
8 // CEMRACS 98 : C++ courses,
9 // templates : new C++ techniques
10 // for scientific computing
11 //
12 //********************************************************
13 //
14 // NumericalTraits class to illustrate TRAITS
15 //
16 //********************************************************
17 #ifndef _promote_h
18 #define _promote_h
19 
20 #include "pzreal.h"
21 // ANSI C++ include
22 #include <complex>
23 
24 using namespace std;
25 
26 template <class T> class ADPromote {
27  const T& x_;
28 public:
29  typedef typename T::value_type value_type;
30  ADPromote(const T& x) : x_(x) {;}
31 
32  value_type val() { return x_.val();}
33 };
34 
35 //Specialization
36 #define ADP_SPE(type) \
37 template <> class ADPromote< type > { \
38  const type& x_; \
39 public: \
40  typedef type value_type; \
41  ADPromote(const type& x) : x_(x) {;} \
42  \
43  value_type val() { return x_;} \
44 };
45 
46 ADP_SPE(long double)
47 ADP_SPE(double)
48 ADP_SPE(float)
49 ADP_SPE(int64_t)
50 ADP_SPE(int)
51 
52 #undef ADP_SPE
53 
54 template <int Num,class T> class TFad;
55 template <class T> class Fad;
56 template <int Num, class T> class TinyFad;
57 
58 template <class A, class B, class Enable = void>
59 class NumericalTraits
60 {
61 public:
62 };
63 
64 //Specialization
65 template <class T> class NumericalTraits<T,T> {
66 public:
67  typedef T promote;
68 };
69 
70 template <int Num, class T>
71 class NumericalTraits< TFad<Num,T>, TFad<Num,T> > {
72 public:
74 };
75 
76 template <int Num, class A, class B> class NumericalTraits< TFad<Num,A>, B> {
77 public:
80 
82 };
83 
84 template <int Num, class A, class B> class NumericalTraits< B, TFad<Num,A> > {
85 public:
88 
90 };
91 
92 
93 
94 template <int Num, class L, class R>
95 class NumericalTraits< TinyFad<Num,L>, TinyFad<Num,R> > {
96 public:
97  typedef typename TinyFad<Num,L>::value_type lv;
98  typedef typename TinyFad<Num,R>::value_type rv;
100 
102 };
103 
104 template <int Num, class L, class R> class NumericalTraits< TinyFad<Num,L>, R> {
105 public:
106  typedef typename TinyFad<Num,L>::value_type lv;
107  typedef typename ADPromote<R>::value_type rv;
109 
111 };
112 
113 template <int Num, class L, class R> class NumericalTraits< L, TinyFad<Num,R> > {
114 public:
115  typedef typename ADPromote<L>::value_type lv;
116  typedef typename TinyFad<Num,R>::value_type rv;
118 
120 };
121 
122 template <class L, class R>
123 class NumericalTraits<Fad<L>, Fad<R>, typename std::enable_if<!std::is_same<L, R>::value>::type> {
124 public:
125  typedef typename Fad<L>::value_type lv;
126  typedef typename Fad<R>::value_type rv;
128 
130 };
131 
132 template <class L, class R>
133 class NumericalTraits< Fad<L>, R, typename std::enable_if<is_arithmetic_pz<R>::value>::type> {
134 public:
135  typedef typename Fad<L>::value_type lv;
136  typedef typename ADPromote<R>::value_type rv;
138 
140 };
141 
142 template <class L, class R>
143 class NumericalTraits< L, Fad<R>, typename std::enable_if<is_arithmetic_pz<L>::value>::type> {
144 public:
145  typedef typename ADPromote<L>::value_type lv;
146  typedef typename Fad<R>::value_type rv;
148 
150 };
151 
152 
153 #define NT_SPE(type1,type2,type3) \
154 template <> class NumericalTraits<type1,type2> { \
155 public: \
156  typedef type3 promote; \
157 }; \
158 template <> class NumericalTraits<type2,type1> { \
159 public: \
160  typedef type3 promote; \
161 };
162 NT_SPE(complex<double>,complex<long double>,complex<long double>)
163 NT_SPE(complex<float>,complex<long double>,complex<long double>)
164 NT_SPE(complex<float>,complex<double>,complex<double>)
165 NT_SPE(long double,complex<long double>,complex<long double>)
166 NT_SPE(long double,complex<double>,complex<long double>)
167 NT_SPE(long double,complex<float>,complex<long double>)
168 NT_SPE(double,complex<long double>,complex<long double>)
169 NT_SPE(double,complex<double>,complex<double>)
170 NT_SPE(double,complex<float>,complex<double>)
171 NT_SPE(double,long double,long double)
172 NT_SPE(float,complex<long double>,complex<long double>)
173 NT_SPE(float,complex<double>,complex<double>)
174 NT_SPE(float,complex<float>,complex<float>)
175 NT_SPE(float,long double,long double)
176 NT_SPE(float,double,double)
177 NT_SPE(int64_t,complex<long double>,complex<long double>)
178 NT_SPE(int64_t,complex<double>,complex<double>)
179 NT_SPE(int64_t,complex<float>,complex<float>)
180 NT_SPE(int64_t,long double,long double)
181 NT_SPE(int64_t,double,double)
182 NT_SPE(int64_t,float,float)
183 NT_SPE(int,complex<long double>,complex<long double>)
184 NT_SPE(int,complex<double>,complex<double>)
185 NT_SPE(int,complex<float>,complex<float>)
186 NT_SPE(int,long double,long double)
187 NT_SPE(int,double,double)
188 NT_SPE(int,float,float)
189 NT_SPE(int,int64_t,int64_t)
190 
191 
192 #undef NT_SPE
193 
194 #endif
const T & x_
Definition: promote.h:27
TFad< Num, A >::value_type fad_type
Definition: promote.h:86
T::value_type value_type
Definition: promote.h:29
TFad< Num, p_type > promote
Definition: promote.h:89
ADPromote(const T &x)
Definition: promote.h:30
NumericalTraits< lv, rv >::promote value_type
Definition: promote.h:117
TFad< Num, p_type > promote
Definition: promote.h:81
TinyFad< Num, R >::value_type rv
Definition: promote.h:116
Definition: fad.h:54
TinyFad< Num, value_type > promote
Definition: promote.h:119
TinyFad< Num, value_type > promote
Definition: promote.h:110
NumericalTraits< fad_type, B >::promote p_type
Definition: promote.h:79
ADPromote< R >::value_type rv
Definition: promote.h:107
ADPromote< L >::value_type lv
Definition: promote.h:115
TFad< Num, A >::value_type fad_type
Definition: promote.h:78
Definition: tfad.h:64
NumericalTraits< lv, rv >::promote value_type
Definition: promote.h:108
T value_type
Definition: tinyfad.h:53
T value_type
Definition: fad.h:56
#define NT_SPE(type1, type2, type3)
Definition: promote.h:153
NumericalTraits< L, R >::promote value_type
Definition: promote.h:99
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
TinyFad< Num, L >::value_type lv
Definition: promote.h:106
value_type val()
Definition: promote.h:32
NumericalTraits< fad_type, B >::promote p_type
Definition: promote.h:87
#define ADP_SPE(type)
Definition: promote.h:36
T value_type
Definition: tfad.h:66