29 #include "Teuchos_UnitTestHarness.hpp" 30 #include "Teuchos_UnitTestRepository.hpp" 31 #include "Teuchos_GlobalMPISession.hpp" 41 using Kokkos::DynRankView;
46 using Kokkos::Experimental::view_alloc;
47 using Kokkos::Experimental::WithoutInitializing;
48 const unsigned derivative_dim_plus_one = 7;
52 DynRankView<FadType>
a(
"a",10,4,13,derivative_dim_plus_one);
54 TEST_EQUALITY(
a.rank(),3);
58 TEST_EQUALITY(b.rank(),3);
62 TEST_EQUALITY(
c.rank(),3);
64 using d_type = Kokkos::DynRankView<FadType,Kokkos::LayoutRight>;
65 d_type d = createDynRankViewWithType<d_type>(
a,
"d",5,3,8);
67 TEST_EQUALITY(d.rank(),3);
72 View<FadType*>
a(
"a",8,derivative_dim_plus_one);
77 TEST_EQUALITY(b.rank(),3);
81 TEST_EQUALITY(
c.rank(),3);
83 using d_type = Kokkos::DynRankView<FadType,Kokkos::LayoutRight>;
84 d_type d = createDynRankViewWithType<d_type>(
a,
"d",5,3,8);
86 TEST_EQUALITY(d.rank(),3);
91 View<FadType*>
a(
"a",8,derivative_dim_plus_one);
94 using b_type = Kokkos::View<FadType***>;
95 b_type b = createViewWithType<b_type>(
a,
"b",5,3,8);
98 b_type
c = createViewWithType<b_type>(
a,view_alloc(
"c",WithoutInitializing),5,3,8);
101 using d_type = Kokkos::View<FadType***,Kokkos::LayoutRight>;
102 d_type d = createViewWithType<d_type>(
a,
"d",5,3,8);
108 DynRankView<FadType>
a(
"a",10,4,13,derivative_dim_plus_one);
110 TEST_EQUALITY(
a.rank(),3);
112 using b_type = Kokkos::View<FadType***>;
113 b_type b = createViewWithType<b_type>(
a,
"b",5,3,8);
116 b_type
c = createViewWithType<b_type>(
a,view_alloc(
"c",WithoutInitializing),5,3,8);
119 using d_type = Kokkos::View<FadType***,Kokkos::LayoutRight>;
120 d_type d = createViewWithType<d_type>(
a,
"d",5,3,8);
126 DynRankView<double>
a(
"a",10,4,13);
128 TEST_EQUALITY(
a.rank(),3);
130 using b_type = Kokkos::DynRankView<FadType,Kokkos::LayoutRight>;
131 b_type b = createDynRankViewWithType<b_type>(
a,
"b",5,3,8);
133 TEST_EQUALITY(b.rank(),3);
138 DynRankView<double>
a(
"a",10,4,13);
140 TEST_EQUALITY(
a.rank(),3);
144 TEST_EQUALITY(b.rank(),3);
149 DynRankView<double>
a(
"a",10,4,13);
151 TEST_EQUALITY(
a.rank(),3);
155 TEST_EQUALITY(b.rank(),0);
160 DynRankView<FadType>
a(
"a",10,4,13,derivative_dim_plus_one);
162 TEST_EQUALITY(
a.rank(),3);
166 TEST_EQUALITY(b.rank(),0);
171 Kokkos::View<double*>
a(
"a",5*3);
172 using b_type = Kokkos::View<double**,Kokkos::MemoryUnmanaged>;
173 b_type b = createViewWithType<b_type>(
a,
a.data(),5,3);
174 TEST_EQUALITY(b.dimension_0(),5);
175 TEST_EQUALITY(b.dimension_1(),3);
181 Kokkos::View<FadType*>
a(
"a",5*3,derivative_dim_plus_one);
182 using b_type = Kokkos::View<FadType**,Kokkos::MemoryUnmanaged>;
183 b_type b = createViewWithType<b_type>(
a,
a.data(),5,3);
184 TEST_EQUALITY(b.dimension_0(),5);
185 TEST_EQUALITY(b.dimension_1(),3);
191 Kokkos::DynRankView<double>
a(
"a",10,13);
192 auto b = Kokkos::subview(
a, std::make_pair(4,8), std::make_pair(5,11));
194 using b_type = decltype(b);
195 using c_type = decltype(
c);
196 using b_layout =
typename b_type::array_layout;
197 using c_layout =
typename c_type::array_layout;
198 using default_layout =
typename b_type::device_type::execution_space::array_layout;
199 const bool is_b_layout_stride =
200 std::is_same<b_layout,Kokkos::LayoutStride>::value;
201 const bool is_c_default_layout =
202 std::is_same<c_layout,default_layout>::value;
203 TEST_EQUALITY(is_b_layout_stride,
true);
204 TEST_EQUALITY(is_c_default_layout,
true);
205 TEST_EQUALITY(
c.rank(),2);
206 TEST_EQUALITY(
c.dimension_0(),5);
207 TEST_EQUALITY(
c.dimension_1(),3);
213 Kokkos::DynRankView<FadType>
a(
"a",10,13,derivative_dim_plus_one);
214 auto b = Kokkos::subview(
a, std::make_pair(4,8), std::make_pair(5,11));
216 using b_type = decltype(b);
217 using c_type = decltype(
c);
218 using b_layout =
typename b_type::array_layout;
219 using c_layout =
typename c_type::array_layout;
220 using default_layout =
typename b_type::device_type::execution_space::array_layout;
221 const bool is_b_layout_stride =
222 std::is_same<b_layout,Kokkos::LayoutStride>::value;
223 const bool is_c_default_layout =
224 std::is_same<c_layout,default_layout>::value;
225 TEST_EQUALITY(is_b_layout_stride,
true);
226 TEST_EQUALITY(is_c_default_layout,
true);
227 TEST_EQUALITY(
c.rank(),2);
228 TEST_EQUALITY(
c.dimension_0(),5);
229 TEST_EQUALITY(
c.dimension_1(),3);
235 int main(
int argc,
char* argv[] ) {
236 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
238 Kokkos::initialize();
240 int res = Teuchos::UnitTestRepository::runUnitTestsFromMain(argc, argv);
std::enable_if< is_view< InputViewType >::value||is_dyn_rank_view< InputViewType >::value, ResultViewType >::type createDynRankViewWithType(const InputViewType &a, const CtorProp &prop, const Dims... dims)
Wrapper to simplify use of Sacado ViewFactory.
std::enable_if< is_view< InputViewType >::value||is_dyn_rank_view< InputViewType >::value, typename Impl::ResultDynRankView< InputViewType >::type >::type createDynRankView(const InputViewType &a, const CtorProp &prop, const Dims... dims)
Wrapper to simplify use of Sacado ViewFactory.
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
int main(int argc, char *argv[])
std::enable_if< is_view< InputViewType >::value||is_dyn_rank_view< InputViewType >::value, ResultViewType >::type createViewWithType(const InputViewType &a, const CtorProp &prop, const Dims... dims)
Wrapper to simplify use of Sacado ViewFactory.
TEUCHOS_UNIT_TEST(view_factory, dyn_rank_views)
unsigned dimension_scalar(const View &v, const ViewPack &... views)