50 Stokhos::create_product_tensor<Device>( *
setup.basis, *
setup.Cijk );
52 for (
int i=0; i<
setup.stoch_length; ++i) {
54 const int iEntryEnd = tensor.entry_end(i);
55 for (
int iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
56 const int kj = tensor.coord( iEntry );
57 const int j = kj & 0x0ffff;
58 const int k = kj >> 16;
61 value_type c2 = tensor.value(iEntry);
62 if (j == k) c2 *= 2.0;
64 int ii =
setup.inv_perm[i];
65 int jj =
setup.inv_perm[
j];
66 int kk =
setup.inv_perm[k];
67 value_type c =
setup.Cijk->getValue(ii,jj,kk);
70 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
71 <<
" == " << c2 <<
" failed!" << std::endl;
85 params.
set(
"Tile Size",10);
86 params.
set(
"Max Tiles",10000);
89 Stokhos::create_tiled_product_tensor<Device>( *
setup.basis, *
setup.Cijk,
96 const size_t n_tile = tensor.num_tiles();
97 for (
size_t tile = 0 ; tile < n_tile ; ++tile ) {
98 const size_t i_offset = tensor.offset(tile, 0);
99 const size_t j_offset = tensor.offset(tile, 1);
100 const size_t k_offset = tensor.offset(tile, 2);
101 const size_t n_row = tensor.num_rows(tile);
103 for (
size_t i=0; i<n_row; ++i) {
104 const size_t iEntryBeg = tensor.entry_begin(tile,i);
105 const size_t iEntryEnd = tensor.entry_end(tile,i);
106 for (
size_t iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
107 const size_t j = tensor.coord(iEntry,0);
108 const size_t k = tensor.coord(iEntry,1);
109 value_type c2 = tensor.value(iEntry);
110 int ii = i + i_offset;
111 int jj = j + j_offset;
112 int kk = k + k_offset;
115 value_type c =
setup.Cijk->getValue(ii,jj,kk);
118 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
119 <<
" == " << c2 <<
" failed!" << std::endl;
134 params.
set(
"Tile Size",10);
137 Stokhos::create_simple_tiled_product_tensor<Device>(
141 const size_t n_i_tile = tensor.num_i_tiles();
142 for (
size_t i_tile = 0; i_tile<n_i_tile; ++i_tile) {
143 const size_t i_begin = tensor.i_begin(i_tile);
144 const size_t i_size = tensor.i_size(i_tile);
146 const size_t n_j_tile = tensor.num_j_tiles(i_tile);
147 for (
size_t j_tile = 0; j_tile<n_j_tile; ++j_tile) {
148 const size_t j_begin = tensor.j_begin(i_tile, j_tile);
151 const size_t n_k_tile = tensor.num_k_tiles(i_tile, j_tile);
152 for (
size_t k_tile = 0; k_tile<n_k_tile; ++k_tile) {
153 const size_t k_begin = tensor.k_begin(i_tile, j_tile, k_tile);
156 for (
size_t i=0; i<i_size; ++i) {
157 const size_t iEntryBeg = tensor.entry_begin(i_tile,j_tile,k_tile,i);
158 const size_t iEntryEnd = tensor.entry_end(i_tile,j_tile,k_tile,i);
159 for (
size_t iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
160 const size_t j = tensor.coord(iEntry,0);
161 const size_t k = tensor.coord(iEntry,1);
162 value_type c2 = tensor.value(iEntry);
163 int ii = i + i_begin;
164 int jj = j + j_begin;
165 int kk = k + k_begin;
171 value_type c =
setup.Cijk->getValue(ii,jj,kk);
174 out <<
"(" << ii <<
"," << jj <<
"," << kk <<
"): " << c
175 <<
" == " << c2 <<
" failed!" << std::endl;
186 template <
typename Scalar,
typename Device,
bool Pack>
196 Stokhos::create_coo_product_tensor<Device, Pack>(
199 const size_t nEntry = tensor.entry_count();
201 for (
size_t entry = 0 ; entry < nEntry ; ++entry ) {
202 tensor.coord(entry, i, j, k);
203 value_type c2 = tensor.value(entry);
204 if (j == k) c2 *= 2.0;
205 value_type c = setup.
Cijk->getValue(i,j,k);
208 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
209 <<
" == " << c2 <<
" failed!" << std::endl;
218 success = test_coo_product_tensor_cijk<Scalar,Device,true>(
setup, out);
222 success = test_coo_product_tensor_cijk<Scalar,Device,false>(
setup, out);
230 typedef size_t size_type;
233 Stokhos::create_flat_sparse_3_tensor<Device>( *
setup.basis, *
setup.Cijk );
235 for (
int i=0; i<
setup.stoch_length; ++i) {
236 const size_type nk = tensor.
num_k(i);
237 const size_type kBeg = tensor.k_begin(i);
238 const size_type kEnd = kBeg + nk;
239 for (size_type kEntry = kBeg; kEntry < kEnd; ++kEntry) {
240 const size_type k = tensor.k_coord(kEntry);
241 const size_type nj = tensor.num_j(kEntry);
242 const size_type jBeg = tensor.j_begin(kEntry);
243 const size_type jEnd = jBeg + nj;
244 for (size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
245 const size_type
j = tensor.j_coord(jEntry);
246 value_type c2 = tensor.value(jEntry);
247 if (j == k) c2 *= 2.0;
248 value_type c =
setup.Cijk->getValue(i,j,k);
250 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
251 <<
" == " << c2 <<
" failed!" << std::endl;
264 typedef size_t size_type;
267 Stokhos::create_flat_sparse_3_tensor_kji<Device>(*
setup.basis, *
setup.Cijk);
268 const size_type nk = tensor.
num_k();
270 for ( size_type k = 0; k < nk; ++k) {
271 const size_type nj = tensor.num_j(k);
272 const size_type jBeg = tensor.j_begin(k);
273 const size_type jEnd = jBeg + nj;
274 for (size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
275 const size_type
j = tensor.j_coord(jEntry);
276 const size_type ni = tensor.num_i(jEntry);
277 const size_type iBeg = tensor.i_begin(jEntry);
278 const size_type iEnd = iBeg + ni;
279 for (size_type iEntry = iBeg; iEntry < iEnd; ++iEntry) {
280 const size_type i = tensor.i_coord(iEntry);
281 value_type c2 = tensor.value(iEntry);
282 if (j == k) c2 *= 2.0;
283 value_type c =
setup.Cijk->getValue(i,j,k);
285 out <<
"(" << i <<
"," << j <<
"," << k <<
"): " << c
286 <<
" == " << c2 <<
" failed!" << std::endl;
294 #define UNIT_TEST_GROUP_SCALAR_HOST_DEVICE( SCALAR, DEVICE ) \
295 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CrsProductTensorCijk, SCALAR, DEVICE ) \
296 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, TiledCrsProductTensorCijk, SCALAR, DEVICE ) \
297 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, SimpleTiledCrsProductTensorCijk, SCALAR, DEVICE ) \
298 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CooProductTensorCijk_Packed, SCALAR, DEVICE ) \
299 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, CooProductTensorCijk_Unpacked, SCALAR, DEVICE ) \
300 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, FlatSparseCijk, SCALAR, DEVICE ) \
301 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Kokkos_SG_SpMv, FlatSparseCijk_kji, SCALAR, DEVICE )
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool test_coo_product_tensor_cijk(const KokkosKernelsUnitTest::UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)
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.