Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tradoptest_47.cpp
Go to the documentation of this file.
1 
2 
3 /* Try to test all combinations of types and operations */
4 
5 
6 
7 #define ADT_RAD Sacado::Rad::
8 
9 
10 
11 #include "Sacado_trad.hpp"
12 #include <cstdio>
13 
14 using std::printf;
15 
16 
17 
18 typedef ADT_RAD IndepADvar<double> AI;
19 
20 typedef ADT_RAD ADvar<double> A;
21 
22 typedef ADT_RAD ConstADvar<double> C;
23 
24 typedef ADT_RAD ADvari<double> Ai;
25 
26 typedef const ADT_RAD IndepADvar<double> cAI;
27 
28 typedef const ADT_RAD ADvar<double> cA;
29 
30 typedef const ADT_RAD ConstADvar<double> cC;
31 
32 typedef const ADT_RAD ADvari<double> cAi;
33 
34 static int rc;
35 
36 
37 
38 /* This is to be run through an awk program that changes lines */
39 
40 /* with "BINTEST" or "UNOPTEST" at the beginning of the line into */
41 
42 /* a the desired C++ (which we can then inspect). */
43 
44 
45 
46  void
47 
48 botch(const char *what, double wanted, double got)
49 
50 {
51 
52  printf("%s: expected %g, got %g, diff = %.2g\n", what, wanted, got, wanted-got);
53 
54  rc = 1;
55 
56  }
57 
58 
59 
60  const double tol = 5e-16;
61 
62 
63 
64  int
65 
66 differ(double a, double b)
67 
68 {
69 
70  double d = a - b;
71 
72  if (d < 0.)
73 
74  d = -d;
75 
76  if (a < 0.)
77 
78  a = -a;
79 
80  if (b < 0.)
81 
82  b = -b;
83 
84  if (a < b)
85 
86  a = b;
87 
88  if (a > 0.)
89 
90  d /= a;
91 
92  return d > tol;
93 
94  }
95 
96 
97 
98 #ifndef RAD_EQ_ALIAS
99 
100 #define Plus_dx 1.
101 
102 #else
103 
104 #ifdef RAD_AUTO_AD_Const
105 
106 #define Plus_dx 1.
107 
108 #else
109 
110 #define Plus_dx 0.
111 
112 #endif
113 
114 #endif
115 
116 
117 
118  int
119 
120 main(void)
121 
122 {
123 
124  AI xAI, yAI;
125 
126  A fA, xA, yA;
127 
128  C xC, yC;
129 
130  double dx, f, xd;
131 
132 
133 
134  rc = 0;
135 
136 
137  /**** Test of atanh ****/
138 
139  xd = .6; f = atanh(.6); dx = 1.5625;
140  xAI = xd;
141  fA = atanh(xAI);
142  A::Gradcomp();
143  if (differ(fA.val(), f)) botch("fA = atanh(xAI)", f, fA.val());
144  else if (differ(xAI.adj(), dx)) botch("d atanh(xAI)/dx", dx, xAI.adj());
145  {
146  A::aval_reset();
147  cAI xcAI(xd);
148  fA = atanh(xcAI);
149  A::Gradcomp();
150  if (differ(fA.val(), f)) botch("fA = atanh(xcAI)", f, fA.val());
151  else if (differ(xcAI.adj(), dx)) botch("d atanh(xcAI)/dx", dx, xcAI.adj());
152  }
153  xA = xd;
154  fA = atanh(xA);
155  A::Gradcomp();
156  if (differ(fA.val(), f)) botch("fA = atanh(xA)", f, fA.val());
157  else if (differ(xA.adj(), dx)) botch("d atanh(xA)/dx", dx, xA.adj());
158  {
159  A::aval_reset();
160  cA xcA(xd);
161  fA = atanh(xcA);
162  A::Gradcomp();
163  if (differ(fA.val(), f)) botch("fA = atanh(xcA)", f, fA.val());
164  else if (differ(xcA.adj(), dx)) botch("d atanh(xcA)/dx", dx, xcA.adj());
165  }
166  xC = xd;
167  fA = atanh(xC);
168  A::Gradcomp();
169  if (differ(fA.val(), f)) botch("fA = atanh(xC)", f, fA.val());
170  else if (differ(xC.adj(), dx)) botch("d atanh(xC)/dx", dx, xC.adj());
171  {
172  A::aval_reset();
173  cC xcC(xd);
174  fA = atanh(xcC);
175  A::Gradcomp();
176  if (differ(fA.val(), f)) botch("fA = atanh(xcC)", f, fA.val());
177  else if (differ(xcC.adj(), dx)) botch("d atanh(xcC)/dx", dx, xcC.adj());
178  }
179  {
180  cAi xcAi(xd);
181  fA = atanh(xcAi);
182  A::Gradcomp();
183  if (differ(fA.val(), f)) botch("fA = atanh(xcAi)", f, fA.val());
184  else if (differ(xcAi.aval, dx)) botch("d atanh(xcAi)/dx", dx, xcAi.aval);
185  }
186  {
187  A::aval_reset();
188  cAi xcAi(xd);
189  fA = atanh(xcAi);
190  A::Gradcomp();
191  if (differ(fA.val(), f)) botch("fA = atanh(xcAi)", f, fA.val());
192  else if (differ(xcAi.aval, dx)) botch("d atanh(xcAi)/dx", dx, xcAi.aval);
193  }
194 
195 
196  if (!rc) // chatter for cppunit test, which cannot tolerate silence
197 
198  printf("OK\n");
199 
200  return rc;
201 
202  }
int botch(ExpectedAnswer *e, const char *partial, double got, double wanted)
void f()
expr expr dx(i)
ADT_RAD IndepADvar< double > AI
const ADT_RAD IndepADvar< double > cAI
atanh(expr.val())
static int rc
#define Ai
Definition: Sacado_rad.hpp:575
#define ADT_RAD
#define C(x)
#define A
Definition: Sacado_rad.hpp:572
int main()
Definition: ad_example.cpp:191
const ADT_RAD ADvari< double > cAi
static int differ(double a, double b)
Definition: hesopcheck.cpp:147
const ADT_RAD ConstADvar< double > cC
const double tol
#define AI
Definition: Sacado_rad.hpp:576
const ADT_RAD ADvar< double > cA