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