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 //
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 
34 
35 #include "Sacado.hpp"
36 
37 // Size used for all Fad types
38 const int global_fad_size = 10;
39 
40 // Check whether the ternary operator works as expected
41 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Ternary, Ternary, AD )
42 {
43  typedef AD ad_type;
44  typedef typename ad_type::value_type value_type;
45 
46  success = true;
47 
48  ad_type x(global_fad_size, value_type(1.5));
49  for (int i=0; i<global_fad_size; ++i)
50  x.fastAccessDx(i) = 2.0;
51 
52  ad_type y = x > 0 ? -x : x;
53 
54  TEST_EQUALITY_CONST( y.val(), -1.5 );
55  for (int i=0; i<global_fad_size; ++i)
56  TEST_EQUALITY_CONST( y.dx(i), -2.0 );
57 }
58 
63 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, Fad_SLFadType )
64 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, Fad_SFadType )
65 
66 typedef Sacado::ELRFad::DFad<double> ELRFad_DFadType;
67 typedef Sacado::ELRFad::SLFad<double,global_fad_size> ELRFad_SLFadType;
68 typedef Sacado::ELRFad::SFad<double,global_fad_size> ELRFad_SFadType;
69 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_DFadType )
70 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_SLFadType )
71 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_SFadType )
72 
73 typedef Sacado::CacheFad::DFad<double> CacheFad_DFadType;
74 typedef Sacado::CacheFad::SLFad<double,global_fad_size> CacheFad_SLFadType;
75 typedef Sacado::CacheFad::SFad<double,global_fad_size> CacheFad_SFadType;
76 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_DFadType )
77 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_SLFadType )
78 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_SFadType )
79 
80 typedef Sacado::ELRCacheFad::DFad<double> ELRCacheFad_DFadType;
81 typedef Sacado::ELRCacheFad::SLFad<double,global_fad_size> ELRCacheFad_SLFadType;
82 typedef Sacado::ELRCacheFad::SFad<double,global_fad_size> ELRCacheFad_SFadType;
83 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_DFadType )
84 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_SLFadType )
85 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_SFadType )
86 
87 #if defined(SACADO_ENABLE_NEW_DESIGN) && !defined(SACADO_NEW_FAD_DESIGN_IS_DEFAULT)
88 typedef Sacado::Fad::Exp::DFad<double> ExpFad_DFadType;
91 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_DFadType )
92 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_SLFadType )
93 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_SFadType )
94 #endif
95 
96 int main( int argc, char* argv[] ) {
97  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
99 }
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:191
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, TYPE)
GeneralFad< StaticFixedStorage< T, Num > > SFad
Sacado::CacheFad::SFad< double, 5 > Fad_SFadType