Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
NestedFadUnitTests.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Sacado Package
5// Copyright (2006) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// This library is free software; you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as
12// published by the Free Software Foundation; either version 2.1 of the
13// License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23// USA
24// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25// (etphipp@sandia.gov).
26//
27// ***********************************************************************
28// @HEADER
29
30#ifndef NESTED_FADUNITTESTS_HPP
31#define NESTED_FADUNITTESTS_HPP
32
33// Sacado includes
34#include "Sacado_No_Kokkos.hpp"
35#include "Sacado_Random.hpp"
36
37// Fad includes
38#include "Fad/fad.h"
39
40// gtest includes
41#include <gtest/gtest.h>
42
43#include "GTestUtils.hpp"
44
45// A class for testing each Fad operation
46template <class FadFadType>
48protected:
51
52 // DFad variables
53 FadFadType a_dfad_, b_dfad_, c_dfad_;
54
55 // Fad variables
56 FAD::Fad<FadType> a_fad_, b_fad_, c_fad_;
57
58 // Random number generator
60
61 // Number of derivative components
62 int n1, n2;
63
64 // Tolerances to which fad objects should be the same
66
67 // Set the random number generator with a specific seed to prevent NaN's
68 // in the second derivatives, likely due to overflow
70 urand(0.0, 1.0, 123456), n1(5), n2(3), tol_a(1.0e-15), tol_r(1.0e-14) {}
71
72 void SetUp() override {
74
75 val = urand.number();
76 a_dfad_ = FadFadType(n1,FadType(n2,val));
77 a_fad_ = FAD::Fad<FadType>(n1,FadType(n2,val));
78
79 val = urand.number();
80 b_dfad_ = FadFadType(n1,FadType(n2,val));
81 b_fad_ = FAD::Fad<FadType>(n1,FadType(n2,val));
82
83 for (int j=0; j<n2; j++) {
84 ScalarType val2;
85 val2 = urand.number();
86 a_dfad_.val().fastAccessDx(j) = val2;
87 a_fad_.val().fastAccessDx(j) = val2;
88
89 val2 = urand.number();
90 b_dfad_.val().fastAccessDx(j) = val2;
91 b_fad_.val().fastAccessDx(j) = val2;
92 }
93
94 for (int i=0; i<n1; i++) {
95 val = urand.number();
96 a_dfad_.fastAccessDx(i) = FadType(n2,val);
97 a_fad_.fastAccessDx(i) = FadType(n2,val);
98
99 val = urand.number();
100 b_dfad_.fastAccessDx(i) = FadType(n2,val);
101 b_fad_.fastAccessDx(i) = FadType(n2,val);
102
103 for (int j=0; j<n2; j++) {
104 ScalarType val2;
105 val2 = urand.number();
106 a_dfad_.fastAccessDx(i).fastAccessDx(j) = val2;
107 a_fad_.fastAccessDx(i).fastAccessDx(j) = val2;
108
109 val2 = urand.number();
110 b_dfad_.fastAccessDx(i).fastAccessDx(j) = val2;
111 b_fad_.fastAccessDx(i).fastAccessDx(j) = val2;
112 }
113 }
114
115 val = 0.0;
116 c_dfad_ = FadFadType(n1, FadType(n2,val));
117 c_fad_ = FAD::Fad<FadType>(n1,FadType(n2,val));
118 }
119
120 void TearDown() override {}
121
122 template <typename ScalarT>
123 ScalarT composite1(const ScalarT& a, const ScalarT& b) {
124 ScalarT t1 = 3. * a + sin(b) / log(fabs(a - b * 7.));
125 ScalarT t2 = 1.0e3;
126 ScalarT t3 = 5.7e4;
127 ScalarT t4 = 3.2e5;
128 t1 *= cos(a + exp(t1)) / 6. - tan(t1*sqrt(abs(a * log10(abs(b)))));
129 t1 -= acos((6.+asin(pow(fabs(a),b)/t2))/t3) * asin(pow(fabs(b),2.)*1.0/t4) * atan((b*pow(2.,log(abs(a))))/(t3*t4));
130 t1 /= cosh(b - 0.7) + 7.*sinh(t1 + 0.8)*tanh(9./a) - 9.;
131 t1 += pow(abs(a*4.),b-8.)/cos(a*b*a);
132
133 return t1;
134 }
135
136 template <typename ScalarT>
137 ScalarT composite1_fad(const ScalarT& a, const ScalarT& b) {
138 ScalarT t1 = FadType(3.) * a + sin(b) / log(fabs(a - b * FadType(7.)));
139 ScalarT t2 = FadType(1.0e3);
140 ScalarT t3 = FadType(7e4);
141 ScalarT t4 = FadType(3.2e5);
142 t1 *= cos(a + exp(t1)) / FadType(6.) - tan(t1*sqrt(abs(a * log10(abs(b)))));
143 t1 -= acos((FadType(6.)+asin(pow(fabs(a),b)/t2))/t3) * asin(pow(fabs(b),FadType(2.))*FadType(1.0)/t4) * atan((b*pow(FadType(2.),log(abs(a))))/(t3*t4));
144 t1 /= cosh(b - FadType(0.7)) + FadType(7.)*sinh(t1 + FadType(0.8))*tanh(FadType(9.)/a) - FadType(9.);
145 t1 += pow(abs(a*FadType(4.)),b-FadType(8.))/cos(a*b*a);
146
147 return t1;
148 }
149
150}; // class FadFadOpsUnitTest
151
153
154#define BINARY_OP_TEST(FIXTURENAME,TESTNAME,OP) \
155 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
156 typedef decltype(this->a_dfad_) FadFadType; \
157 typedef typename Sacado::ValueType<FadFadType>::type FadType; \
158 auto a_dfad = this->a_dfad_; \
159 auto b_dfad = this->b_dfad_; \
160 auto c_dfad = this->c_dfad_; \
161 auto a_fad = this->a_fad_; \
162 auto b_fad = this->b_fad_; \
163 auto c_fad = this->c_fad_; \
164 c_dfad = a_dfad OP b_dfad; \
165 c_fad = a_fad OP b_fad; \
166 COMPARE_NESTED_FADS(c_dfad, c_fad); \
167 \
168 double val = this->urand.number(); \
169 c_dfad = a_dfad OP val; \
170 c_fad = a_fad OP FadType(val); \
171 COMPARE_NESTED_FADS(c_dfad, c_fad); \
172 \
173 c_dfad = val OP b_dfad; \
174 c_fad = FadType(val) OP b_fad; \
175 COMPARE_NESTED_FADS(c_dfad, c_fad); \
176 }
177
178#define RELOP_TEST(FIXTURENAME,TESTNAME,OP) \
179 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
180 typedef decltype(this->a_dfad_) FadFadType; \
181 typedef typename Sacado::ValueType<FadFadType>::type FadType; \
182 auto a_dfad = this->a_dfad_; \
183 auto b_dfad = this->b_dfad_; \
184 auto a_fad = this->a_fad_; \
185 auto b_fad = this->b_fad_; \
186 bool r1 = a_dfad OP b_dfad; \
187 bool r2 = a_fad OP b_fad; \
188 ASSERT_TRUE(r1 == r2); \
189 \
190 double val = this->urand.number(); \
191 r1 = a_dfad OP val; \
192 r2 = a_fad OP FadType(val); \
193 ASSERT_TRUE(r1 == r2); \
194 \
195 r1 = val OP b_dfad; \
196 r2 = FadType(val) OP b_fad; \
197 ASSERT_TRUE(r1 == r2); \
198 }
199
200#define BINARY_FUNC_TEST(FIXTURENAME,TESTNAME,FUNC) \
201 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
202 typedef decltype(this->a_dfad_) FadFadType; \
203 typedef typename Sacado::ValueType<FadFadType>::type FadType; \
204 auto a_dfad = this->a_dfad_; \
205 auto b_dfad = this->b_dfad_; \
206 auto c_dfad = this->c_dfad_; \
207 auto a_fad = this->a_fad_; \
208 auto b_fad = this->b_fad_; \
209 auto c_fad = this->c_fad_; \
210 c_dfad = FUNC (a_dfad,b_dfad); \
211 c_fad = FUNC (a_fad,b_fad); \
212 COMPARE_NESTED_FADS(c_dfad, c_fad); \
213 \
214 double val = this->urand.number(); \
215 c_dfad = FUNC (a_dfad,val); \
216 c_fad = FUNC (a_fad,FadType(val)); \
217 COMPARE_NESTED_FADS(c_dfad, c_fad); \
218 \
219 c_dfad = FUNC (val,b_dfad); \
220 c_fad = FUNC (FadType(val),b_fad); \
221 COMPARE_NESTED_FADS(c_dfad, c_fad); \
222 }
223
224#define UNARY_OP_TEST(FIXTURENAME,TESTNAME,OP) \
225 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
226 auto a_dfad = this->a_dfad_; \
227 auto c_dfad = this->c_dfad_; \
228 auto a_fad = this->a_fad_; \
229 auto c_fad = this->c_fad_; \
230 c_dfad = OP a_dfad; \
231 c_fad = OP a_fad; \
232 COMPARE_NESTED_FADS(c_dfad, c_fad); \
233 }
234
235#define UNARY_FUNC_TEST(FIXTURENAME,TESTNAME,FUNC) \
236 TYPED_TEST_P(FIXTURENAME, TESTNAME) { \
237 auto a_dfad = this->a_dfad_; \
238 auto c_dfad = this->c_dfad_; \
239 auto a_fad = this->a_fad_; \
240 auto c_fad = this->c_fad_; \
241 c_dfad = FUNC (a_dfad); \
242 c_fad = FUNC (a_fad); \
243 COMPARE_NESTED_FADS(c_dfad, c_fad); \
244 }
245
246#define UNARY_ASSIGNOP_TEST(FIXTURENAME,TESTNAME,OP) \
247 TYPED_TEST_P(FIXTURENAME, TESTNAME){ \
248 auto a_dfad = this->a_dfad_; \
249 auto b_dfad = this->b_dfad_; \
250 auto c_dfad = this->c_dfad_; \
251 auto a_fad = this->a_fad_; \
252 auto b_fad = this->b_fad_; \
253 auto c_fad = this->c_fad_; \
254 c_dfad = b_dfad; \
255 c_fad = b_fad; \
256 c_dfad OP a_dfad; \
257 c_fad OP a_fad; \
258 COMPARE_NESTED_FADS(c_dfad, c_fad); \
259 \
260 double val = this->urand.number(); \
261 c_dfad OP val; \
262 c_fad OP val; \
263 COMPARE_NESTED_FADS(c_dfad, c_fad); \
264 }
265
266BINARY_OP_TEST(FadFadOpsUnitTest, testAddition, +)
267BINARY_OP_TEST(FadFadOpsUnitTest, testSubtraction, -)
268BINARY_OP_TEST(FadFadOpsUnitTest, testMultiplication, *)
269BINARY_OP_TEST(FadFadOpsUnitTest, testDivision, /)
270
271RELOP_TEST(FadFadOpsUnitTest, testEquals, ==)
272RELOP_TEST(FadFadOpsUnitTest, testNotEquals, !=)
273RELOP_TEST(FadFadOpsUnitTest, testLessThanOrEquals, <=)
274RELOP_TEST(FadFadOpsUnitTest, testGreaterThanOrEquals, >=)
275RELOP_TEST(FadFadOpsUnitTest, testLessThan, <)
276RELOP_TEST(FadFadOpsUnitTest, testGreaterThan, >)
277
279
280UNARY_OP_TEST(FadFadOpsUnitTest, testUnaryPlus, +)
281UNARY_OP_TEST(FadFadOpsUnitTest, testUnaryMinus, -)
282
285UNARY_FUNC_TEST(FadFadOpsUnitTest, testLog10, log10)
286UNARY_FUNC_TEST(FadFadOpsUnitTest, testSqrt, sqrt)
290UNARY_FUNC_TEST(FadFadOpsUnitTest, testACos, acos)
291UNARY_FUNC_TEST(FadFadOpsUnitTest, testASin, asin)
292UNARY_FUNC_TEST(FadFadOpsUnitTest, testATan, atan)
293UNARY_FUNC_TEST(FadFadOpsUnitTest, testCosh, cosh)
294UNARY_FUNC_TEST(FadFadOpsUnitTest, testSinh, sinh)
295UNARY_FUNC_TEST(FadFadOpsUnitTest, testTanh, tanh)
297UNARY_FUNC_TEST(FadFadOpsUnitTest, testFAbs, fabs)
298
299UNARY_ASSIGNOP_TEST(FadFadOpsUnitTest, testPlusEquals, +=)
300UNARY_ASSIGNOP_TEST(FadFadOpsUnitTest, testMinusEquals, -=)
301UNARY_ASSIGNOP_TEST(FadFadOpsUnitTest, testTimesEquals, *=)
302UNARY_ASSIGNOP_TEST(FadFadOpsUnitTest, testDivideEquals, /=)
303
305 typedef decltype(this->a_dfad_) FadFadType;
307
308 FadType val;
309
310 auto a_dfad = this->a_dfad_;
311 auto b_dfad = this->b_dfad_;
312 auto c_dfad = this->c_dfad_;
313 auto a_fad = this->a_fad_;
314 auto b_fad = this->b_fad_;
315 auto c_fad = this->c_fad_;
316
317 FadFadType aa_dfad = a_dfad + 1.0;
318 c_dfad = max(aa_dfad, a_dfad);
319 COMPARE_FADS(c_dfad.val(), aa_dfad.val());
320 for (int i=0; i<this->n1; i++) {
321 COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
322 COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
323 }
324
325 c_dfad = max(a_dfad, aa_dfad);
326 COMPARE_FADS(c_dfad.val(), aa_dfad.val());
327 for (int i=0; i<this->n1; i++) {
328 COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
329 COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
330 }
331
332 c_dfad = max(a_dfad+1.0, a_dfad);
333 COMPARE_FADS(c_dfad.val(), aa_dfad.val());
334 for (int i=0; i<this->n1; i++) {
335 COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
336 COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
337 }
338
339 c_dfad = max(a_dfad, a_dfad+1.0);
340 COMPARE_FADS(c_dfad.val(), aa_dfad.val());
341 for (int i=0; i<this->n1; i++) {
342 COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
343 COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
344 }
345
346 val = a_dfad.val() + 1;
347 c_dfad = max(a_dfad, val);
348 COMPARE_FADS(c_dfad.val(), val);
349 for (int i=0; i<this->n1; i++) {
350 COMPARE_FADS(c_dfad.dx(i), FadType(0.0));
351 }
352
353 val = a_dfad.val() - 1;
354 c_dfad = max(a_dfad, val);
355 COMPARE_FADS(c_dfad.val(), a_dfad.val());
356 for (int i=0; i<this->n1; i++) {
357 COMPARE_FADS(c_dfad.dx(i), a_dfad.dx(i));
358 COMPARE_FADS(c_dfad.fastAccessDx(i), a_dfad.fastAccessDx(i));
359 }
360
361 val = b_dfad.val() + 1;
362 c_dfad = max(val, b_dfad);
363 COMPARE_FADS(c_dfad.val(), val);
364 for (int i=0; i<this->n1; i++) {
365 COMPARE_FADS(c_dfad.dx(i), FadType(0.0));
366 }
367
368 val = b_dfad.val() - 1;
369 c_dfad = max(val, b_dfad);
370 COMPARE_FADS(c_dfad.val(), b_dfad.val());
371 for (int i=0; i<this->n1; i++) {
372 COMPARE_FADS(c_dfad.dx(i), b_dfad.dx(i));
373 COMPARE_FADS(c_dfad.fastAccessDx(i), b_dfad.fastAccessDx(i));
374 }
375}
376
378 typedef decltype(this->a_dfad_) FadFadType;
380
381 FadType val;
382
383 auto a_dfad = this->a_dfad_;
384 auto b_dfad = this->b_dfad_;
385 auto c_dfad = this->c_dfad_;
386 auto a_fad = this->a_fad_;
387 auto b_fad = this->b_fad_;
388 auto c_fad = this->c_fad_;
389
390 FadFadType aa_dfad = a_dfad - 1.0;
391 c_dfad = min(aa_dfad, a_dfad);
392 COMPARE_FADS(c_dfad.val(), aa_dfad.val());
393 for (int i=0; i<this->n1; i++) {
394 COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
395 COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
396 }
397
398 c_dfad = min(a_dfad, aa_dfad);
399 COMPARE_FADS(c_dfad.val(), aa_dfad.val());
400 for (int i=0; i<this->n1; i++) {
401 COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
402 COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
403 }
404
405 val = a_dfad.val() - 1;
406 c_dfad = min(a_dfad, val);
407 COMPARE_FADS(c_dfad.val(), val);
408 for (int i=0; i<this->n1; i++) {
409 COMPARE_FADS(c_dfad.dx(i), FadType(0.0));
410 }
411
412 val = a_dfad.val() + 1;
413 c_dfad = min(a_dfad, val);
414 COMPARE_FADS(c_dfad.val(), a_dfad.val());
415 for (int i=0; i<this->n1; i++) {
416 COMPARE_FADS(c_dfad.dx(i), a_dfad.dx(i));
417 COMPARE_FADS(c_dfad.fastAccessDx(i), a_dfad.fastAccessDx(i));
418 }
419
420 val = b_dfad.val() - 1;
421 c_dfad = min(val, b_dfad);
422 COMPARE_FADS(c_dfad.val(), val);
423 for (int i=0; i<this->n1; i++) {
424 COMPARE_FADS(c_dfad.dx(i), FadType(0.0));
425 }
426
427 val = b_dfad.val() + 1;
428 c_dfad = min(val, b_dfad);
429 COMPARE_FADS(c_dfad.val(), b_dfad.val());
430 for (int i=0; i<this->n1; i++) {
431 COMPARE_FADS(c_dfad.dx(i), b_dfad.dx(i));
432 COMPARE_FADS(c_dfad.fastAccessDx(i), b_dfad.fastAccessDx(i));
433 }
434}
435
437 auto a_dfad = this->a_dfad_;
438 auto b_dfad = this->b_dfad_;
439 auto c_dfad = this->c_dfad_;
440 auto a_fad = this->a_fad_;
441 auto b_fad = this->b_fad_;
442 auto c_fad = this->c_fad_;
443
444 c_dfad = this->composite1(a_dfad, b_dfad);
445 c_fad = this->composite1_fad(a_fad, b_fad);
446 COMPARE_NESTED_FADS(c_dfad, c_fad);
447}
448
450 typedef decltype(this->a_dfad_) FadFadType;
452
453 auto a_dfad = this->a_dfad_;
454 auto b_dfad = this->b_dfad_;
455 auto a_fad = this->a_fad_;
456 auto b_fad = this->b_fad_;
457
458 FadFadType aa_dfad = a_dfad;
459 FAD::Fad< FadType > aa_fad = a_fad;
460 aa_dfad = 1.0;
461 aa_fad = FadType(1.0);
462 aa_dfad = aa_dfad + b_dfad;
463 aa_fad = aa_fad + b_fad;
464 COMPARE_NESTED_FADS(aa_dfad, aa_fad);
465}
466
468 typedef decltype(this->a_dfad_) FadFadType;
470
471 auto a_dfad = this->a_dfad_;
472 auto b_dfad = this->b_dfad_;
473 auto a_fad = this->a_fad_;
474 auto b_fad = this->b_fad_;
475
476 FadFadType aa_dfad = a_dfad;
477 FAD::Fad< FadType > aa_fad = a_fad;
478 aa_dfad = 1.0;
479 aa_fad = FadType(1.0);
480 aa_dfad = aa_dfad - b_dfad;
481 aa_fad = aa_fad - b_fad;
482 COMPARE_NESTED_FADS(aa_dfad, aa_fad);
483}
484
486 typedef decltype(this->a_dfad_) FadFadType;
488
489 auto a_dfad = this->a_dfad_;
490 auto b_dfad = this->b_dfad_;
491 auto a_fad = this->a_fad_;
492 auto b_fad = this->b_fad_;
493
494 FadFadType aa_dfad = a_dfad;
495 FAD::Fad< FadType > aa_fad = a_fad;
496 aa_dfad = 2.0;
497 aa_fad = FadType(2.0);
498 aa_dfad = aa_dfad * b_dfad;
499 aa_fad = aa_fad * b_fad;
500 COMPARE_NESTED_FADS(aa_dfad, aa_fad);
501}
502
504 typedef decltype(this->a_dfad_) FadFadType;
506
507 auto a_dfad = this->a_dfad_;
508 auto b_dfad = this->b_dfad_;
509 auto a_fad = this->a_fad_;
510 auto b_fad = this->b_fad_;
511
512 FadFadType aa_dfad = a_dfad;
513 FAD::Fad< FadType > aa_fad = a_fad;
514 aa_dfad = 2.0;
515 aa_fad = FadType(2.0);
516 aa_dfad = aa_dfad / b_dfad;
517 aa_fad = aa_fad / b_fad;
518 COMPARE_NESTED_FADS(aa_dfad, aa_fad);
519}
520
521 // Check various corner cases for pow()
523 typedef decltype(this->a_dfad_) FadFadType;
525 typedef typename Sacado::ScalarType<FadFadType>::type ScalarType;
526
527 auto a_dfad = this->a_dfad_;
528
529 FadFadType a, b, c, cc;
530
531 // Constant b
532 a = a_dfad;
533 b = 3.456;
534 c = pow(a, b);
535 ScalarType f = pow(a.val().val(), b.val().val());
536 ScalarType fp = b.val().val()*pow(a.val().val(),b.val().val()-1);
537 ScalarType fpp = b.val().val()*(b.val().val()-1)*pow(a.val().val(),b.val().val()-2);
538 cc = FadFadType(this->n1,FadType(this->n2,f));
539 for (int i=0; i<this->n2; ++i)
540 cc.val().fastAccessDx(i) = fp*a.val().dx(i);
541 for (int i=0; i<this->n1; ++i) {
542 cc.fastAccessDx(i) = FadType(this->n2,fp*a.dx(i).val());
543 for (int j=0; j<this->n2; ++j)
544 cc.fastAccessDx(i).fastAccessDx(j) = fpp*a.dx(i).val()*a.val().dx(j) + fp*a.dx(i).dx(j);
545 }
547
548 // Constant scalar b
549 c = pow(a, b.val());
551 c = pow(a, b.val().val());
553
554 // Constant b == 0
555 b = 0.0;
556 c = pow(a, b);
557 cc.val() = FadType(this->n2,1.0);
558 for (int i=0; i<this->n1; ++i)
559 cc.fastAccessDx(i) = 0.0;
561
562 // Constant scalar b == 0
563 c = pow(a, b.val());
564 cc.val() = FadType(this->n2,1.0);
565 for (int i=0; i<this->n1; ++i)
566 cc.fastAccessDx(i) = 0.0;
568 c = pow(a, b.val().val());
570
571 // a == 0 and constant b as a Fad
572 // This only works for DFad/SLFad, because there is no such thing as a
573 // constant SFad.
575 a.val() = 0.0;
576 b = 3.456;
577 c = pow(a, b);
578 cc.val() = 0.0;
579 for (int i=0; i<this->n1; ++i)
580 cc.fastAccessDx(i) = FadType(this->n2,0.0);
582 }
583
584 // a == 0 and constant scalar b
585 a.val() = 0.0;
586 b = 3.456;
587 c = pow(a, b.val());
588 cc.val() = 0.0;
589 for (int i=0; i<this->n1; ++i)
590 cc.fastAccessDx(i) = FadType(this->n2,0.0);
592 c = pow(a, b.val().val());
594
595 // a == 0 and b == 0
596 b = 0.0;
597 cc.val() = 1.0;
598 for (int i=0; i<this->n1; ++i)
599 cc.fastAccessDx(i) = 0.0;
601 c = pow(a, b);
603 c = pow(a, b.val());
605 }
606 c = pow(a, b.val().val());
608
609 // a nonzero and b == 2
610 a = a_dfad;
611 a.val().val() = 0.0;
612 b = 2.0;
613 c = pow(a, b);
614 f = pow(a.val().val(), b.val().val());
615 fp = b.val().val()*pow(a.val().val(),b.val().val()-1);
616 fpp = b.val().val()*(b.val().val()-1)*pow(a.val().val(),b.val().val()-2);
617 cc = FadFadType(this->n1,FadType(this->n2,f));
618 for (int i=0; i<this->n2; ++i)
619 cc.val().fastAccessDx(i) = fp*a.val().dx(i);
620 for (int i=0; i<this->n1; ++i) {
621 cc.fastAccessDx(i) = FadType(this->n2,fp*a.dx(i).val());
622 for (int j=0; j<this->n2; ++j)
623 cc.fastAccessDx(i).fastAccessDx(j) = fpp*a.dx(i).val()*a.val().dx(j) + fp*a.dx(i).dx(j);
624 }
625
626 // a.val().val() == 0 with a.val().dx() != 0
629 c = pow(a, b.val());
631 }
632 c = pow(a, b.val().val());
634
635 // a.val().val() == 0 and b == 1
636 b = 1.0;
637 c = pow(a, b);
638 cc = a;
641 c = pow(a, b.val());
643 }
644 c = pow(a, b.val().val());
646
647 // a.val().val() == 0 and b == 0
648 b = 0.0;
649 c = pow(a, b);
650 cc.val() = FadType(this->n2, 1.0);
651 for (int i=0; i<this->n1; ++i)
652 cc.fastAccessDx(i) = 0.0;
655 c = pow(a, b.val());
657 }
658 c = pow(a, b.val().val());
660
661 // a.val().val() == 0, b == 2, nested expression
662 c = pow(2.0*a,2.0);
663 cc = 4.0*a*a;
665}
666
669 testAddition,
670 testSubtraction,
671 testMultiplication,
672 testDivision,
673 testEquals,
674 testNotEquals,
675 testLessThanOrEquals,
676 testGreaterThanOrEquals,
677 testLessThan,
678 testGreaterThan,
679 testPow,
680 testUnaryPlus,
681 testUnaryMinus,
682 testExp,
683 testLog,
684 testLog10,
685 testSqrt,
686 testCos,
687 testSin,
688 testTan,
689 testACos,
690 testASin,
691 testATan,
692 testCosh,
693 testSinh,
694 testTanh,
695 testAbs,
696 testFAbs,
697 testPlusEquals,
698 testMinusEquals,
699 testTimesEquals,
700 testDivideEquals,
701 testMax,
702 testMin,
703 testComposite1,
704 testPlusLR,
705 testMinusLR,
706 testTimesLR,
707 testDivideLR,
708 testPowConstB);
709
710#endif // NESETD_FADUNITTESTS_HPP
#define COMPARE_FADS(a, b)
Definition: GTestUtils.hpp:112
#define COMPARE_NESTED_FADS(a, b)
Definition: GTestUtils.hpp:115
#define RELOP_TEST(FIXTURENAME, TESTNAME, OP)
#define UNARY_FUNC_TEST(FIXTURENAME, TESTNAME, FUNC)
#define UNARY_OP_TEST(FIXTURENAME, TESTNAME, OP)
TYPED_TEST_P(FadFadOpsUnitTest, testMax)
#define UNARY_ASSIGNOP_TEST(FIXTURENAME, TESTNAME, OP)
REGISTER_TYPED_TEST_SUITE_P(FadFadOpsUnitTest, testAddition, testSubtraction, testMultiplication, testDivision, testEquals, testNotEquals, testLessThanOrEquals, testGreaterThanOrEquals, testLessThan, testGreaterThan, testPow, testUnaryPlus, testUnaryMinus, testExp, testLog, testLog10, testSqrt, testCos, testSin, testTan, testACos, testASin, testATan, testCosh, testSinh, testTanh, testAbs, testFAbs, testPlusEquals, testMinusEquals, testTimesEquals, testDivideEquals, testMax, testMin, testComposite1, testPlusLR, testMinusLR, testTimesLR, testDivideLR, testPowConstB)
#define BINARY_FUNC_TEST(FIXTURENAME, TESTNAME, FUNC)
#define BINARY_OP_TEST(FIXTURENAME, TESTNAME, OP)
TYPED_TEST_SUITE_P(FadFadOpsUnitTest)
fabs(expr.val())
log(expr.val())
tan(expr.val())
abs(expr.val())
cos(expr.val())
cosh(expr.val())
acos(expr.val())
sin(expr.val())
sinh(expr.val())
log10(expr.val())
exp(expr.val())
atan(expr.val())
expr val()
sqrt(expr.val())
tanh(expr.val())
asin(expr.val())
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
Sacado::Fad::DFad< double > FadType
FAD::Fad< FadType > b_fad_
Sacado::ValueType< FadFadType >::type FadType
FAD::Fad< FadType > c_fad_
Sacado::ScalarType< FadFadType >::type ScalarType
void TearDown() override
FAD::Fad< FadType > a_fad_
ScalarT composite1(const ScalarT &a, const ScalarT &b)
ScalarT composite1_fad(const ScalarT &a, const ScalarT &b)
void SetUp() override
Sacado::Random< ScalarType > urand
A random number generator that generates random numbers uniformly distributed in the interval (a,...
Base template specification for testing whether type is statically sized.