10 #ifndef FADUNITTESTS_HPP
11 #define FADUNITTESTS_HPP
26 template <
typename FadType>
59 for (
int i=0;
i<
n;
i++) {
76 template <
typename ScalarT>
78 ScalarT t1 = 3. * a +
sin(b) /
log(
fabs(a - b * 7.));
94 #define BINARY_OP_TEST(FIXTURENAME,TESTNAME,OP) \
95 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
96 auto a_dfad = this->a_dfad_; \
97 auto b_dfad = this->b_dfad_; \
98 auto c_dfad = this->c_dfad_; \
99 auto a_fad = this->a_fad_; \
100 auto b_fad = this->b_fad_; \
101 auto c_fad = this->c_fad_; \
102 c_dfad = a_dfad OP b_dfad; \
103 c_fad = a_fad OP b_fad; \
104 COMPARE_FADS(c_dfad, c_fad); \
106 double val = this->urand.number(); \
107 c_dfad = a_dfad OP val; \
108 c_fad = a_fad OP val; \
109 COMPARE_FADS(c_dfad, c_fad); \
111 c_dfad = val OP b_dfad; \
112 c_fad = val OP b_fad; \
113 COMPARE_FADS(c_dfad, c_fad); \
116 #define RELOP_TEST(FIXTURENAME,TESTNAME,OP) \
117 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
118 auto a_dfad = this->a_dfad_; \
119 auto b_dfad = this->b_dfad_; \
120 auto a_fad = this->a_fad_; \
121 auto b_fad = this->b_fad_; \
122 bool r1 = a_dfad OP b_dfad; \
123 bool r2 = a_fad OP b_fad; \
124 ASSERT_TRUE(r1 == r2); \
126 double val = this->urand.number(); \
127 r1 = a_dfad OP val; \
129 ASSERT_TRUE(r1 == r2); \
131 r1 = val OP b_dfad; \
133 ASSERT_TRUE(r1 == r2); \
136 #define BINARY_FUNC_TEST(FIXTURENAME,TESTNAME,FUNC) \
137 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
138 auto a_dfad = this->a_dfad_; \
139 auto b_dfad = this->b_dfad_; \
140 auto c_dfad = this->c_dfad_; \
141 auto a_fad = this->a_fad_; \
142 auto b_fad = this->b_fad_; \
143 auto c_fad = this->c_fad_; \
144 c_dfad = FUNC (a_dfad,b_dfad); \
145 c_fad = FUNC (a_fad,b_fad); \
146 COMPARE_FADS(c_dfad, c_fad); \
148 double val = this->urand.number(); \
149 c_dfad = FUNC (a_dfad,val); \
150 c_fad = FUNC (a_fad,val); \
151 COMPARE_FADS(c_dfad, c_fad); \
153 c_dfad = FUNC (val,b_dfad); \
154 c_fad = FUNC (val,b_fad); \
155 COMPARE_FADS(c_dfad, c_fad); \
158 #define UNARY_OP_TEST(FIXTURENAME,TESTNAME,OP) \
159 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
160 auto a_dfad = this->a_dfad_; \
161 auto c_dfad = this->c_dfad_; \
162 auto a_fad = this->a_fad_; \
163 auto c_fad = this->c_fad_; \
164 c_dfad = OP a_dfad; \
166 COMPARE_FADS(c_dfad, c_fad); \
169 #define UNARY_FUNC_TEST(FIXTURENAME,TESTNAME,FUNC) \
170 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
171 auto a_dfad = this->a_dfad_; \
172 auto c_dfad = this->c_dfad_; \
173 auto a_fad = this->a_fad_; \
174 auto c_fad = this->c_fad_; \
175 c_dfad = FUNC (a_dfad); \
176 c_fad = FUNC (a_fad); \
177 COMPARE_FADS(c_dfad, c_fad); \
180 #define UNARY_ASSIGNOP_TEST(FIXTURENAME,TESTNAME,OP) \
181 TYPED_TEST_P(FIXTURENAME, TESTNAME){ \
182 auto a_dfad = this->a_dfad_; \
183 auto b_dfad = this->b_dfad_; \
184 auto c_dfad = this->c_dfad_; \
185 auto a_fad = this->a_fad_; \
186 auto b_fad = this->b_fad_; \
187 auto c_fad = this->c_fad_; \
192 COMPARE_FADS(c_dfad, c_fad); \
194 double val = this->urand.number(); \
197 COMPARE_FADS(c_dfad, c_fad); \
207 RELOP_TEST(FadOpsUnitTest, testLessThanOrEquals, <=)
208 RELOP_TEST(FadOpsUnitTest, testGreaterThanOrEquals, >=)
210 RELOP_TEST(FadOpsUnitTest, testGreaterThan, >)
239 typedef decltype(this->a_dfad_)
FadType;
244 auto a_dfad = this->a_dfad_;
245 auto b_dfad = this->b_dfad_;
246 auto c_dfad = this->c_dfad_;
247 auto a_fad = this->a_fad_;
248 auto b_fad = this->b_fad_;
249 auto c_fad = this->c_fad_;
251 FadType aa_dfad = a_dfad + 1.0;
252 c_dfad =
max(aa_dfad, a_dfad);
254 for (
int i=0;
i<this->
n;
i++) {
259 c_dfad =
max(a_dfad, aa_dfad);
261 for (
int i=0;
i<this->n;
i++) {
266 c_dfad =
max(a_dfad+1.0, a_dfad);
268 for (
int i=0;
i<this->n;
i++) {
273 c_dfad =
max(a_dfad, a_dfad+1.0);
275 for (
int i=0;
i<this->n;
i++) {
280 val = a_dfad.val() + 1;
281 c_dfad =
max(a_dfad, val);
283 for (
int i=0;
i<this->n;
i++)
286 val = a_dfad.val() - 1;
287 c_dfad =
max(a_dfad, val);
289 for (
int i=0;
i<this->n;
i++) {
294 val = b_dfad.val() + 1;
295 c_dfad =
max(val, b_dfad);
297 for (
int i=0;
i<this->n;
i++)
300 val = b_dfad.val() - 1;
301 c_dfad =
max(val, b_dfad);
303 for (
int i=0;
i<this->n;
i++) {
310 typedef decltype(this->a_dfad_)
FadType;
315 auto a_dfad = this->a_dfad_;
316 auto b_dfad = this->b_dfad_;
317 auto c_dfad = this->c_dfad_;
318 auto a_fad = this->a_fad_;
319 auto b_fad = this->b_fad_;
320 auto c_fad = this->c_fad_;
322 FadType aa_dfad = a_dfad - 1.0;
323 c_dfad =
min(aa_dfad, a_dfad);
325 for (
int i=0;
i<this->
n;
i++) {
330 c_dfad =
min(a_dfad, aa_dfad);
332 for (
int i=0;
i<this->n;
i++) {
337 val = a_dfad.val() - 1;
338 c_dfad =
min(a_dfad, val);
340 for (
int i=0;
i<this->n;
i++)
343 val = a_dfad.val() + 1;
344 c_dfad =
min(a_dfad, val);
346 for (
int i=0;
i<this->n;
i++) {
351 val = b_dfad.val() - 1;
352 c_dfad =
min(val, b_dfad);
354 for (
int i=0;
i<this->n;
i++)
357 val = b_dfad.val() + 1;
358 c_dfad =
min(val, b_dfad);
360 for (
int i=0;
i<this->n;
i++) {
367 auto a_dfad = this->a_dfad_;
368 auto b_dfad = this->b_dfad_;
369 auto c_dfad = this->c_dfad_;
370 auto a_fad = this->a_fad_;
371 auto b_fad = this->b_fad_;
372 auto c_fad = this->c_fad_;
374 c_dfad = this->composite1(a_dfad, b_dfad);
375 c_fad = this->composite1(a_fad, b_fad);
380 typedef decltype(this->a_dfad_)
FadType;
383 auto a_dfad = this->a_dfad_;
384 auto b_dfad = this->b_dfad_;
385 auto a_fad = this->a_fad_;
386 auto b_fad = this->b_fad_;
388 FadType aa_dfad = a_dfad;
389 FAD::Fad<ScalarType> aa_fad = a_fad;
392 aa_dfad = aa_dfad + b_dfad;
393 aa_fad = aa_fad + b_fad;
398 typedef decltype(this->a_dfad_)
FadType;
401 auto a_dfad = this->a_dfad_;
402 auto b_dfad = this->b_dfad_;
403 auto a_fad = this->a_fad_;
404 auto b_fad = this->b_fad_;
406 FadType aa_dfad = a_dfad;
407 FAD::Fad<ScalarType> aa_fad = a_fad;
410 aa_dfad = aa_dfad - b_dfad;
411 aa_fad = aa_fad - b_fad;
416 typedef decltype(this->a_dfad_)
FadType;
419 auto a_dfad = this->a_dfad_;
420 auto b_dfad = this->b_dfad_;
421 auto a_fad = this->a_fad_;
422 auto b_fad = this->b_fad_;
424 FadType aa_dfad = a_dfad;
425 FAD::Fad<ScalarType> aa_fad = a_fad;
428 aa_dfad = aa_dfad * b_dfad;
429 aa_fad = aa_fad * b_fad;
434 typedef decltype(this->a_dfad_)
FadType;
437 auto a_dfad = this->a_dfad_;
438 auto b_dfad = this->b_dfad_;
439 auto a_fad = this->a_fad_;
440 auto b_fad = this->b_fad_;
442 FadType aa_dfad = a_dfad;
443 FAD::Fad<ScalarType> aa_fad = a_fad;
446 aa_dfad = aa_dfad / b_dfad;
447 aa_fad = aa_fad / b_fad;
453 typedef decltype(this->a_dfad_)
FadType;
459 for (
int i=0;
i<this->
n; ++
i)
460 a.fastAccessDx(
i) = this->urand.number();
464 for (
int i=0;
i<this->n; ++
i)
465 cc.fastAccessDx(
i) = b.val()*
pow(a.val(),b.val()-1)*a.dx(
i);
476 for (
int i=0;
i<this->n; ++
i)
477 cc.fastAccessDx(
i) = 0.0;
489 for (
int i=0;
i<this->n; ++
i)
490 cc.fastAccessDx(
i) = 0.0;
501 for (
int i=0;
i<this->n; ++
i)
502 cc.fastAccessDx(
i) = 0.0;
538 testLessThanOrEquals,
539 testGreaterThanOrEquals,
573 #endif // FADUNITTESTS_HPP
REGISTER_TYPED_TEST_SUITE_P(FadBLASUnitTests, testSCAL1, testSCAL2, testSCAL3, testSCAL4, testCOPY1, testCOPY2, testCOPY3, testCOPY4, testAXPY1, testAXPY2, testAXPY3, testAXPY4, testDOT1, testDOT2, testDOT3, testDOT4, testNRM21, testNRM22, testGEMV1, testGEMV2, testGEMV3, testGEMV4, testGEMV5, testGEMV6, testGEMV7, testGEMV8, testGEMV9, testTRMV1, testTRMV2, testTRMV3, testTRMV4, testGER1, testGER2, testGER3, testGER4, testGER5, testGER6, testGER7, testGEMM1, testGEMM2, testGEMM3, testGEMM4, testGEMM5, testGEMM6, testGEMM7, testGEMM8, testGEMM9, testGEMM10, testSYMM1, testSYMM2, testSYMM3, testSYMM4, testSYMM5, testSYMM6, testSYMM7, testSYMM8, testSYMM9, testTRMM1, testTRMM2, testTRMM3, testTRMM4, testTRMM5, testTRMM6, testTRMM7, testTRSM1, testTRSM2, testTRSM3, testTRSM4, testTRSM5, testTRSM6, testTRSM7)
FAD::Fad< ScalarType > c_fad_
TYPED_TEST_P(FadBLASUnitTests, testSCAL1)
#define COMPARE_VALUES(a, b)
Sacado::Fad::DFad< double > FadType
#define UNARY_OP_TEST(FIXTURENAME, TESTNAME, OP)
#define BINARY_OP_TEST(FIXTURENAME, TESTNAME, OP)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
#define UNARY_ASSIGNOP_TEST(FIXTURENAME, TESTNAME, OP)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
Sacado::Random< ScalarType > urand
#define BINARY_FUNC_TEST(FIXTURENAME, TESTNAME, FUNC)
Sacado::ScalarType< FadType >::type ScalarType
#define UNARY_FUNC_TEST(FIXTURENAME, TESTNAME, FUNC)
ScalarT composite1(const ScalarT &a, const ScalarT &b)
TYPED_TEST_SUITE_P(FadBLASUnitTests)
FAD::Fad< ScalarType > a_fad_
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SACADO_INLINE_FUNCTION mpl::enable_if_c< ExprLevel< Expr< T1 > >::value==ExprLevel< Expr< T2 > >::value, Expr< PowerOp< Expr< T1 >, Expr< T2 > > > >::type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
A random number generator that generates random numbers uniformly distributed in the interval (a...
#define COMPARE_FADS(a, b)
FAD::Fad< ScalarType > b_fad_
#define RELOP_TEST(FIXTURENAME, TESTNAME, OP)
Base template specification for testing whether type is statically sized.