49#ifndef SACADO_TRAITS_HPP
50#define SACADO_TRAITS_HPP
60#ifdef HAVE_SACADO_COMPLEX
78 static const bool value =
false;
84 static const bool value =
false;
94 template <
typename T,
unsigned,
unsigned>
struct ViewFadType {};
98 static const bool value =
false;
106 template <
typename A,
typename B,
typename Enabled =
void>
struct Promote {};
109 template <
typename A>
111 typename mpl::enable_if_c< !OverrideDefaultPromote<A>::value >::type > {
116 template <
typename A,
typename B>
118 typename mpl::enable_if_c< mpl::is_convertible<A,B>::value &&
119 !mpl::is_convertible<B,A>::value &&
120 !OverrideDefaultPromote<A>::value &&
121 !OverrideDefaultPromote<B>::value
127 template <
typename A,
typename B>
129 typename mpl::enable_if_c< mpl::is_convertible<B,A>::value &&
130 !mpl::is_convertible<A,B>::value &&
131 !OverrideDefaultPromote<A>::value &&
132 !OverrideDefaultPromote<B>::value
141 template <
typename A,
typename B>
143 typename mpl::enable_if_c< mpl::is_convertible<A,B>::value &&
144 mpl::is_convertible<B,A>::value &&
145 !mpl::is_same<A,B>::value &&
146 ( IsExpr<A>::value ||
147 IsExpr<B>::value ) >::type >
159 template <
typename A,
typename B>
161 typename mpl::enable_if_c< !mpl::is_convertible<A,B>::value &&
162 !mpl::is_convertible<B,A>::value &&
164 mpl::is_convertible< B, typename BaseExprType< typename A::value_type >::type >::value
175 template <
typename A,
typename B>
177 typename mpl::enable_if_c< !mpl::is_convertible<A,B>::value &&
178 !mpl::is_convertible<B,A>::value &&
180 mpl::is_convertible< A, typename BaseExprType< typename B::value_type >::type >::value
191 template <
typename A,
typename B>
193 typename mpl::enable_if_c< !mpl::is_convertible<A,B>::value &&
194 !mpl::is_convertible<B,A>::value &&
197 mpl::is_same< typename BaseExprType< typename A::value_type >::type,
198 typename BaseExprType< typename B::value_type >::type >::value
207#define SACADO_PROMOTE_SPECIALIZATION(type1,type2,type3) \
208 template <> struct Promote< type1, type2, void > { \
209 typedef type3 type; \
211 template <> struct Promote< type2, type1, void > { \
212 typedef type3 type; \
220#ifdef HAVE_SACADO_COMPLEX
231#undef SACADO_PROMOTE_SPECIALIZATION
235#define SACADO_AD_PROMOTE_SPEC(NS, AD)
237#define SACADO_AD_PROMOTE_SPEC2(NS, AD)
239#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
241#define SACADO_SFAD_PROMOTE_SPEC(NS, FAD)
243#define SACADO_EXPR_PROMOTE_SPEC(NS)
245#define SACADO_VFAD_PROMOTE_SPEC(NS)
247#define SACADO_RAD_PROMOTE_SPEC(NS) \
249 template <typename> class ADvar; \
250 template <typename> class ADvari; \
252 template <typename T> \
253 struct OverrideDefaultPromote< NS :: ADvari <T>& > { \
254 static const bool value = true; \
256 template <typename T> \
257 struct Promote< NS :: ADvar <T>, \
258 NS :: ADvari <T>& > { \
259 typedef NS :: ADvar <T> type; \
261 template <typename T> \
262 struct Promote< NS :: ADvari <T>&, \
263 NS :: ADvar <T> > { \
264 typedef NS :: ADvar <T> type; \
266 template <typename T> \
267 struct Promote< NS :: ADvari <T>&, \
268 typename NS :: ADvari <T>::value_type > { \
269 typedef NS :: ADvar <T> type; \
271 template <typename T> \
272 struct Promote< typename NS :: ADvari <T>::value_type, \
273 NS :: ADvari <T>& > { \
274 typedef NS :: ADvar <T> type; \
276 template <typename T> \
277 struct Promote< NS :: ADvari <T>&, \
278 typename dummy< typename NS :: ADvari <T>::value_type, \
279 typename NS :: ADvari <T>::scalar_type \
281 typedef NS :: ADvar <T> type; \
283 template <typename T> \
284 struct Promote< typename dummy< typename NS :: ADvari <T>::value_type, \
285 typename NS :: ADvari <T>::scalar_type \
287 NS :: ADvari <T>& > { \
288 typedef NS :: ADvar <T> type; \
363 template <
typename T>
struct Value {
365 static const T&
eval(
const T&
x) {
return x; }
369 template <
typename T>
struct Value<const T> {
384 static const T&
eval(
const T&
x) {
return x; }
397 template <
typename T>
411 static std::string
eval() {
return ""; }
417 static bool eval(
const T&
x,
const T&
y) {
return x ==
y; }
439 template <
typename T>
struct IsFad {
444 template <
typename T>
struct IsFad< const T >
450 template <
typename T>
456 template <
typename T>
462#define SACADO_BUILTIN_SPECIALIZATION(t,NAME) \
463 template <> struct ScalarType< t > { \
466 template <> struct ValueType< t > { \
469 template <> struct IsADType< t > { \
470 static const bool value = false; \
472 template <> struct IsScalarType< t > { \
473 static const bool value = true; \
475 template <> struct Value< t > { \
476 SACADO_INLINE_FUNCTION \
477 static const t& eval(const t& x) { return x; } \
479 template <> struct ScalarValue< t > { \
480 SACADO_INLINE_FUNCTION \
481 static const t& eval(const t& x) { return x; } \
483 template <> struct StringName< t > { \
484 static std::string eval() { return NAME; } \
486 template <> struct IsEqual< t > { \
487 SACADO_INLINE_FUNCTION \
488 static bool eval(const t& x, const t& y) { \
491 template <> struct IsStaticallySized< t > { \
492 static const bool value = true; \
495#define SACADO_BUILTIN_SPECIALIZATION_COMPLEX(t,NAME) \
496 template <> struct ScalarType< t > { \
499 template <> struct ValueType< t > { \
502 template <> struct IsADType< t > { \
503 static const bool value = false; \
505 template <> struct IsScalarType< t > { \
506 static const bool value = true; \
508 template <> struct Value< t > { \
509 static const t& eval(const t& x) { return x; } \
511 template <> struct ScalarValue< t > { \
512 static const t& eval(const t& x) { return x; } \
514 template <> struct StringName< t > { \
515 static std::string eval() { return NAME; } \
517 template <> struct IsEqual< t > { \
518 static bool eval(const t& x, const t& y) { \
521 template <> struct IsStaticallySized< t > { \
522 static const bool value = true; \
533#ifdef HAVE_SACADO_COMPLEX
538#undef SACADO_BUILTIN_SPECIALIZATION
539#undef SACADO_BUILTIN_SPECIALIZATION_COMPLEX
541template<
typename T , T v ,
bool NonZero = ( v != T(0) ) >
556template<
typename T , T zero >
#define SACADO_INLINE_FUNCTION
#define SACADO_BUILTIN_SPECIALIZATION_COMPLEX(t, NAME)
#define SACADO_BUILTIN_SPECIALIZATION(t, NAME)
Specialization of above classes to builtin types.
#define SACADO_PROMOTE_SPECIALIZATION(type1, type2, type3)
Specialization of Promote to builtin types.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors.
@ InitDerivArray
Initialize the derivative array.
@ NoInitDerivArray
Do not initialize the derivative array.
SACADO_INLINE_FUNCTION ScalarType< T >::type scalarValue(const T &x)
A simple template function for invoking ScalarValue<>
Get the base Fad type from a view/expression.
Base template specification for IsADType.
Base template specification for testing equivalence.
static SACADO_INLINE_FUNCTION bool eval(const T &x, const T &y)
Base template specification for whether a type is a Fad type.
Base template specification for IsScalarType.
Base template specification for IsSimdType.
Base template specification for testing whether type is statically sized.
Determine whether a given type is a view.
Base template specification for marking constants.
static SACADO_INLINE_FUNCTION void eval(T &x)
Remove const from a type.
const ScalarType< T >::type type
Base template specification for ScalarType.
ScalarType< T >::type scalar_type
static SACADO_INLINE_FUNCTION const scalar_type & eval(const T &x)
Base template specification for ScalarValue.
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
Base template specification for static size.
static const unsigned value
Base template specification for string names of types.
static std::string eval()
const ValueType< T >::type type
Base template specification for ValueType.
static SACADO_INLINE_FUNCTION const value_type & eval(const T &x)
ValueType< T >::type value_type
Base template specification for Value.
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
Get view type for any Fad type.
integral_nonzero< T, 0 > type
SACADO_INLINE_FUNCTION integral_nonzero()
SACADO_INLINE_FUNCTION integral_nonzero(const T &v)
SACADO_INLINE_FUNCTION integral_nonzero(const integral_nonzero &v)
SACADO_INLINE_FUNCTION integral_nonzero & operator=(const integral_nonzero &v)
SACADO_INLINE_FUNCTION integral_nonzero & operator=(const T &v)
SACADO_INLINE_FUNCTION integral_nonzero & operator=(const integral_nonzero &)
SACADO_INLINE_FUNCTION integral_nonzero(const integral_nonzero &)
SACADO_INLINE_FUNCTION integral_nonzero(const T &)
SACADO_INLINE_FUNCTION integral_nonzero()
SACADO_INLINE_FUNCTION integral_nonzero & operator=(const T &)
integral_nonzero< T, v > type