v0.14.0
Loading...
Searching...
No Matches
promote.hpp
Go to the documentation of this file.
1/* Traits that allow auto-promotion of int's to double's, double's to
2 complex, etc. Shamelessly stolen from
3
4 http://extreme.indiana.edu/~tveldhui/papers/techniques/
5
6 For now, only int, double, and complex<double> are covered. If you
7 want more, just insert a DECLARE_PROMOTE(A,B,C), where A and B are
8 the two types, and C is what they should be coerced to. */
9
10#pragma once
11
12namespace FTensor
13{
14 template <class T1, class T2> class promote
15 {
16 public:
17 using V = T1;
18 };
19
20#define DECLARE_PROMOTE(A, B, C) \
21 template <> class promote<A, B> { \
22 public: \
23 using V = C; \
24 }
25
26 DECLARE_PROMOTE(int, double, double);
27 DECLARE_PROMOTE(double, int, double);
28 DECLARE_PROMOTE(int, std::complex<double>, std::complex<double>);
29 DECLARE_PROMOTE(std::complex<double>, int, std::complex<double>);
30 DECLARE_PROMOTE(double, std::complex<double>, std::complex<double>);
31 DECLARE_PROMOTE(std::complex<double>, double, std::complex<double>);
32
33#ifdef WITH_ADOL_C
38 DECLARE_PROMOTE(adtl::adouble, double, adtl::adouble);
39 DECLARE_PROMOTE(double, adtl::adouble, adtl::adouble);
40 DECLARE_PROMOTE(adtl::adouble, int, adtl::adouble);
41 DECLARE_PROMOTE(int, adtl::adouble, adtl::adouble);
42 DECLARE_PROMOTE(adub, double, adub);
43 DECLARE_PROMOTE(double, adub, adub);
44 DECLARE_PROMOTE(adub, int, adub);
45 DECLARE_PROMOTE(int, adub, adub);
46#endif // WITH_ADOL_C
47
48#undef DECLARE_PROMOTE
49} // namespace FTensor
Tensors class implemented by Walter Landry.
Definition: FTensor.hpp:51
#define DECLARE_PROMOTE(A, B, C)
Definition: promote.hpp:20