Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TernaryExprTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
14 
15 #include "Sacado.hpp"
16 
17 // Size used for all Fad types
18 const int global_fad_size = 10;
19 
20 // Check whether the ternary operator works as expected
22 {
23  typedef AD ad_type;
24  typedef typename ad_type::value_type value_type;
25 
26  success = true;
27 
28  ad_type x(global_fad_size, value_type(1.5));
29  for (int i=0; i<global_fad_size; ++i)
30  x.fastAccessDx(i) = 2.0;
31 
32  ad_type y = x > 0 ? -x : x;
33 
34  TEST_EQUALITY_CONST( y.val(), -1.5 );
35  for (int i=0; i<global_fad_size; ++i)
36  TEST_EQUALITY_CONST( y.dx(i), -2.0 );
37 }
38 
43 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, Fad_SLFadType )
44 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, Fad_SFadType )
45 
46 typedef Sacado::ELRFad::DFad<double> ELRFad_DFadType;
47 typedef Sacado::ELRFad::SLFad<double,global_fad_size> ELRFad_SLFadType;
48 typedef Sacado::ELRFad::SFad<double,global_fad_size> ELRFad_SFadType;
49 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_DFadType )
50 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_SLFadType )
51 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_SFadType )
52 
53 typedef Sacado::CacheFad::DFad<double> CacheFad_DFadType;
54 typedef Sacado::CacheFad::SLFad<double,global_fad_size> CacheFad_SLFadType;
55 typedef Sacado::CacheFad::SFad<double,global_fad_size> CacheFad_SFadType;
56 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_DFadType )
57 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_SLFadType )
58 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_SFadType )
59 
60 typedef Sacado::ELRCacheFad::DFad<double> ELRCacheFad_DFadType;
61 typedef Sacado::ELRCacheFad::SLFad<double,global_fad_size> ELRCacheFad_SLFadType;
62 typedef Sacado::ELRCacheFad::SFad<double,global_fad_size> ELRCacheFad_SFadType;
63 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_DFadType )
64 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_SLFadType )
65 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_SFadType )
66 
67 #if defined(SACADO_ENABLE_NEW_DESIGN) && !defined(SACADO_NEW_FAD_DESIGN_IS_DEFAULT)
68 typedef Sacado::Fad::Exp::DFad<double> ExpFad_DFadType;
71 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_DFadType )
72 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_SLFadType )
73 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_SFadType )
74 #endif
75 
76 int main( int argc, char* argv[] ) {
77  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
79 }
Sacado::CacheFad::SLFad< double, 10 > Fad_SLFadType
#define TEST_EQUALITY_CONST(v1, v2)
const int global_fad_size
Sacado::CacheFad::DFad< double > Fad_DFadType
GeneralFad< StaticStorage< T, Num > > SLFad
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(ConditionalReturnType, Fad, FAD)
static int runUnitTestsFromMain(int argc, char *argv[])
GeneralFad< DynamicStorage< T > > DFad
Forward-mode AD class templated on the storage for the derivative array.
int main()
Definition: ad_example.cpp:171
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, TYPE)
GeneralFad< StaticFixedStorage< T, Num > > SFad
Sacado::CacheFad::SFad< double, 5 > Fad_SFadType
const double y