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 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 // This test requires C++11 (for static_assert), so why not use the
11 // standard type traits
12 #include <type_traits>
13 
18 
19 #include "Sacado.hpp"
20 #include "Stokhos_Sacado.hpp"
22 #include "Sacado_mpl_apply.hpp"
23 
24 template <typename uq_type, typename expr_type>
26  using Sacado::Promote;
27  using std::is_same;
28 
29  typedef typename Sacado::ValueType<uq_type>::type value_type;
30  typedef typename Sacado::ScalarType<uq_type>::type scalar_type;
31 
32  static_assert(
33  is_same<typename Promote<uq_type,uq_type>::type, uq_type >::value,
34  "Promote<uq_type,uq_type>::type != uq_type");
35 
36  static_assert(
37  is_same<typename Promote<uq_type,value_type>::type, uq_type >::value,
38  "Promote<uq_type,value_type>::type != uq_type");
39 
40  static_assert(
41  is_same<typename Promote<value_type,uq_type>::type, uq_type >::value,
42  "Promote<value_type,uq_type>::type != uq_type");
43 
44  static_assert(
45  is_same<typename Promote<uq_type,scalar_type>::type, uq_type >::value,
46  "Promote<uq_type,scalar_type>::type != uq_type");
47 
48  static_assert(
49  is_same<typename Promote<scalar_type,uq_type>::type, uq_type >::value,
50  "Promote<scalar_type,uq_type>::type != uq_type");
51 
52  static_assert(
53  is_same<typename Promote<uq_type,expr_type>::type, uq_type >::value,
54  "Promote<expr_type,uq_type>::type != uq_type");
55 
56  static_assert(
57  is_same<typename Promote<expr_type,uq_type>::type, uq_type >::value,
58  "Promote<expr_type,uq_type>::type != uq_type");
59 
60  static_assert(
61  is_same<typename Promote<scalar_type,expr_type>::type, uq_type >::value,
62  "Promote<scalar_type,uq_type>::type != uq_type");
63 
64  static_assert(
65  is_same<typename Promote<expr_type,scalar_type>::type, uq_type >::value,
66  "Promote<expr_type,scalar_type>::type != uq_type");
67 
68  static_assert(
69  is_same<typename Promote<value_type,expr_type>::type, uq_type >::value,
70  "Promote<value_type,uq_type>::type != uq_type");
71 
72  static_assert(
73  is_same<typename Promote<expr_type,value_type>::type, uq_type >::value,
74  "Promote<expr_type,value_type>::type != uq_type");
75 
76  // These tests are all compile-time tests, so if the test compiles,
77  // it passes...
78  return true;
79 }
80 
81 template <typename uq_type, typename expr1_type, typename expr2_type>
83  using Sacado::Promote;
84  using std::is_same;
85 
86  static_assert(
87  is_same<typename Promote<expr1_type,expr2_type>::type, uq_type >::value,
88  "Promote<expr1_type,expr2_type>::type != uq_type");
89 
90  // These tests are all compile-time tests, so if the test compiles,
91  // it passes...
92  return true;
93 }
94 
95 template <typename uq_type>
96 bool testUQPromote() {
97 
98  // Get the type of the result of the expression 'ad_type * ad_type'
99  // The use of declval gets around actually instantiation objects of type
100  // ad_type.
101  typedef decltype(std::declval<uq_type>()*std::declval<uq_type>()) bi_expr_type;
102  bool res1 = testUQExprPromote<uq_type,bi_expr_type>();
103 
104  // Get the type of the result of the expression '-ad_type'
105  // This provides additional testing for Promote specializations as unary
106  // expressions are convertible to/from the scalar type
107  typedef decltype(-std::declval<uq_type>()) un_expr_type;
108  bool res2 = testUQExprPromote<uq_type,un_expr_type>();
109 
110  bool res3 = testUQExprPromote2<uq_type,bi_expr_type,un_expr_type>();
111 
112  return res1 && res2 && res3;
113 }
114 
115 template <typename uq_type>
116 bool testPromote() {
117  using Sacado::Promote;
118  using std::is_same;
119  typedef Sacado::Fad::DFad<uq_type> fad_uq_type;
120 
121  bool res1 = testUQPromote<uq_type>();
122  bool res2 = testUQPromote<fad_uq_type>();
123 
124  typedef decltype(std::declval<uq_type>()*std::declval<uq_type>()) uq_expr_type;
125  typedef decltype(-std::declval<fad_uq_type>()) fad_uq_expr_type;
126  static_assert(
127  is_same<typename Promote<uq_expr_type,fad_uq_expr_type>::type, fad_uq_type >::value,
128  "Promote<uq_expr_type,fad_uq_expr_type>::type != fad_uq_type");
129 
130  return res1 && res2;
131 }
132 
133 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Promote, Promote, UQ )
134 {
135  success = testPromote<UQ>();
136 }
137 
138 typedef Kokkos::DefaultExecutionSpace device;
139 
140 #ifdef HAVE_STOKHOS_PCE_SCALAR_TYPE
141 //
142 // Sacado::PCE::OrthogPoly
143 //
145 typedef Sacado::PCE::OrthogPoly<double,storage_type> orthog_poly_type;
146 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Promote, Promote, orthog_poly_type )
147 
148 //
149 // Sacado::ETPCE::OrthogPoly
150 //
151 typedef Sacado::ETPCE::OrthogPoly<double,storage_type> et_orthog_poly_type;
152 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Promote, Promote, et_orthog_poly_type )
153 
154 //
155 // Sacado::UQ::PCE
156 //
157 typedef Stokhos::DynamicStorage<int,double,device> dynamic_storage_type;
158 typedef Sacado::UQ::PCE<dynamic_storage_type> kokkos_pce_type;
159 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Promote, Promote, kokkos_pce_type )
160 #endif
161 
162 #ifdef HAVE_STOKHOS_ENSEMBLE_SCALAR_TYPE
163 //
164 // Sacado::MP::Vector
165 //
166 
167 typedef Stokhos::StaticFixedStorage<int,double,32,device> static_storage_type;
168 typedef Sacado::MP::Vector<static_storage_type> kokkos_mp_type;
169 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( Promote, Promote, kokkos_mp_type )
170 #endif
171 
172 int main( int argc, char* argv[] ) {
173  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
175 }
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)