Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
30#include "Teuchos_UnitTestHarness.hpp"
31#include "Teuchos_UnitTestRepository.hpp"
32#include "Teuchos_GlobalMPISession.hpp"
33#include "Teuchos_TestingHelpers.hpp"
34
35#include "Sacado.hpp"
36
37// Size used for all Fad types
38const int global_fad_size = 10;
39
40// Check whether the ternary operator works as expected
41TEUCHOS_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
62TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, Fad_DFadType )
63TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, Fad_SLFadType )
64TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, Fad_SFadType )
65
66typedef Sacado::ELRFad::DFad<double> ELRFad_DFadType;
67typedef Sacado::ELRFad::SLFad<double,global_fad_size> ELRFad_SLFadType;
68typedef Sacado::ELRFad::SFad<double,global_fad_size> ELRFad_SFadType;
69TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_DFadType )
70TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_SLFadType )
71TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRFad_SFadType )
72
73typedef Sacado::CacheFad::DFad<double> CacheFad_DFadType;
74typedef Sacado::CacheFad::SLFad<double,global_fad_size> CacheFad_SLFadType;
75typedef Sacado::CacheFad::SFad<double,global_fad_size> CacheFad_SFadType;
76TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_DFadType )
77TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_SLFadType )
78TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, CacheFad_SFadType )
79
80typedef Sacado::ELRCacheFad::DFad<double> ELRCacheFad_DFadType;
81typedef Sacado::ELRCacheFad::SLFad<double,global_fad_size> ELRCacheFad_SLFadType;
82typedef Sacado::ELRCacheFad::SFad<double,global_fad_size> ELRCacheFad_SFadType;
83TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_DFadType )
84TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_SLFadType )
85TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ELRCacheFad_SFadType )
86
87#if defined(SACADO_ENABLE_NEW_DESIGN) && !defined(SACADO_NEW_FAD_DESIGN_IS_DEFAULT)
88typedef Sacado::Fad::Exp::DFad<double> ExpFad_DFadType;
91TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_DFadType )
92TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_SLFadType )
93TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Ternary, Ternary, ExpFad_SFadType )
94#endif
95
96int main( int argc, char* argv[] ) {
97 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
98 return Teuchos::UnitTestRepository::runUnitTestsFromMain(argc, argv);
99}
Sacado::Fad::SLFad< double, global_fad_size > Fad_SLFadType
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Ternary, Ternary, AD)
Sacado::Fad::DFad< double > Fad_DFadType
Sacado::Fad::SFad< double, global_fad_size > Fad_SFadType
const int global_fad_size
int main()
Definition: ad_example.cpp:191
Forward-mode AD class templated on the storage for the derivative array.
const double y