18 Stokhos::create_product_tensor<Device>( *
setup.basis, *
setup.Cijk );
20 for (
int i=0; i<
setup.stoch_length; ++i) {
22 const int iEntryEnd = tensor.entry_end(i);
23 for (
int iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
24 const int kj = tensor.coord( iEntry );
25 const int j = kj & 0x0ffff;
26 const int k = kj >> 16;
29 value_type c2 = tensor.value(iEntry);
30 if (j == k) c2 *= 2.0;
32 int ii =
setup.inv_perm[i];
33 int jj =
setup.inv_perm[
j];
34 int kk =
setup.inv_perm[k];
35 value_type c =
setup.Cijk->getValue(ii,jj,kk);
38 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
39 <<
" == " << c2 <<
" failed!" << std::endl;
53 params.
set(
"Tile Size",10);
54 params.
set(
"Max Tiles",10000);
57 Stokhos::create_tiled_product_tensor<Device>( *
setup.basis, *
setup.Cijk,
64 const size_t n_tile = tensor.num_tiles();
65 for (
size_t tile = 0 ; tile < n_tile ; ++tile ) {
66 const size_t i_offset = tensor.offset(tile, 0);
67 const size_t j_offset = tensor.offset(tile, 1);
68 const size_t k_offset = tensor.offset(tile, 2);
69 const size_t n_row = tensor.num_rows(tile);
71 for (
size_t i=0; i<n_row; ++i) {
72 const size_t iEntryBeg = tensor.entry_begin(tile,i);
73 const size_t iEntryEnd = tensor.entry_end(tile,i);
74 for (
size_t iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
75 const size_t j = tensor.coord(iEntry,0);
76 const size_t k = tensor.coord(iEntry,1);
77 value_type c2 = tensor.value(iEntry);
78 int ii = i + i_offset;
79 int jj = j + j_offset;
80 int kk = k + k_offset;
83 value_type c =
setup.Cijk->getValue(ii,jj,kk);
86 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
87 <<
" == " << c2 <<
" failed!" << std::endl;
102 params.
set(
"Tile Size",10);
105 Stokhos::create_simple_tiled_product_tensor<Device>(
109 const size_t n_i_tile = tensor.num_i_tiles();
110 for (
size_t i_tile = 0; i_tile<n_i_tile; ++i_tile) {
111 const size_t i_begin = tensor.i_begin(i_tile);
112 const size_t i_size = tensor.i_size(i_tile);
114 const size_t n_j_tile = tensor.num_j_tiles(i_tile);
115 for (
size_t j_tile = 0; j_tile<n_j_tile; ++j_tile) {
116 const size_t j_begin = tensor.j_begin(i_tile, j_tile);
119 const size_t n_k_tile = tensor.num_k_tiles(i_tile, j_tile);
120 for (
size_t k_tile = 0; k_tile<n_k_tile; ++k_tile) {
121 const size_t k_begin = tensor.k_begin(i_tile, j_tile, k_tile);
124 for (
size_t i=0; i<i_size; ++i) {
125 const size_t iEntryBeg = tensor.entry_begin(i_tile,j_tile,k_tile,i);
126 const size_t iEntryEnd = tensor.entry_end(i_tile,j_tile,k_tile,i);
127 for (
size_t iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
128 const size_t j = tensor.coord(iEntry,0);
129 const size_t k = tensor.coord(iEntry,1);
130 value_type c2 = tensor.value(iEntry);
131 int ii = i + i_begin;
132 int jj = j + j_begin;
133 int kk = k + k_begin;
139 value_type c =
setup.Cijk->getValue(ii,jj,kk);
142 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
143 <<
" == " << c2 <<
" failed!" << std::endl;
154 template <
typename Scalar,
typename Device,
bool Pack>
164 Stokhos::create_coo_product_tensor<Device, Pack>(
167 const size_t nEntry = tensor.entry_count();
169 for (
size_t entry = 0 ; entry < nEntry ; ++entry ) {
170 tensor.coord(entry, i, j, k);
171 value_type c2 = tensor.value(entry);
172 if (j == k) c2 *= 2.0;
173 value_type c = setup.
Cijk->getValue(i,j,k);
176 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
177 <<
" == " << c2 <<
" failed!" << std::endl;
186 success = test_coo_product_tensor_cijk<Scalar,Device,true>(
setup, out);
190 success = test_coo_product_tensor_cijk<Scalar,Device,false>(
setup, out);
198 typedef size_t size_type;
201 Stokhos::create_flat_sparse_3_tensor<Device>( *
setup.basis, *
setup.Cijk );
203 for (
int i=0; i<
setup.stoch_length; ++i) {
204 const size_type nk = tensor.
num_k(i);
205 const size_type kBeg = tensor.k_begin(i);
206 const size_type kEnd = kBeg + nk;
207 for (size_type kEntry = kBeg; kEntry < kEnd; ++kEntry) {
208 const size_type k = tensor.k_coord(kEntry);
209 const size_type nj = tensor.num_j(kEntry);
210 const size_type jBeg = tensor.j_begin(kEntry);
211 const size_type jEnd = jBeg + nj;
212 for (size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
213 const size_type
j = tensor.j_coord(jEntry);
214 value_type c2 = tensor.value(jEntry);
215 if (j == k) c2 *= 2.0;
216 value_type c =
setup.Cijk->getValue(i,j,k);
218 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
219 <<
" == " << c2 <<
" failed!" << std::endl;
232 typedef size_t size_type;
235 Stokhos::create_flat_sparse_3_tensor_kji<Device>(*
setup.basis, *
setup.Cijk);
236 const size_type nk = tensor.
num_k();
238 for ( size_type k = 0; k < nk; ++k) {
239 const size_type nj = tensor.num_j(k);
240 const size_type jBeg = tensor.j_begin(k);
241 const size_type jEnd = jBeg + nj;
242 for (size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
243 const size_type
j = tensor.j_coord(jEntry);
244 const size_type ni = tensor.num_i(jEntry);
245 const size_type iBeg = tensor.i_begin(jEntry);
246 const size_type iEnd = iBeg + ni;
247 for (size_type iEntry = iBeg; iEntry < iEnd; ++iEntry) {
248 const size_type i = tensor.i_coord(iEntry);
249 value_type c2 = tensor.value(iEntry);
250 if (j == k) c2 *= 2.0;
251 value_type c =
setup.Cijk->getValue(i,j,k);
253 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
254 <<
" == " << c2 <<
" failed!" << std::endl;
262 #define UNIT_TEST_GROUP_SCALAR_HOST_DEVICE( SCALAR, DEVICE ) \
263 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CrsProductTensorCijk, SCALAR, DEVICE ) \
264 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, TiledCrsProductTensorCijk, SCALAR, DEVICE ) \
265 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, SimpleTiledCrsProductTensorCijk, SCALAR, DEVICE ) \
266 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CooProductTensorCijk_Packed, SCALAR, DEVICE ) \
267 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CooProductTensorCijk_Unpacked, SCALAR, DEVICE ) \
268 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, FlatSparseCijk, SCALAR, DEVICE ) \
269 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, FlatSparseCijk_kji, SCALAR, DEVICE )
bool test_coo_product_tensor_cijk(const KokkosKernelsUnitTest::UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_SG_SpMv, CrsProductTensorCijk, Scalar, Device)
KOKKOS_INLINE_FUNCTION size_type num_k() const
Number of k entries.
KOKKOS_INLINE_FUNCTION size_type entry_begin(size_type i) const
Begin entries with a coordinate 'i'.
UnitTestSetup< int, double > setup
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION size_type num_k(size_type i) const
Number of k entries with a coordinate 'i'.
RCP< product_basis_type > basis
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
Sparse product tensor using 'COO'-like storage format.