Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_KokkosViewUQPCEUnitTest.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
13 
18 
19 //
20 // Tests various View< Sacado::UQ::PCE<...>,...> operations work
21 // as expected
22 //
23 
24 // Helper functions
25 
26 template <typename kokkos_cijk_type, typename ordinal_type>
29 {
30  using Teuchos::RCP;
31  using Teuchos::rcp;
32  using Teuchos::Array;
33 
40 
41  // Create product basis
42  Array< RCP<const one_d_basis> > bases(stoch_dim);
43  for (ordinal_type i=0; i<stoch_dim; i++)
44  bases[i] = rcp(new legendre_basis(poly_ord, true));
45  RCP<const product_basis> basis = rcp(new product_basis(bases));
46 
47  // Triple product tensor
48  RCP<Cijk> cijk = basis->computeTripleProductTensor();
49 
50  // Kokkos triple product tensor
51  kokkos_cijk_type kokkos_cijk =
52  Stokhos::create_product_tensor<execution_space>(*basis, *cijk);
53 
54  return kokkos_cijk;
55 }
56 
57 template <typename scalar, typename ordinal>
58 inline
59 scalar generate_pce_coefficient( const ordinal nFEM,
60  const ordinal nStoch,
61  const ordinal iColFEM,
62  const ordinal iStoch )
63 {
64  const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
65  const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
66  return X_fem + X_stoch;
67  //return 1.0;
68 }
69 
70 template <typename ViewType>
71 bool
72 checkPCEView(const ViewType& v, Teuchos::FancyOStream& out) {
73  typedef ViewType view_type;
74  typedef typename view_type::size_type size_type;
75  typedef typename view_type::HostMirror host_view_type;
76  typedef typename host_view_type::array_type host_array_type;
78 
79  // Copy to host
80  host_view_type h_v = Kokkos::create_mirror_view(v);
81  Kokkos::deep_copy(h_v, v);
82  host_array_type h_a = h_v;
83 
84  size_type num_rows, num_cols;
85 
86  // For layout left, sacado dimension becomes first dimension
87  // instead of last
88  bool is_right = std::is_same< typename ViewType::array_layout,
89  Kokkos::LayoutRight >::value;
90  if (is_right) {
91  num_rows = h_a.extent(0);
92  num_cols = h_a.extent(1);
93  }
94  else {
95  num_rows = h_a.extent(1);
96  num_cols = h_a.extent(0);
97  }
98  bool success = true;
99  if (is_right) {
100  for (size_type i=0; i<num_rows; ++i) {
101  for (size_type j=0; j<num_cols; ++j) {
102  scalar_type val = h_a(i,j);
103  scalar_type val_expected =
104  generate_pce_coefficient<scalar_type>(
105  num_rows, num_cols, i, j);
106  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
107  }
108  }
109  }
110  else {
111  for (size_type i=0; i<num_rows; ++i) {
112  for (size_type j=0; j<num_cols; ++j) {
113  scalar_type val = h_a(j,i);
114  scalar_type val_expected =
115  generate_pce_coefficient<scalar_type>(
116  num_rows, num_cols, i, j);
117  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
118  }
119  }
120  }
121 
122  return success;
123 }
124 
125 template <typename ViewType>
126 bool
127 checkConstantPCEView(const ViewType& v,
128  const typename ViewType::value_type& v_expected,
129  Teuchos::FancyOStream& out) {
130  typedef ViewType view_type;
131  typedef typename view_type::size_type size_type;
132  typedef typename view_type::HostMirror host_view_type;
134 
135  // Copy to host
136  host_view_type h_v = Kokkos::create_mirror_view(v);
137  Kokkos::deep_copy(h_v, v);
138 
139  const size_type num_rows = h_v.extent(0);
140  const size_type num_cols = Kokkos::dimension_scalar(h_v);
141 
142  bool success = true;
143  for (size_type i=0; i<num_rows; ++i) {
144  for (size_type j=0; j<num_cols; ++j) {
145  scalar_type val = h_v(i).coeff(j);
146  scalar_type val_expected = v_expected.coeff(j);
147  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
148  }
149  }
150 
151  return success;
152 }
153 
154 template <typename DataType, typename LayoutType, typename ExecutionSpace>
155 struct ApplyView {
156  typedef Kokkos::View<DataType,LayoutType,ExecutionSpace> type;
157 };
158 
159 struct NoLayout {};
160 template <typename DataType, typename ExecutionSpace>
161 struct ApplyView<DataType,NoLayout,ExecutionSpace> {
162  typedef Kokkos::View<DataType,ExecutionSpace> type;
163 };
164 
165 //
166 // Tests
167 //
168 
169 const int global_num_rows = 11;
170 const int global_num_cols = 9;
171 
172 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, Size, Storage, Layout )
173 {
174  typedef typename Storage::execution_space Device;
175  typedef Sacado::UQ::PCE<Storage> PCE;
176  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
177  typedef typename ViewType::size_type size_type;
178  //typedef size_t size_type;
179  typedef typename PCE::cijk_type Cijk;
180 
181  // Build Cijk tensor
182  const int stoch_dim = 2;
183  const int poly_ord = 3;
184  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
185 
186  const size_type num_rows = 11;
187  const size_type num_cols = cijk.dimension();
188  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
189  TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
190 }
191 
192 
193 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy, Storage, Layout )
194 {
195  typedef typename Storage::execution_space Device;
196  typedef typename Storage::value_type Scalar;
197  typedef Sacado::UQ::PCE<Storage> PCE;
198  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
199  typedef typename ViewType::size_type size_type;
200  typedef typename ViewType::HostMirror host_view_type;
201  typedef typename host_view_type::array_type host_array_type;
202  typedef typename PCE::cijk_type Cijk;
203 
204  // Build Cijk tensor
205  const int stoch_dim = 2;
206  const int poly_ord = 3;
207  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
208 
209  const size_type num_rows = 11;
210  const size_type num_cols = cijk.dimension();
211  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
212  host_view_type h_v = Kokkos::create_mirror_view(v);
213  host_array_type h_a = h_v;
214 
215  bool is_right = std::is_same< typename ViewType::array_layout,
216  Kokkos::LayoutRight >::value;
217  if (is_right) {
218  for (size_type i=0; i<num_rows; ++i)
219  for (size_type j=0; j<num_cols; ++j)
220  h_a(i,j) = generate_pce_coefficient<Scalar>(
221  num_rows, num_cols, i, j);
222  }
223  else {
224  for (size_type i=0; i<num_rows; ++i)
225  for (size_type j=0; j<num_cols; ++j)
226  h_a(j,i) = generate_pce_coefficient<Scalar>(
227  num_rows, num_cols, i, j);
228  }
229  Kokkos::deep_copy(v, h_v);
230 
231  success = checkPCEView(v, out);
232 }
233 
234 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_NonContiguous, Storage, Layout )
235 {
236  typedef typename Storage::execution_space Device;
237  typedef typename Storage::value_type Scalar;
238  typedef Sacado::UQ::PCE<Storage> PCE;
239  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
240  typedef Kokkos::HostSpace HostDevice;
241  typedef Kokkos::View<PCE*,typename ViewType::array_layout,HostDevice,Kokkos::MemoryUnmanaged> HostViewType;
242  typedef typename ViewType::size_type size_type;
243  typedef typename PCE::cijk_type Cijk;
244 
245  // Build Cijk tensor
246  const int stoch_dim = 2;
247  const int poly_ord = 3;
248  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
249 
250  const size_type num_rows = 11;
251  const size_type num_cols = cijk.dimension();
252  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
253 
254  Teuchos::Array<PCE> a(num_rows);
255  for (size_type i=0; i<num_rows; ++i) {
256  a[i].reset(cijk);
257  for (size_type j=0; j<num_cols; ++j)
258  a[i].fastAccessCoeff(j) = generate_pce_coefficient<Scalar>(
259  num_rows, num_cols, i, j);
260  }
261  // HostViewType ha(a.getRawPtr(), cijk, num_rows, num_cols);
262  HostViewType ha =
263  Kokkos::make_view<HostViewType>(a.getRawPtr(), cijk, num_rows, num_cols);
264  Kokkos::deep_copy(v, ha);
265 
266  success = checkPCEView(v, out);
267 }
268 
269 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_ConstantScalar, Storage, Layout )
270 {
271  typedef typename Storage::execution_space Device;
272  typedef typename Storage::value_type Scalar;
273  typedef Sacado::UQ::PCE<Storage> PCE;
274  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
275  typedef typename ViewType::size_type size_type;
276  typedef typename PCE::cijk_type Cijk;
277 
278  // Build Cijk tensor
279  const int stoch_dim = 2;
280  const int poly_ord = 3;
281  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
282 
283  const size_type num_rows = 11;
284  const size_type num_cols = cijk.dimension();
285  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
286  Scalar val = 1.2345;
287 
288  Kokkos::deep_copy( v, val );
289 
290  PCE pce_val(cijk); pce_val.fastAccessCoeff(0) = val;
291  success = checkConstantPCEView(v, pce_val, out);
292 }
293 
294 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_ConstantPCE, Storage, Layout )
295 {
296  typedef typename Storage::execution_space Device;
297  typedef typename Storage::value_type Scalar;
298  typedef Sacado::UQ::PCE<Storage> PCE;
299  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
300  typedef typename ViewType::size_type size_type;
301  typedef typename PCE::cijk_type Cijk;
302 
303  // Build Cijk tensor
304  const int stoch_dim = 2;
305  const int poly_ord = 3;
306  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
307 
308  const size_type num_rows = 11;
309  const size_type num_cols = cijk.dimension();
310  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
311  Scalar val = 1.2345;
312 
313  Kokkos::deep_copy( v, PCE(val) );
314 
315  PCE pce_val(cijk); pce_val.fastAccessCoeff(0) = val;
316  success = checkConstantPCEView(v, pce_val, out);
317 }
318 
319 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_ConstantPCE2, Storage, Layout )
320 {
321  typedef typename Storage::execution_space Device;
322  typedef typename Storage::value_type Scalar;
323  typedef Sacado::UQ::PCE<Storage> PCE;
324  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
325  typedef typename ViewType::size_type size_type;
326  typedef typename PCE::cijk_type Cijk;
327 
328  // Build Cijk tensor
329  const int stoch_dim = 2;
330  const int poly_ord = 3;
331  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
332 
333  const size_type num_rows = 11;
334  const size_type num_cols = cijk.dimension();
335  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
336  PCE val(cijk);
337  for (size_type j=0; j<num_cols; ++j)
338  val.fastAccessCoeff(j) =
339  generate_pce_coefficient<Scalar>(num_rows, num_cols, size_type(0), j);
340 
341  Kokkos::deep_copy( v, val );
342 
343  success = checkConstantPCEView(v, val, out);
344 }
345 
346 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Kokkos_View_PCE, DeepCopy_Subview_Range, Storage )
347 {
348  typedef typename Storage::execution_space Device;
349  typedef typename Storage::value_type Scalar;
350  typedef Sacado::UQ::PCE<Storage> PCE;
351  typedef typename ApplyView<PCE**,Kokkos::LayoutLeft,Device>::type ViewType;
352  typedef typename ViewType::size_type size_type;
353  typedef typename ViewType::HostMirror host_view_type;
354  typedef typename PCE::cijk_type Cijk;
355 
356  // Build Cijk tensor
357  const int stoch_dim = 2;
358  const int poly_ord = 3;
359  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
360 
361  const size_type num_rows1 = global_num_rows;
362  const size_type num_rows2 = global_num_rows*2;
363  const size_type num_cols = 5;
364  const size_type num_pce = cijk.dimension();
365  ViewType v1 = Kokkos::make_view<ViewType>("view1", cijk, num_rows1, num_cols);
366  ViewType v2 = Kokkos::make_view<ViewType>("view2", cijk, num_rows2, num_cols);
367 
368  for (size_type j=0; j<num_cols; ++j) {
369  std::pair<size_type,size_type> rows( 0, num_rows1 );
370  ViewType v1s = Kokkos::subview( v1, rows, std::pair<size_t,size_t> (j,j+1) );
371  ViewType v2s = Kokkos::subview( v2, rows, std::pair<size_t,size_t> (j,j+1) );
372  Kokkos::deep_copy( v1s, Scalar(j+1) );
373  Kokkos::deep_copy( v2s, v1s );
374  }
375 
376  // Check
377  success = true;
378  host_view_type hv2 = Kokkos::create_mirror_view( v2 );
379  Kokkos::deep_copy( hv2, v2 );
380  for (size_type j=0; j<num_cols; ++j) {
381  for (size_type i=0; i<num_rows1; ++i) {
382  for (size_type k=0; k<num_pce; ++k) {
383  Scalar val = hv2(i,j).fastAccessCoeff(k);
384  Scalar val_expected = k == 0 ? Scalar(j+1) : Scalar(0);
385  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
386  }
387  }
388  for (size_type i=num_rows1; i<num_rows2; ++i) {
389  for (size_type k=0; k<num_pce; ++k) {
390  Scalar val = hv2(i,j).fastAccessCoeff(k);
391  Scalar val_expected = 0;
392  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
393  }
394  }
395  }
396 }
397 
398 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_HostArray, Storage, Layout )
399 {
400  typedef typename Storage::execution_space Device;
401  typedef typename Storage::value_type Scalar;
402  typedef Sacado::UQ::PCE<Storage> PCE;
403  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
404  typedef typename ViewType::size_type size_type;
405  typedef typename ViewType::HostMirror host_view_type;
406  typedef typename host_view_type::array_type host_array_type;
407  typedef typename PCE::cijk_type Cijk;
408 
409  // Build Cijk tensor
410  const int stoch_dim = 2;
411  const int poly_ord = 3;
412  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
413 
414  const size_type num_rows = 11;
415  const size_type num_cols = cijk.dimension();
416  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
417  host_array_type h_a = Kokkos::create_mirror_view(v);
418 
419  bool is_right = std::is_same< typename ViewType::array_layout,
420  Kokkos::LayoutRight >::value;
421  if (is_right) {
422  for (size_type i=0; i<num_rows; ++i)
423  for (size_type j=0; j<num_cols; ++j)
424  h_a(i,j) = generate_pce_coefficient<Scalar>(
425  num_rows, num_cols, i, j);
426  }
427  else {
428  for (size_type i=0; i<num_rows; ++i)
429  for (size_type j=0; j<num_cols; ++j)
430  h_a(j,i) = generate_pce_coefficient<Scalar>(
431  num_rows, num_cols, i, j);
432  }
433  Kokkos::deep_copy(v, h_a);
434 
435  success = checkPCEView(v, out);
436 }
437 
438 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_DeviceArray, Storage, Layout )
439 {
440  typedef typename Storage::execution_space Device;
441  typedef typename Storage::value_type Scalar;
442  typedef Sacado::UQ::PCE<Storage> PCE;
443  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
444  typedef typename ViewType::size_type size_type;
445  typedef typename ViewType::HostMirror host_view_type;
446  typedef typename host_view_type::array_type host_array_type;
447  typedef typename ViewType::array_type array_type;
448  typedef typename PCE::cijk_type Cijk;
449 
450  // Build Cijk tensor
451  const int stoch_dim = 2;
452  const int poly_ord = 3;
453  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
454 
455  const size_type num_rows = 11;
456  const size_type num_cols = cijk.dimension();
457  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
458  host_view_type h_v = Kokkos::create_mirror_view(v);
459  host_array_type h_a = h_v;
460  array_type a = v;
461 
462  for (size_type i=0; i<num_rows; ++i)
463  for (size_type j=0; j<num_cols; ++j)
464  h_a(i,j) = generate_pce_coefficient<Scalar>(
465  num_rows, num_cols, i, j);
466  Kokkos::deep_copy(a, h_v);
467 
468  success = checkPCEView(v, out);
469 }
470 
471 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, Unmanaged, Storage, Layout )
472 {
473  typedef typename Storage::execution_space Device;
474  typedef typename Storage::value_type Scalar;
475  typedef Sacado::UQ::PCE<Storage> PCE;
476  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
477  typedef typename ViewType::size_type size_type;
478  typedef typename ViewType::HostMirror host_view_type;
479  typedef typename host_view_type::array_type host_array_type;
480  typedef typename PCE::cijk_type Cijk;
481 
482  // Build Cijk tensor
483  const int stoch_dim = 2;
484  const int poly_ord = 3;
485  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
486 
487  const size_type num_rows = 11;
488  const size_type num_cols = cijk.dimension();
489  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
490  host_view_type h_v = Kokkos::create_mirror_view(v);
491  host_array_type h_a = h_v;
492 
493  bool is_right = std::is_same< typename ViewType::array_layout,
494  Kokkos::LayoutRight >::value;
495  if (is_right) {
496  for (size_type i=0; i<num_rows; ++i)
497  for (size_type j=0; j<num_cols; ++j)
498  h_a(i,j) = generate_pce_coefficient<Scalar>(
499  num_rows, num_cols, i, j);
500  }
501  else {
502  for (size_type i=0; i<num_rows; ++i)
503  for (size_type j=0; j<num_cols; ++j)
504  h_a(j,i) = generate_pce_coefficient<Scalar>(
505  num_rows, num_cols, i, j);
506  }
507  Kokkos::deep_copy(v, h_v);
508 
509  // Create unmanaged view
510  ViewType v2 =
511  Kokkos::make_view<ViewType>( v.data(), cijk, num_rows, num_cols );
512 
513  success = checkPCEView(v2, out);
514 }
515 
516 
517 namespace Test {
518 
519 template< class ViewType >
522 
523  typedef typename ViewType::value_type pce_type ;
525 
527  ViewType m_v ;
528 
529  PCEAtomicFunctor( const ViewType & v , const scalar_type & s ) :
530  m_v( v ), m_s( s )
531  {
532  Kokkos::parallel_for( m_v.extent(0) , *this );
533  }
534 
535  KOKKOS_INLINE_FUNCTION
536  void operator()( int i ) const
537  {
538  pce_type v( m_s );
539  atomic_assign( & m_v(i) , v );
540  }
541 };
542 
543 }
544 
545 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeviceAtomic, Storage, Layout )
546 {
547  typedef typename Storage::execution_space Device;
548  typedef typename Storage::value_type Scalar;
549  typedef Sacado::UQ::PCE<Storage> PCE;
550  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
551  typedef typename ViewType::size_type size_type;
552  typedef typename PCE::cijk_type Cijk;
553 
554  // Build Cijk tensor
555  const int stoch_dim = 2;
556  const int poly_ord = 3;
557  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
558 
559  const size_type num_rows = 11;
560  const size_type num_cols = cijk.dimension();
561  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
562  Scalar val = 1.2345;
563 
564  (void) Test::PCEAtomicFunctor<ViewType>( v , val );
565 
566  success = checkConstantPCEView(v, val, out);
567 }
568 
569 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, AssignData, Storage, Layout )
570 {
571  typedef typename Storage::execution_space Device;
572  typedef typename Storage::value_type Scalar;
573  typedef Sacado::UQ::PCE<Storage> PCE;
574  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
575  typedef typename ViewType::size_type size_type;
576  //typedef size_t size_type;
577  typedef typename PCE::cijk_type Cijk;
578 
579  // Build Cijk tensor
580  const int stoch_dim = 2;
581  const int poly_ord = 3;
582  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
583 
584  const size_type num_rows = 11;
585  const size_type num_cols = cijk.dimension();
586  ViewType v1 = Kokkos::make_view<ViewType>("view1", cijk, num_rows, num_cols);
587  ViewType v2 = Kokkos::make_view<ViewType>("view2", cijk, num_rows, num_cols);
588  Scalar val1 = 1.234;
589  Scalar val2 = 5.678;
590  Kokkos::deep_copy(v1, val1);
591  Kokkos::deep_copy(v2, val2);
592 
593  auto s1 = Kokkos::subview(v1, std::make_pair(0, 1));
594  auto s2 = Kokkos::subview(v2, std::make_pair(0, 1));
595 
596  s1.assign_data(s2.data());
597 
598  success = checkConstantPCEView(s1, val2, out);
599 }
600 
601 /*
602 */
603 
604 #define VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT( STORAGE, LAYOUT ) \
605  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
606  Kokkos_View_PCE, Size, STORAGE, LAYOUT ) \
607  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
608  Kokkos_View_PCE, DeepCopy, STORAGE, LAYOUT ) \
609  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
610  Kokkos_View_PCE, DeepCopy_NonContiguous, STORAGE, LAYOUT ) \
611  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
612  Kokkos_View_PCE, DeepCopy_ConstantScalar, STORAGE, LAYOUT ) \
613  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
614  Kokkos_View_PCE, DeepCopy_ConstantPCE, STORAGE, LAYOUT ) \
615  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
616  Kokkos_View_PCE, DeepCopy_ConstantPCE2, STORAGE, LAYOUT ) \
617  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
618  Kokkos_View_PCE, Unmanaged, STORAGE, LAYOUT ) \
619  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
620  Kokkos_View_PCE, AssignData, STORAGE, LAYOUT )
621 
622 // Some tests the fail, or fail to compile
623 
624  /*
625  // These don't compile as there are no deep_copy overloads between
626  // static view spec and its array_type. That could be done, but
627  // would require some additional work to ensure the shapes match.
628  // It is simple enough to create an array_type view, so deep copying
629  // between matching views isn't much more trouble.
630  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
631  Kokkos_View_PCE, DeepCopy_HostArray, STORAGE, LAYOUT ) \
632  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
633  Kokkos_View_PCE, DeepCopy_DeviceArray, STORAGE, LAYOUT )
634  */
635 
636 #define VIEW_UQ_PCE_TESTS_STORAGE( STORAGE ) \
637  using Kokkos::LayoutLeft; \
638  using Kokkos::LayoutRight; \
639  VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \
640  VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \
641  VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \
642  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
643  Kokkos_View_PCE, DeepCopy_Subview_Range, STORAGE )
644 
645 #define VIEW_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \
646  typedef Stokhos::DynamicStorage<ORDINAL,SCALAR,DEVICE> DS; \
647  VIEW_UQ_PCE_TESTS_STORAGE( DS )
648 
649 #define VIEW_UQ_PCE_TESTS_DEVICE( DEVICE ) \
650  VIEW_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( int, double, DEVICE )
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
bool checkConstantPCEView(const ViewType &v, const typename ViewType::value_type &v_expected, Teuchos::FancyOStream &out)
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_SG_SpMv, CrsProductTensorCijk, Scalar, Device)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
pce_type::storage_type::value_type scalar_type
KOKKOS_INLINE_FUNCTION void atomic_assign(volatile Sacado::UQ::PCE< Storage > *const dest, const Sacado::UQ::PCE< Storage > &src)
scalar generate_pce_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
KOKKOS_INLINE_FUNCTION void operator()(int i) const
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
view_type::array_type::non_const_value_type type
kokkos_cijk_type build_cijk(ordinal_type stoch_dim, ordinal_type poly_ord)
ViewType::execution_space execution_space
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
Legendre polynomial basis.
expr val()
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Abstract base class for 1-D orthogonal polynomials.
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)
Kokkos::View< DataType, LayoutType, ExecutionSpace > type
bool checkPCEView(const ViewType &v, Teuchos::FancyOStream &out)
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
PCEAtomicFunctor(const ViewType &v, const scalar_type &s)