NeoPZ
fadlog.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 // A short implementation ( not all operators and
15 // functions are overloaded ) of 1st order Automatic
16 // Differentiation in forward mode (FAD) using
17 // EXPRESSION TEMPLATES.
18 //
19 //********************************************************
20 #ifndef _fadlog_h_
21 #define _fadlog_h_
22 
23 #include "pzreal.h"
24 
25 
26 #define FAD_LOG_MACRO(OP) \
27  template <class T> \
28  inline bool operator OP(const Fad<T> &a, const Fad<T> &b) { \
29  return (a.val() OP b.val()); \
30  } \
31  \
32  template < \
33  class A, class B, \
34  typename std::enable_if<((std::is_integral<B>::value || \
35  is_complex_or_floating_point<B>::value) && \
36  (std::is_integral<A>::value || \
37  is_complex_or_floating_point<A>::value)), \
38  int>::type * = nullptr> \
39  inline bool operator OP(const Fad<A> &a, const B &b) { \
40  return (a.val() OP b); \
41  } \
42  \
43  template < \
44  class A, class B, \
45  typename std::enable_if<((std::is_integral<B>::value || \
46  is_complex_or_floating_point<B>::value) && \
47  (std::is_integral<A>::value || \
48  is_complex_or_floating_point<A>::value)), \
49  int>::type * = nullptr> \
50  inline bool operator OP(const A &a, const Fad<B> &b) { \
51  return (a OP b.val()); \
52  } \
53  \
54  template <class T> \
55  inline bool operator OP(const FadExpr<T> &a, const FadExpr<T> &b) { \
56  return (a.val() OP b.val()); \
57  } \
58  \
59  template <class T> \
60  inline bool operator OP(const T &a, const FadExpr<T> &b) { \
61  return (a OP b.val()); \
62  } \
63  \
64  template <class T> \
65  inline bool operator OP(const FadExpr<T> &a, const T &b) { \
66  return (a.val() OP b); \
67  }
68 
69 
70 FAD_LOG_MACRO(==)
71 FAD_LOG_MACRO(!=)
74 FAD_LOG_MACRO(<=)
75 FAD_LOG_MACRO(>=)
76 FAD_LOG_MACRO(<<=)
77 FAD_LOG_MACRO(>>=)
79 
80 #undef FAD_LOG_MACRO
81 
82 
83 template <class T> inline bool operator !(const Fad<T> &a) {
84  return ( !a.val() );
85 }
86 
87 template <class T> inline bool operator !(const FadExpr<T> &a) {
88  return ( !a.val() );
89 }
90 
91 #endif
value_type val() const
Definition: fad.h:567
Definition: fad.h:36
Definition: fad.h:54
bool operator!(const Fad< T > &a)
Definition: fadlog.h:83
const T & val() const
Definition: fad.h:112
#define FAD_LOG_MACRO(OP)
Definition: fadlog.h:26
Contains the declaration of TPZFlopCounter class and TPZCounter struct.