Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_SacadoPromoteUnitTest.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 // This test requires C++11 (for static_assert), so why not use the
31 // standard type traits
32 #include <type_traits>
33 
38 
39 #include "Sacado.hpp"
40 #include "Stokhos_Sacado.hpp"
42 #include "Sacado_mpl_apply.hpp"
43 
44 template <typename uq_type, typename expr_type>
46  using Sacado::Promote;
47  using std::is_same;
48 
49  typedef typename Sacado::ValueType<uq_type>::type value_type;
50  typedef typename Sacado::ScalarType<uq_type>::type scalar_type;
51 
52  static_assert(
53  is_same<typename Promote<uq_type,uq_type>::type, uq_type >::value,
54  "Promote<uq_type,uq_type>::type != uq_type");
55 
56  static_assert(
57  is_same<typename Promote<uq_type,value_type>::type, uq_type >::value,
58  "Promote<uq_type,value_type>::type != uq_type");
59 
60  static_assert(
61  is_same<typename Promote<value_type,uq_type>::type, uq_type >::value,
62  "Promote<value_type,uq_type>::type != uq_type");
63 
64  static_assert(
65  is_same<typename Promote<uq_type,scalar_type>::type, uq_type >::value,
66  "Promote<uq_type,scalar_type>::type != uq_type");
67 
68  static_assert(
69  is_same<typename Promote<scalar_type,uq_type>::type, uq_type >::value,
70  "Promote<scalar_type,uq_type>::type != uq_type");
71 
72  static_assert(
73  is_same<typename Promote<uq_type,expr_type>::type, uq_type >::value,
74  "Promote<expr_type,uq_type>::type != uq_type");
75 
76  static_assert(
77  is_same<typename Promote<expr_type,uq_type>::type, uq_type >::value,
78  "Promote<expr_type,uq_type>::type != uq_type");
79 
80  static_assert(
81  is_same<typename Promote<scalar_type,expr_type>::type, uq_type >::value,
82  "Promote<scalar_type,uq_type>::type != uq_type");
83 
84  static_assert(
85  is_same<typename Promote<expr_type,scalar_type>::type, uq_type >::value,
86  "Promote<expr_type,scalar_type>::type != uq_type");
87 
88  static_assert(
89  is_same<typename Promote<value_type,expr_type>::type, uq_type >::value,
90  "Promote<value_type,uq_type>::type != uq_type");
91 
92  static_assert(
93  is_same<typename Promote<expr_type,value_type>::type, uq_type >::value,
94  "Promote<expr_type,value_type>::type != uq_type");
95 
96  // These tests are all compile-time tests, so if the test compiles,
97  // it passes...
98  return true;
99 }
100 
101 template <typename uq_type, typename expr1_type, typename expr2_type>
103  using Sacado::Promote;
104  using std::is_same;
105 
106  static_assert(
107  is_same<typename Promote<expr1_type,expr2_type>::type, uq_type >::value,
108  "Promote<expr1_type,expr2_type>::type != uq_type");
109 
110  // These tests are all compile-time tests, so if the test compiles,
111  // it passes...
112  return true;
113 }
114 
115 template <typename uq_type>
117 
118  // Get the type of the result of the expression 'ad_type * ad_type'
119  // The use of declval gets around actually instantiation objects of type
120  // ad_type.
121  typedef decltype(std::declval<uq_type>()*std::declval<uq_type>()) bi_expr_type;
122  bool res1 = testUQExprPromote<uq_type,bi_expr_type>();
123 
124  // Get the type of the result of the expression '-ad_type'
125  // This provides additional testing for Promote specializations as unary
126  // expressions are convertible to/from the scalar type
127  typedef decltype(-std::declval<uq_type>()) un_expr_type;
128  bool res2 = testUQExprPromote<uq_type,un_expr_type>();
129 
130  bool res3 = testUQExprPromote2<uq_type,bi_expr_type,un_expr_type>();
131 
132  return res1 && res2 && res3;
133 }
134 
135 template <typename uq_type>
136 bool testPromote() {
137  using Sacado::Promote;
138  using std::is_same;
139  typedef Sacado::Fad::DFad<uq_type> fad_uq_type;
140 
141  bool res1 = testUQPromote<uq_type>();
142  bool res2 = testUQPromote<fad_uq_type>();
143 
144  typedef decltype(std::declval<uq_type>()*std::declval<uq_type>()) uq_expr_type;
145  typedef decltype(-std::declval<fad_uq_type>()) fad_uq_expr_type;
146  static_assert(
147  is_same<typename Promote<uq_expr_type,fad_uq_expr_type>::type, fad_uq_type >::value,
148  "Promote<uq_expr_type,fad_uq_expr_type>::type != fad_uq_type");
149 
150  return res1 && res2;
151 }
152 
153 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Promote, Promote, UQ )
154 {
155  success = testPromote<UQ>();
156 }
157 
158 typedef Kokkos::DefaultExecutionSpace device;
159 
160 #ifdef HAVE_STOKHOS_PCE_SCALAR_TYPE
161 //
162 // Sacado::PCE::OrthogPoly
163 //
165 typedef Sacado::PCE::OrthogPoly<double,storage_type> orthog_poly_type;
166 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Promote, Promote, orthog_poly_type )
167 
168 //
169 // Sacado::ETPCE::OrthogPoly
170 //
171 typedef Sacado::ETPCE::OrthogPoly<double,storage_type> et_orthog_poly_type;
172 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Promote, Promote, et_orthog_poly_type )
173 
174 //
175 // Sacado::UQ::PCE
176 //
177 typedef Stokhos::DynamicStorage<int,double,device> dynamic_storage_type;
178 typedef Sacado::UQ::PCE<dynamic_storage_type> kokkos_pce_type;
179 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Promote, Promote, kokkos_pce_type )
180 #endif
181 
182 #ifdef HAVE_STOKHOS_ENSEMBLE_SCALAR_TYPE
183 //
184 // Sacado::MP::Vector
185 //
186 
187 typedef Stokhos::StaticFixedStorage<int,double,32,device> static_storage_type;
188 typedef Sacado::MP::Vector<static_storage_type> kokkos_mp_type;
189 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Promote, Promote, kokkos_mp_type )
190 #endif
191 
192 int main( int argc, char* argv[] ) {
193  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
195 }
Stokhos::StandardStorage< int, double > storage_type
bool testUQExprPromote2()
Statically allocated storage class.
static int runUnitTestsFromMain(int argc, char *argv[])
bool testUQExprPromote()
Kokkos::DefaultExecutionSpace device
int main(int argc, char **argv)
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Kokkos_CrsMatrix_MP, ReplaceValues, MatrixScalar)
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, TYPE)