10 #ifndef TAYLORUNITTESTS_HPP
11 #define TAYLORUNITTESTS_HPP
14 #include "adolc/adouble.h"
15 #include "adolc/interfaces.h"
16 #include "adolc/taping.h"
22 inline adouble
max(
const adouble&
a,
const adouble& b) {
return fmax(a,b); }
23 inline adouble
max(
const adouble&
a,
double v) {
return fmax(a,v); }
24 inline adouble
max(
double v,
const adouble& b) {
return fmax(v,b); }
25 inline adouble
min(
const adouble&
a,
const adouble& b) {
return fmin(a,b); }
26 inline adouble
min(
const adouble&
a,
double v) {
return fmin(a,v); }
27 inline adouble
min(
double v,
const adouble& b) {
return fmin(v,b); }
34 #define COMPARE_POLYS(x_dtay, x_adolc) \
35 ASSERT_TRUE(x_dtay.degree() == d); \
36 for (int i=0; i<=d; i++) { \
37 COMPARE_VALUES(x_dtay.coeff(i), x_adolc[i]); \
41 #define COMPARE_TAYS(x_dtay, y_dtay) \
42 ASSERT_TRUE(x_dtay.degree() == y_dtay.degree()); \
43 for (int i=0; i<=x_dtay.degree(); i++) { \
44 COMPARE_VALUES(x_dtay.coeff(i), y_dtay.coeff(i)); \
49 template <
class TaylorType>
72 X_[0] =
new double[
d_+1];
73 X_[1] =
new double[
d_+1];
76 Y_[0] =
new double[
d_+1];
95 for (
int i=0;
i<=
d_;
i++) {
110 template <
typename ScalarT>
112 ScalarT t1 = 3. * a +
sin(b) /
log(
fabs(a - b * 7.));
118 t1 /=
cosh(b - 0.7) + 7.*
sinh(t1 + 0.8)*
tanh(9./(a+1.)) - 9.;
153 template <
typename TaylorType>
163 #define BINARY_OP2_TEST(FIXTURENAME,TESTNAME,OP) \
164 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
165 auto a_dtay = this->a_dtay_; \
166 auto b_dtay = this->b_dtay_; \
167 auto c_dtay = this->c_dtay_; \
171 c_dtay = a_dtay OP b_dtay; \
173 adouble aa, ab, ac; \
179 forward(0,1,2,d,0,X,Y); \
180 COMPARE_POLYS(c_dtay,Y[0]); \
183 #define BINARY_OPRC_TEST(FIXTURENAME,TESTNAME,OP) \
184 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
185 auto a_dtay = this->a_dtay_; \
186 auto c_dtay = this->c_dtay_; \
190 double val = this->urand.number(); \
191 c_dtay = a_dtay OP val; \
198 forward(0,1,1,d,0,X,Y); \
199 COMPARE_POLYS(c_dtay,Y[0]); \
202 #define BINARY_OPLC_TEST(FIXTURENAME,TESTNAME,OP) \
203 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
204 auto a_dtay = this->a_dtay_; \
205 auto c_dtay = this->c_dtay_; \
209 double val = this->urand.number(); \
210 c_dtay = val OP a_dtay; \
217 forward(0,1,1,d,0,X,Y); \
218 COMPARE_POLYS(c_dtay,Y[0]); \
221 #define BINARY_OP_TEST(FIXTURENAME,TESTNAME,OP) \
222 BINARY_OP2_TEST(FIXTURENAME,TESTNAME,OP) \
223 BINARY_OPLC_TEST(FIXTURENAME,TESTNAME ## LeftConstant,OP) \
224 BINARY_OPRC_TEST(FIXTURENAME,TESTNAME ## RightConstant,OP)
226 #define RELOP_OP2_TEST(FIXTURENAME,TESTNAME,OP) \
227 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
228 auto a_dtay = this->a_dtay_; \
229 auto b_dtay = this->b_dtay_; \
230 bool r1 = a_dtay OP b_dtay; \
231 bool r2 = a_dtay.coeff(0) OP b_dtay.coeff(0); \
232 ASSERT_TRUE(r1 == r2); \
235 #define RELOP_OPLC_TEST(FIXTURENAME,TESTNAME,OP) \
236 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
237 auto b_dtay = this->b_dtay_; \
238 double val = this->urand.number(); \
239 bool r1 = val OP b_dtay; \
240 bool r2 = val OP b_dtay.coeff(0); \
241 ASSERT_TRUE(r1 == r2); \
244 #define RELOP_OPRC_TEST(FIXTURENAME,TESTNAME,OP) \
245 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
246 auto a_dtay = this->b_dtay_; \
247 double val = this->urand.number(); \
248 bool r1 = a_dtay OP val; \
249 bool r2 = a_dtay.coeff(0) OP val; \
250 ASSERT_TRUE(r1 == r2); \
253 #define RELOP_OP_TEST(FIXTURENAME,TESTNAME,OP) \
254 RELOP_OP2_TEST(FIXTURENAME,TESTNAME,OP) \
255 RELOP_OPLC_TEST(FIXTURENAME,TESTNAME ## LeftConstant,OP) \
256 RELOP_OPRC_TEST(FIXTURENAME,TESTNAME ## RightConstant,OP)
258 #define BINARY_FUNC2_TEST(FIXTURENAME,TESTNAME,FUNC) \
259 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
260 auto a_dtay = this->a_dtay_; \
261 auto b_dtay = this->b_dtay_; \
262 auto c_dtay = this->c_dtay_; \
266 c_dtay = FUNC (a_dtay, b_dtay); \
268 adouble aa, ab, ac; \
271 ac = FUNC (aa, ab); \
274 forward(0,1,2,d,0,X,Y); \
275 COMPARE_POLYS(c_dtay,Y[0]); \
278 #define BINARY_FUNCRC_TEST(FIXTURENAME,TESTNAME,FUNC) \
279 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
280 auto a_dtay = this->a_dtay_; \
281 auto c_dtay = this->c_dtay_; \
285 double val = this->urand.number(); \
286 c_dtay = FUNC (a_dtay, val); \
290 ac = FUNC (aa, val); \
293 forward(0,1,1,d,0,X,Y); \
294 COMPARE_POLYS(c_dtay,Y[0]); \
297 #define BINARY_FUNCLC_TEST(FIXTURENAME,TESTNAME,FUNC) \
298 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
299 auto a_dtay = this->a_dtay_; \
300 auto c_dtay = this->c_dtay_; \
304 double val = this->urand.number(); \
305 c_dtay = FUNC (val, a_dtay); \
309 ac = FUNC (val, aa); \
312 forward(0,1,1,d,0,X,Y); \
313 COMPARE_POLYS(c_dtay,Y[0]); \
316 #define BINARY_FUNC_TEST(FIXTURENAME,TESTNAME,FUNC) \
317 BINARY_FUNC2_TEST(FIXTURENAME,TESTNAME,FUNC) \
318 BINARY_FUNCLC_TEST(FIXTURENAME,TESTNAME ## LeftConstant,FUNC) \
319 BINARY_FUNCRC_TEST(FIXTURENAME,TESTNAME ## RightConstant,FUNC)
321 #define UNARY_OP_TEST(FIXTURENAME,TESTNAME,OP) \
322 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
323 auto a_dtay = this->a_dtay_; \
324 auto c_dtay = this->c_dtay_; \
328 c_dtay = OP a_dtay; \
335 forward(0,1,1,d,0,X,Y); \
336 COMPARE_POLYS(c_dtay,Y[0]); \
339 #define UNARY_FUNC_TEST(FIXTURENAME,TESTNAME,FUNC) \
340 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
341 auto a_dtay = this->a_dtay_; \
342 auto c_dtay = this->c_dtay_; \
346 c_dtay = FUNC (a_dtay); \
353 forward(0,1,1,d,0,X,Y); \
354 COMPARE_POLYS(c_dtay,Y[0]); \
357 #define UNARY_ASSIGNOP2_TEST(FIXTURENAME,TESTNAME,OP) \
358 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
359 auto a_dtay = this->a_dtay_; \
360 auto b_dtay = this->b_dtay_; \
361 auto c_dtay = this->c_dtay_; \
368 adouble aa, ab, ac; \
375 forward(0,1,2,d,0,X,Y); \
376 COMPARE_POLYS(c_dtay,Y[0]); \
379 #define UNARY_ASSIGNOPRC_TEST(FIXTURENAME,TESTNAME,OP) \
380 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
381 auto a_dtay = this->a_dtay_; \
382 auto c_dtay = this->c_dtay_; \
386 double val = this->urand.number(); \
396 forward(0,1,1,d,0,X,Y); \
397 COMPARE_POLYS(c_dtay,Y[0]); \
400 #define UNARY_ASSIGNOPLC_TEST(FIXTURENAME,TESTNAME,OP) \
401 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
402 auto a_dtay = this->a_dtay_; \
403 auto c_dtay = this->c_dtay_; \
407 double val = this->urand.number(); \
417 forward(0,1,1,d,0,X,Y); \
418 COMPARE_POLYS(c_dtay,Y[0]); \
421 #define UNARY_ASSIGNOP_TEST(FIXTURENAME,TESTNAME,OP) \
422 UNARY_ASSIGNOP2_TEST(FIXTURENAME,TESTNAME,OP) \
423 UNARY_ASSIGNOPLC_TEST(FIXTURENAME,TESTNAME ## LeftConstant,OP) \
424 UNARY_ASSIGNOPRC_TEST(FIXTURENAME,TESTNAME ## RightConstant,OP)
434 RELOP_OP_TEST(TaylorOpsUnitTest, testGreaterThanOrEquals, >=)
464 auto a_dtay = this->a_dtay_;
465 auto b_dtay = this->b_dtay_;
466 auto c_dtay = this->c_dtay_;
470 c_dtay = this->composite1(a_dtay, b_dtay);
475 ac = this->composite1(aa,ab);
478 forward(0,1,2,d,0,X,Y);
484 auto a_dtay = this->a_dtay_;
486 TaylorType a_diff1 =
diff(a_dtay);
487 TaylorType a_diff2(d-1, 0.0);
488 for (
int i=1;
i<=d; ++
i)
495 auto a_dtay = this->a_dtay_;
496 TaylorType a_diff1 =
diff(a_dtay, 3);
504 testAdditionLeftConstant,
505 testAdditionRightConstant,
507 testSubtractionLeftConstant,
508 testSubtractionRightConstant,
510 testMultiplicationLeftConstant,
511 testMultiplicationRightConstant,
513 testDivisionLeftConstant,
514 testDivisionRightConstant,
516 testEqualsLeftConstant,
517 testEqualsRightConstant,
519 testNotEqualsLeftConstant,
520 testNotEqualsRightConstant,
521 testLessThanOrEquals,
522 testLessThanOrEqualsLeftConstant,
523 testLessThanOrEqualsRightConstant,
524 testGreaterThanOrEquals,
525 testGreaterThanOrEqualsLeftConstant,
526 testGreaterThanOrEqualsRightConstant,
528 testLessThanLeftConstant,
529 testLessThanRightConstant,
531 testGreaterThanLeftConstant,
532 testGreaterThanRightConstant,
550 testPlusEqualsLeftConstant,
551 testPlusEqualsRightConstant,
553 testMinusEqualsLeftConstant,
554 testMinusEqualsRightConstant,
556 testTimesEqualsLeftConstant,
557 testTimesEqualsRightConstant,
559 testDivideEqualsLeftConstant,
560 testDivideEqualsRightConstant,
563 testPowRightConstant,
572 TaylorMaxMinUnitTest,
575 testMaxRightConstant,
578 testMinRightConstant);
580 #endif // TAYLORUNITTESTS_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)
TYPED_TEST_P(FadBLASUnitTests, testSCAL1)
#define RELOP_OP_TEST(FIXTURENAME, TESTNAME, OP)
Sacado::Random< double > urand
#define COMPARE_TAYS(x_dtay, y_dtay)
ScalarT number()
Get random number.
Sacado::Tay::Taylor< double > TaylorType
#define UNARY_OP_TEST(FIXTURENAME, TESTNAME, OP)
ScalarT composite1(const ScalarT &a, const ScalarT &b)
CacheTaylor< T > diff(const CacheTaylor< T > &x, int n=1)
Compute Taylor series of n-th derivative of x.
T & fastAccessCoeff(int i)
Returns degree i term without bounds checking.
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
#define UNARY_ASSIGNOP_TEST(FIXTURENAME, TESTNAME, OP)
#define COMPARE_POLYS(x_dtay, x_adolc)
#define BINARY_FUNC_TEST(FIXTURENAME, TESTNAME, FUNC)
#define BINARY_OP_TEST(FIXTURENAME, TESTNAME, OP)
TYPED_TEST_SUITE_P(FadBLASUnitTests)
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)
#define UNARY_FUNC_TEST(FIXTURENAME, TESTNAME, FUNC)