Sacado Package Browser (Single Doxygen Collection)  Version of the Day
TraitsTests.hpp
Go to the documentation of this file.
1 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Sacado Package
7 // Copyright (2006) Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // This library is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as
14 // published by the Free Software Foundation; either version 2.1 of the
15 // License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 // USA
26 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27 // (etphipp@sandia.gov).
28 //
29 // ***********************************************************************
30 // @HEADER
31 
32 #ifndef TRAITSTESTS_HPP
33 #define TRAITSTESTS_HPP
34 
35 // Sacado includes
36 #include "Sacado_No_Kokkos.hpp"
37 #include "Sacado_Random.hpp"
38 #include "Sacado_mpl_apply.hpp"
39 #include "Sacado_mpl_is_same.hpp"
40 
41 // Cppunit includes
42 #include <cppunit/extensions/HelperMacros.h>
43 
44 // A class for testing Sacado::Traits definitions for Sacado AD types
45 template <class ADType>
46 class TraitsTests : public CppUnit::TestFixture {
47 
49 
57 
59 
60 public:
61 
62  TraitsTests();
64 
65  void setUp() {}
66 
67  void tearDown() {}
68 
69  void testScalarType();
70  void testValueType();
71  void testIsADType();
72  void testIsScalarType();
73  void testValue();
74  void testScalarValue();
75  void testStringName();
76 
77 protected:
78 
81 
82  // Random number generator
84 
85  // Memory pools for DMFad
88 
89 }; // class TraitsTests
90 
91 template <class ADType>
94  urand(),
95  poolManager(1),
96  poolManager2(1)
97 {
100 
102  Sacado::Fad::DMFad< Sacado::Fad::DMFad<double> >::setDefaultPool(pool2);
103 }
104 
105 template <class ADType>
106 void
110  CPPUNIT_ASSERT(same == true);
111 
113  CPPUNIT_ASSERT(same == true);
114 }
115 
116 template <class ADType>
117 void
121  CPPUNIT_ASSERT(same == true);
122 
124  CPPUNIT_ASSERT(same == true);
125 }
126 
127 template <class ADType>
128 void
131  CPPUNIT_ASSERT(Sacado::IsADType<ad1_t>::value == true);
132  CPPUNIT_ASSERT(Sacado::IsADType<ad2_t>::value == true);
133 }
134 
135 template <class ADType>
136 void
139  CPPUNIT_ASSERT(Sacado::IsScalarType<ad1_t>::value == false);
140  CPPUNIT_ASSERT(Sacado::IsScalarType<ad2_t>::value == false);
141 }
142 
143 template <class ADType>
144 void
147  double val = urand.number();
148  ad1_t a(val);
149  CPPUNIT_ASSERT(Sacado::Value<ad1_t>::eval(a) == val);
150 
151  ad2_t b(a);
152  CPPUNIT_ASSERT(Sacado::Value<ad2_t>::eval(b) == a);
153 }
154 
155 template <class ADType>
156 void
159  double val = urand.number();
160  ad1_t a(val);
161  CPPUNIT_ASSERT(Sacado::ScalarValue<ad1_t>::eval(a) == val);
162 
163  ad2_t b(a);
164  CPPUNIT_ASSERT(Sacado::ScalarValue<ad2_t>::eval(b) == val);
165 }
166 
167 template <class ADType>
168 void
171  // Currently we can't check the string name, here we are just making sure
172  // it compiles
175  // CPPUNIT_ASSERT(Sacado::StringName<ad1_t>::eval() == name + "< double, double >");
176  // CPPUNIT_ASSERT(Sacado::StringName<ad2_t>::eval() == name + "< " + name + "< double, double >, double >");
177 }
178 
179 #endif // TRAITSTESTS_HPP
Sacado::Random< double >
Sacado::StringName::eval
static std::string eval()
Definition: Sacado_Traits.hpp:377
TraitsTests::testStringName
void testStringName()
Definition: TraitsTests.hpp:170
TraitsTests::testIsScalarType
void testIsScalarType()
Definition: TraitsTests.hpp:138
TraitsTests::testScalarType
void testScalarType()
Definition: TraitsTests.hpp:108
TraitsTests::poolManager
Sacado::Fad::MemPoolManager< double > poolManager
Definition: TraitsTests.hpp:86
TraitsTests::testScalarValue
void testScalarValue()
Definition: TraitsTests.hpp:158
Sacado::Fad::MemPool
Memory pool.
Definition: Sacado_Fad_MemPool.hpp:40
Sacado::Value
Base template specification for Value.
Definition: Sacado_Traits.hpp:354
TraitsTests::setUp
void setUp()
Definition: TraitsTests.hpp:65
Sacado::mpl::is_same
Definition: Sacado_mpl_is_same.hpp:38
TraitsTests::poolManager2
Sacado::Fad::MemPoolManager< Sacado::Fad::DMFad< double > > poolManager2
Definition: TraitsTests.hpp:87
TraitsTests::CPPUNIT_TEST_SUITE
CPPUNIT_TEST_SUITE(TraitsTests)
TraitsTests::TraitsTests
TraitsTests()
Definition: TraitsTests.hpp:93
TraitsTests::CPPUNIT_TEST
CPPUNIT_TEST(testScalarType)
TraitsTests::~TraitsTests
~TraitsTests()
Definition: TraitsTests.hpp:63
Sacado::Fad::MemPoolManager::getMemoryPool
MemPool * getMemoryPool(unsigned int dim)
Get memory pool for supplied dimension dim.
Definition: Sacado_Fad_MemPoolManagerImp.hpp:51
TraitsTests::ad2_t
Sacado::mpl::apply< ADType, ad1_t >::type ad2_t
Definition: TraitsTests.hpp:80
TraitsTests::testIsADType
void testIsADType()
Definition: TraitsTests.hpp:130
TraitsTests::testValue
void testValue()
Definition: TraitsTests.hpp:146
Sacado_mpl_apply.hpp
TraitsTests::tearDown
void tearDown()
Definition: TraitsTests.hpp:67
Sacado_No_Kokkos.hpp
Sacado::mpl::apply_wrap5< lambda< F >::type, A1, A2, A3, A4, A5 >::type
lambda< F >::type ::template apply< A1, A2, A3, A4, A5 >::type type
Definition: Sacado_mpl_apply_wrap.hpp:84
Sacado_mpl_is_same.hpp
Sacado::IsScalarType
Base template specification for IsScalarType.
Definition: Sacado_Traits.hpp:346
a
a
Definition: Sacado_CacheFad_Ops.hpp:426
Sacado::ScalarValue
Base template specification for ScalarValue.
Definition: Sacado_Traits.hpp:364
TraitsTests::CPPUNIT_TEST_SUITE_END
CPPUNIT_TEST_SUITE_END()
TraitsTests::testValueType
void testValueType()
Definition: TraitsTests.hpp:119
TraitsTests::urand
Sacado::Random< double > urand
Definition: TraitsTests.hpp:83
Sacado::IsADType
Base template specification for IsADType.
Definition: Sacado_Traits.hpp:337
Sacado_Random.hpp
Sacado::Fad::MemPoolManager< double >
TraitsTests
Definition: TraitsTests.hpp:46
val
expr val()
TraitsTests::ad1_t
Sacado::mpl::apply< ADType, double >::type ad1_t
Definition: TraitsTests.hpp:79
Sacado::Fad::DMFad
Forward-mode AD class using dynamic memory allocation and expression templates.
Definition: Sacado_Fad_DMFad.hpp:68