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