Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
14using std::printf;
15
16
17
18typedef ADT_RAD IndepADvar<double> AI;
19
20typedef ADT_RAD ADvar<double> A;
21
22typedef ADT_RAD ConstADvar<double> C;
23
24typedef ADT_RAD ADvari<double> Ai;
25
26typedef const ADT_RAD IndepADvar<double> cAI;
27
28typedef const ADT_RAD ADvar<double> cA;
29
30typedef const ADT_RAD ConstADvar<double> cC;
31
32typedef const ADT_RAD ADvari<double> cAi;
33
34static 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
48botch(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
66differ(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
120main(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 }
expr expr dx(i)
atanh(expr.val())
ADT_RAD IndepADvar< double > AI
const ADT_RAD ConstADvar< double > cC
const ADT_RAD IndepADvar< double > cAI
const ADT_RAD ADvari< double > cAi
const ADT_RAD ADvar< double > cA
ADT_RAD IndepADvar< double > AI
const ADT_RAD ConstADvar< double > cC
#define ADT_RAD
const ADT_RAD IndepADvar< double > cAI
ADT_RAD ADvar< double > A
const double tol
int main(void)
const ADT_RAD ADvari< double > cAi
static int rc
ADT_RAD ConstADvar< double > C
void botch(const char *what, double wanted, double got)
const ADT_RAD ADvar< double > cA
ADT_RAD ADvari< double > Ai
int differ(double a, double b)