Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // Cppunit includes
41 #include <cppunit/extensions/HelperMacros.h>
42 
43 #define COMPARE_VALUES(a, b) \
44  CPPUNIT_ASSERT( std::abs(a-b) < this->tol_a + this->tol_r*std::abs(a) );
45 
46 #define COMPARE_FADS(a, b) \
47 CPPUNIT_ASSERT(a.size() == b.size()); \
48 CPPUNIT_ASSERT(a.hasFastAccess() == b.hasFastAccess()); \
49 COMPARE_VALUES(a.val(), b.val()); \
50 for (int zz=0; zz<a.size(); zz++) { \
51  COMPARE_VALUES(a.dx(zz), b.dx(zz)); \
52  COMPARE_VALUES(a.fastAccessDx(zz), b.fastAccessDx(zz)); \
53  } \
54  ;
55 
56 #define COMPARE_NESTED_FADS(a, b) \
57 CPPUNIT_ASSERT(a.size() == b.size()); \
58 CPPUNIT_ASSERT(a.hasFastAccess() == b.hasFastAccess()); \
59 COMPARE_FADS(a.val(), b.val()); \
60 for (int z=0; z<a.size(); z++) { \
61  COMPARE_FADS(a.dx(z), b.dx(z)); \
62  COMPARE_FADS(a.fastAccessDx(z), b.fastAccessDx(z)); \
63  } \
64  ;
65 
66 #define BINARY_OP_TEST(TESTNAME,OP) \
67  void TESTNAME () { \
68  c_dfad = a_dfad OP b_dfad; \
69  c_fad = a_fad OP b_fad; \
70  COMPARE_NESTED_FADS(c_dfad, c_fad); \
71  \
72  double val = urand.number(); \
73  c_dfad = a_dfad OP val; \
74  c_fad = a_fad OP FadType(val); \
75  COMPARE_NESTED_FADS(c_dfad, c_fad); \
76  \
77  c_dfad = val OP b_dfad; \
78  c_fad = FadType(val) OP b_fad; \
79  COMPARE_NESTED_FADS(c_dfad, c_fad); \
80  }
81 
82 #define RELOP_TEST(TESTNAME,OP) \
83  void TESTNAME () { \
84  bool r1 = a_dfad OP b_dfad; \
85  bool r2 = a_fad OP b_fad; \
86  CPPUNIT_ASSERT(r1 == r2); \
87  \
88  double val = urand.number(); \
89  r1 = a_dfad OP val; \
90  r2 = a_fad OP FadType(val); \
91  CPPUNIT_ASSERT(r1 == r2); \
92  \
93  r1 = val OP b_dfad; \
94  r2 = FadType(val) OP b_fad; \
95  CPPUNIT_ASSERT(r1 == r2); \
96  }
97 
98 #define BINARY_FUNC_TEST(TESTNAME,FUNC) \
99  void TESTNAME () { \
100  c_dfad = FUNC (a_dfad,b_dfad); \
101  c_fad = FUNC (a_fad,b_fad); \
102  COMPARE_NESTED_FADS(c_dfad, c_fad); \
103  \
104  double val = urand.number(); \
105  c_dfad = FUNC (a_dfad,val); \
106  c_fad = FUNC (a_fad,FadType(val)); \
107  COMPARE_NESTED_FADS(c_dfad, c_fad); \
108  \
109  c_dfad = FUNC (val,b_dfad); \
110  c_fad = FUNC (FadType(val),b_fad); \
111  COMPARE_NESTED_FADS(c_dfad, c_fad); \
112  }
113 
114 #define UNARY_OP_TEST(TESTNAME,OP) \
115  void TESTNAME () { \
116  c_dfad = OP a_dfad; \
117  c_fad = OP a_fad; \
118  COMPARE_NESTED_FADS(c_dfad, c_fad); \
119  }
120 
121 #define UNARY_FUNC_TEST(TESTNAME,FUNC) \
122  void TESTNAME () { \
123  c_dfad = FUNC (a_dfad); \
124  c_fad = FUNC (a_fad); \
125  COMPARE_NESTED_FADS(c_dfad, c_fad); \
126  }
127 
128 #define UNARY_ASSIGNOP_TEST(TESTNAME,OP) \
129  void TESTNAME () { \
130  c_dfad OP a_dfad; \
131  c_fad OP a_fad; \
132  COMPARE_NESTED_FADS(c_dfad, c_fad); \
133  \
134  double val = urand.number(); \
135  c_dfad OP val; \
136  c_fad OP FadType(val); \
137  COMPARE_NESTED_FADS(c_dfad, c_fad); \
138  }
139 
140 // A class for testing each Fad operation
141 template <class FadFadType, class ScalarType>
142 class FadFadOpsUnitTest : public CppUnit::TestFixture {
143 
145 
146  CPPUNIT_TEST(testAddition);
147  CPPUNIT_TEST(testSubtraction);
148  CPPUNIT_TEST(testMultiplication);
149  CPPUNIT_TEST(testDivision);
150 
151  CPPUNIT_TEST(testEquals);
152  CPPUNIT_TEST(testNotEquals);
153  CPPUNIT_TEST(testLessThanOrEquals);
154  CPPUNIT_TEST(testGreaterThanOrEquals);
155  CPPUNIT_TEST(testLessThan);
156  CPPUNIT_TEST(testGreaterThan);
157 
158  CPPUNIT_TEST(testPow);
161 
162  CPPUNIT_TEST(testUnaryPlus);
163  CPPUNIT_TEST(testUnaryMinus);
164 
165  CPPUNIT_TEST(testExp);
166  CPPUNIT_TEST(testLog);
167  CPPUNIT_TEST(testLog10);
168  CPPUNIT_TEST(testSqrt);
169  CPPUNIT_TEST(testCos);
170  CPPUNIT_TEST(testSin);
171  CPPUNIT_TEST(testTan);
172  CPPUNIT_TEST(testACos);
173  CPPUNIT_TEST(testASin);
174  CPPUNIT_TEST(testATan);
175  CPPUNIT_TEST(testCosh);
176  CPPUNIT_TEST(testSinh);
177  CPPUNIT_TEST(testTanh);
178  CPPUNIT_TEST(testAbs);
179  CPPUNIT_TEST(testFAbs);
180 
181  CPPUNIT_TEST(testPlusEquals);
182  CPPUNIT_TEST(testMinusEquals);
183  CPPUNIT_TEST(testTimesEquals);
184  CPPUNIT_TEST(testDivideEquals);
185 
187 
192 
194 
196 
197 public:
198 
199  typedef typename FadFadType::value_type FadType;
200 
202 
203  FadFadOpsUnitTest(int numComponents1, int numComponents2,
204  ScalarType absolute_tolerance,
205  ScalarType relative_tolerance);
206 
207  void setUp();
208 
209  void tearDown();
210 
211  BINARY_OP_TEST(testAddition, +);
212  BINARY_OP_TEST(testSubtraction, -);
213  BINARY_OP_TEST(testMultiplication, *);
214  BINARY_OP_TEST(testDivision, /);
215 
216  RELOP_TEST(testEquals, ==);
217  RELOP_TEST(testNotEquals, !=);
218  RELOP_TEST(testLessThanOrEquals, <=);
219  RELOP_TEST(testGreaterThanOrEquals, >=);
220  RELOP_TEST(testLessThan, <);
221  RELOP_TEST(testGreaterThan, >);
222 
223  BINARY_FUNC_TEST(testPow, pow);
224 
225  UNARY_OP_TEST(testUnaryPlus, +);
226  UNARY_OP_TEST(testUnaryMinus, -);
227 
228  UNARY_FUNC_TEST(testExp, exp);
229  UNARY_FUNC_TEST(testLog, log);
230  UNARY_FUNC_TEST(testLog10, log10);
231  UNARY_FUNC_TEST(testSqrt, sqrt);
232  UNARY_FUNC_TEST(testCos, cos);
233  UNARY_FUNC_TEST(testSin, sin);
234  UNARY_FUNC_TEST(testTan, tan);
235  UNARY_FUNC_TEST(testACos, acos);
236  UNARY_FUNC_TEST(testASin, asin);
237  UNARY_FUNC_TEST(testATan, atan);
238  UNARY_FUNC_TEST(testCosh, cosh);
239  UNARY_FUNC_TEST(testSinh, sinh);
240  UNARY_FUNC_TEST(testTanh, tanh);
241  UNARY_FUNC_TEST(testAbs, abs);
242  UNARY_FUNC_TEST(testFAbs, fabs);
243 
244  UNARY_ASSIGNOP_TEST(testPlusEquals, +=);
245  UNARY_ASSIGNOP_TEST(testMinusEquals, -=);
246  UNARY_ASSIGNOP_TEST(testTimesEquals, *=);
247  UNARY_ASSIGNOP_TEST(testDivideEquals, /=);
248 
249  void testMax();
250  void testMin();
251 
252  template <typename ScalarT>
253  ScalarT composite1(const ScalarT& a, const ScalarT& b) {
254  ScalarT t1 = 3. * a + sin(b) / log(fabs(a - b * 7.));
255  ScalarT t2 = 1.0e3;
256  ScalarT t3 = 5.7e4;
257  ScalarT t4 = 3.2e5;
258  t1 *= cos(a + exp(t1)) / 6. - tan(t1*sqrt(abs(a * log10(abs(b)))));
259  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));
260  t1 /= cosh(b - 0.7) + 7.*sinh(t1 + 0.8)*tanh(9./a) - 9.;
261  t1 += pow(abs(a*4.),b-8.)/cos(a*b*a);
262 
263  return t1;
264  }
265 
266  template <typename ScalarT>
267  ScalarT composite1_fad(const ScalarT& a, const ScalarT& b) {
268  ScalarT t1 = FadType(3.) * a + sin(b) / log(fabs(a - b * FadType(7.)));
269  ScalarT t2 = FadType(1.0e3);
270  ScalarT t3 = FadType(7e4);
271  ScalarT t4 = FadType(3.2e5);
272  t1 *= cos(a + exp(t1)) / FadType(6.) - tan(t1*sqrt(abs(a * log10(abs(b)))));
273  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));
274  t1 /= cosh(b - FadType(0.7)) + FadType(7.)*sinh(t1 + FadType(0.8))*tanh(FadType(9.)/a) - FadType(9.);
275  t1 += pow(abs(a*FadType(4.)),b-FadType(8.))/cos(a*b*a);
276 
277  return t1;
278  }
279 
280  void testComposite1() {
284  }
285 
286  void testPlusLR() {
287  FadFadType aa_dfad = a_dfad;
288  FAD::Fad< FadType > aa_fad = a_fad;
289  aa_dfad = 1.0;
290  aa_fad = FadType(1.0);
291  aa_dfad = aa_dfad + b_dfad;
292  aa_fad = aa_fad + b_fad;
293  COMPARE_NESTED_FADS(aa_dfad, aa_fad);
294  }
295 
296  void testMinusLR() {
297  FadFadType aa_dfad = a_dfad;
298  FAD::Fad< FadType > aa_fad = a_fad;
299  aa_dfad = 1.0;
300  aa_fad = FadType(1.0);
301  aa_dfad = aa_dfad - b_dfad;
302  aa_fad = aa_fad - b_fad;
303  COMPARE_NESTED_FADS(aa_dfad, aa_fad);
304  }
305 
306  void testTimesLR() {
307  FadFadType aa_dfad = a_dfad;
308  FAD::Fad< FadType > aa_fad = a_fad;
309  aa_dfad = 2.0;
310  aa_fad = FadType(2.0);
311  aa_dfad = aa_dfad * b_dfad;
312  aa_fad = aa_fad * b_fad;
313  COMPARE_NESTED_FADS(aa_dfad, aa_fad);
314  }
315 
316  void testDivideLR() {
317  FadFadType aa_dfad = a_dfad;
318  FAD::Fad< FadType > aa_fad = a_fad;
319  aa_dfad = 2.0;
320  aa_fad = FadType(2.0);
321  aa_dfad = aa_dfad / b_dfad;
322  aa_fad = aa_fad / b_fad;
323  COMPARE_NESTED_FADS(aa_dfad, aa_fad);
324  }
325 
326  // Check various corner cases for pow()
327  void testPowConstB() {
328  FadFadType a, b, c, cc;
329 
330  // Constant b
331  a = a_dfad;
332  b = 3.456;
333  c = pow(a, b);
334  ScalarType f = pow(a.val().val(), b.val().val());
335  ScalarType fp = b.val().val()*pow(a.val().val(),b.val().val()-1);
336  ScalarType fpp = b.val().val()*(b.val().val()-1)*pow(a.val().val(),b.val().val()-2);
337  cc = FadFadType(n1,FadType(n2,f));
338  for (int i=0; i<n2; ++i)
339  cc.val().fastAccessDx(i) = fp*a.val().dx(i);
340  for (int i=0; i<n1; ++i) {
341  cc.fastAccessDx(i) = FadType(n2,fp*a.dx(i).val());
342  for (int j=0; j<n2; ++j)
343  cc.fastAccessDx(i).fastAccessDx(j) = fpp*a.dx(i).val()*a.val().dx(j) + fp*a.dx(i).dx(j);
344  }
345  COMPARE_NESTED_FADS(c, cc);
346 
347  // Constant scalar b
348  c = pow(a, b.val());
349  COMPARE_NESTED_FADS(c, cc);
350  c = pow(a, b.val().val());
351  COMPARE_NESTED_FADS(c, cc);
352 
353  // Constant b == 0
354  b = 0.0;
355  c = pow(a, b);
356  cc.val() = FadType(n2,1.0);
357  for (int i=0; i<n1; ++i)
358  cc.fastAccessDx(i) = FadType(n2,0.0);
359  COMPARE_NESTED_FADS(c, cc);
360 
361  // Constant scalar b == 0
362  c = pow(a, b.val());
363  cc.val() = FadType(n2,1.0);
364  for (int i=0; i<n1; ++i)
365  cc.fastAccessDx(i) = FadType(n2,0.0);
366  COMPARE_NESTED_FADS(c, cc);
367  c = pow(a, b.val().val());
368  COMPARE_NESTED_FADS(c, cc);
369 
370  // a == 0 and constant b
371  a.val() = 0.0;
372  b = 3.456;
373  c = pow(a, b);
374  cc.val() = 0.0;
375  for (int i=0; i<n1; ++i)
376  cc.fastAccessDx(i) = 0.0;
377  COMPARE_NESTED_FADS(c, cc);
378 
379  // a == 0 and constant scalar b
380  c = pow(a, b.val());
381  for (int i=0; i<n1; ++i)
382  cc.fastAccessDx(i) = 0.0;
383  COMPARE_NESTED_FADS(c, cc);
384  c = pow(a, b.val().val());
385  COMPARE_NESTED_FADS(c, cc);
386 
387  // a == 0 and b == 0
388  b = 0.0;
389  c = pow(a, b);
390  cc.val() = 1.0;
391  for (int i=0; i<n1; ++i)
392  cc.fastAccessDx(i) = 0.0;
393  COMPARE_NESTED_FADS(c, cc);
394 
395  // a == 0 and scalar b == 0
396  c = pow(a, b.val());
397  COMPARE_NESTED_FADS(c, cc);
398  c = pow(a, b.val().val());
399  COMPARE_NESTED_FADS(c, cc);
400  }
401 
402 protected:
403 
404  // DFad variables
405  FadFadType a_dfad, b_dfad, c_dfad;
406 
407  // Fad variables
408  FAD::Fad<FadType> a_fad, b_fad, c_fad;
409 
410  // Random number generator
412 
413  // Number of derivative components
414  int n1, n2;
415 
416  // Tolerances to which fad objects should be the same
417  ScalarType tol_a, tol_r;
418 
419 }; // class FadFadOpsUnitTest
420 
421 // Set the random number generator with a specific seed to prevent NaN's
422 // in the second derivatives, likely due to overflow
423 
424 template <class FadFadType, class ScalarType>
427  urand(0.0, 1.0, 123456), n1(5), n2(3), tol_a(1.0e-15), tol_r(1.0e-14) {}
428 
429 template <class FadFadType, class ScalarType>
431 FadFadOpsUnitTest(int numComponents1, int numComponents2,
432  ScalarType absolute_tolerance,
433  ScalarType relative_tolerance) :
434  urand(0.0, 1.0, 123456),
435  n1(numComponents1),
436  n2(numComponents2),
437  tol_a(absolute_tolerance),
438  tol_r(relative_tolerance) {}
439 
440 template <class FadFadType, class ScalarType>
442  ScalarType val;
443 
444  val = urand.number();
445  a_dfad = FadFadType(n1,FadType(n2,val));
446  a_fad = FAD::Fad<FadType>(n1,FadType(n2,val));
447 
448  val = urand.number();
449  b_dfad = FadFadType(n1,FadType(n2,val));
450  b_fad = FAD::Fad<FadType>(n1,FadType(n2,val));
451 
452  for (int j=0; j<n2; j++) {
453  ScalarType val2;
454  val2 = urand.number();
455  a_dfad.val().fastAccessDx(j) = val2;
456  a_fad.val().fastAccessDx(j) = val2;
457 
458  val2 = urand.number();
459  b_dfad.val().fastAccessDx(j) = val2;
460  b_fad.val().fastAccessDx(j) = val2;
461  }
462 
463  for (int i=0; i<n1; i++) {
464  val = urand.number();
465  a_dfad.fastAccessDx(i) = FadType(n2,val);
466  a_fad.fastAccessDx(i) = FadType(n2,val);
467 
468  val = urand.number();
469  b_dfad.fastAccessDx(i) = FadType(n2,val);
470  b_fad.fastAccessDx(i) = FadType(n2,val);
471 
472  for (int j=0; j<n2; j++) {
473  ScalarType val2;
474  val2 = urand.number();
475  a_dfad.fastAccessDx(i).fastAccessDx(j) = val2;
476  a_fad.fastAccessDx(i).fastAccessDx(j) = val2;
477 
478  val2 = urand.number();
479  b_dfad.fastAccessDx(i).fastAccessDx(j) = val2;
480  b_fad.fastAccessDx(i).fastAccessDx(j) = val2;
481  }
482  }
483 }
484 
485 template <class FadFadType, class ScalarType>
488 
489 template <class FadFadType, class ScalarType>
492  FadType val;
493 
494  FadFadType aa_dfad = a_dfad + 1.0;
495  c_dfad = max(aa_dfad, a_dfad);
496  COMPARE_FADS(c_dfad.val(), aa_dfad.val());
497  for (int i=0; i<n1; i++) {
498  COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
499  COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
500  }
501 
502  c_dfad = max(a_dfad, aa_dfad);
503  COMPARE_FADS(c_dfad.val(), aa_dfad.val());
504  for (int i=0; i<n1; i++) {
505  COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
506  COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
507  }
508 
509  c_dfad = max(a_dfad+1.0, a_dfad);
510  COMPARE_FADS(c_dfad.val(), aa_dfad.val());
511  for (int i=0; i<n1; i++) {
512  COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
513  COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
514  }
515 
516  c_dfad = max(a_dfad, a_dfad+1.0);
517  COMPARE_FADS(c_dfad.val(), aa_dfad.val());
518  for (int i=0; i<n1; i++) {
519  COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
520  COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
521  }
522 
523  val = a_dfad.val() + 1;
524  c_dfad = max(a_dfad, val);
525  COMPARE_FADS(c_dfad.val(), val);
526  for (int i=0; i<n1; i++) {
527  COMPARE_FADS(c_dfad.dx(i), FadType(0.0));
528  }
529 
530  val = a_dfad.val() - 1;
531  c_dfad = max(a_dfad, val);
532  COMPARE_FADS(c_dfad.val(), a_dfad.val());
533  for (int i=0; i<n1; i++) {
534  COMPARE_FADS(c_dfad.dx(i), a_dfad.dx(i));
535  COMPARE_FADS(c_dfad.fastAccessDx(i), a_dfad.fastAccessDx(i));
536  }
537 
538  val = b_dfad.val() + 1;
539  c_dfad = max(val, b_dfad);
540  COMPARE_FADS(c_dfad.val(), val);
541  for (int i=0; i<n1; i++) {
542  COMPARE_FADS(c_dfad.dx(i), FadType(0.0));
543  }
544 
545  val = b_dfad.val() - 1;
546  c_dfad = max(val, b_dfad);
547  COMPARE_FADS(c_dfad.val(), b_dfad.val());
548  for (int i=0; i<n1; i++) {
549  COMPARE_FADS(c_dfad.dx(i), b_dfad.dx(i));
550  COMPARE_FADS(c_dfad.fastAccessDx(i), b_dfad.fastAccessDx(i));
551  }
552 }
553 
554 template <class FadFadType, class ScalarType>
557  FadType val;
558 
559  FadFadType aa_dfad = a_dfad - 1.0;
560  c_dfad = min(aa_dfad, a_dfad);
561  COMPARE_FADS(c_dfad.val(), aa_dfad.val());
562  for (int i=0; i<n1; i++) {
563  COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
564  COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
565  }
566 
567  c_dfad = min(a_dfad, aa_dfad);
568  COMPARE_FADS(c_dfad.val(), aa_dfad.val());
569  for (int i=0; i<n1; i++) {
570  COMPARE_FADS(c_dfad.dx(i), aa_dfad.dx(i));
571  COMPARE_FADS(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
572  }
573 
574  val = a_dfad.val() - 1;
575  c_dfad = min(a_dfad, val);
576  COMPARE_FADS(c_dfad.val(), val);
577  for (int i=0; i<n1; i++) {
578  COMPARE_FADS(c_dfad.dx(i), FadType(0.0));
579  }
580 
581  val = a_dfad.val() + 1;
582  c_dfad = min(a_dfad, val);
583  COMPARE_FADS(c_dfad.val(), a_dfad.val());
584  for (int i=0; i<n1; i++) {
585  COMPARE_FADS(c_dfad.dx(i), a_dfad.dx(i));
586  COMPARE_FADS(c_dfad.fastAccessDx(i), a_dfad.fastAccessDx(i));
587  }
588 
589  val = b_dfad.val() - 1;
590  c_dfad = min(val, b_dfad);
591  COMPARE_FADS(c_dfad.val(), val);
592  for (int i=0; i<n1; i++) {
593  COMPARE_FADS(c_dfad.dx(i), FadType(0.0));
594  }
595 
596  val = b_dfad.val() + 1;
597  c_dfad = min(val, b_dfad);
598  COMPARE_FADS(c_dfad.val(), b_dfad.val());
599  for (int i=0; i<n1; i++) {
600  COMPARE_FADS(c_dfad.dx(i), b_dfad.dx(i));
601  COMPARE_FADS(c_dfad.fastAccessDx(i), b_dfad.fastAccessDx(i));
602  }
603 }
604 
605 #undef COMPARE_VALUES
606 #undef COMPARE_FADS
607 #undef COMPARE_NESTED_FADS
608 
609 #endif // NESETD_FADUNITTESTS_HPP
ScalarT composite1(const ScalarT &a, const ScalarT &b)
void f()
asin(expr.val())
cosh(expr.val())
abs(expr.val())
#define COMPARE_FADS(a, b)
UNARY_OP_TEST(testUnaryPlus,+)
FAD::Fad< FadType > a_fad
Sacado::Fad::DFad< double > FadType
BINARY_FUNC_TEST(testPow, pow)
atan(expr.val())
FAD::Fad< FadType > b_fad
KOKKOS_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)
BINARY_OP_TEST(testAddition,+)
FAD::Fad< FadType > c_fad
expr val()
tanh(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
#define COMPARE_NESTED_FADS(a, b)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
CPPUNIT_TEST(testAddition)
UNARY_FUNC_TEST(testExp, exp)
sqrt(expr.val())
sinh(expr.val())
tan(expr.val())
Sacado::Random< ScalarType > urand
UNARY_ASSIGNOP_TEST(testPlusEquals,+=)
FadFadType::value_type FadType
sin(expr.val())
log(expr.val())
acos(expr.val())
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
ScalarT composite1_fad(const ScalarT &a, const ScalarT &b)
exp(expr.val())
RELOP_TEST(testEquals,==)
fabs(expr.val())
CPPUNIT_TEST_SUITE(FadFadOpsUnitTest)
log10(expr.val())
cos(expr.val())