@@ -189,16 +189,14 @@ struct TestFunctor {
189189 auto row_ptr = iblockrow.local_row_in_block (blk, lrow);
190190 for (auto lcol = 0 ; lcol < A.blockDim (); ++lcol) {
191191 auto entry = iblockrow.local_block_value (blk, lrow, lcol);
192- // std::cout << "check0: " << ( entry == row_ptr[lcol] );
193- // std::cout << "check1: " << ( entry == view_blk(lrow,lcol) );
194- check0 = check0 && (entry == row_ptr[lcol]);
195- check1 = check1 && (entry == view_blk (lrow, lcol));
192+ check0 &= (entry == row_ptr[lcol]);
193+ check1 &= (entry == view_blk (lrow, lcol));
196194 } // end local col in row
197195 } // end local row in blk
198196 } // end blk
199197 }
200- d_results (0 ) = check0;
201- d_results (1 ) = check1;
198+ d_results (0 ) & = check0;
199+ d_results (1 ) & = check1;
202200
203201 // Test BsrRowViewConst
204202 {
@@ -210,16 +208,14 @@ struct TestFunctor {
210208 auto row_ptr = iblockrow.local_row_in_block (blk, lrow);
211209 for (auto lcol = 0 ; lcol < A.blockDim (); ++lcol) {
212210 auto entry = iblockrow.local_block_value (blk, lrow, lcol);
213- check2 = check2 && (entry == row_ptr[lcol]);
214- check3 = check3 && (entry == view_blk (lrow, lcol));
211+ check2 &= (entry == row_ptr[lcol]);
212+ check3 &= (entry == view_blk (lrow, lcol));
215213 } // end local col in row
216214 } // end local row in blk
217215 } // end blk
218216 }
219- d_results (0 ) = check0;
220- d_results (1 ) = check1;
221- d_results (2 ) = check2;
222- d_results (3 ) = check3;
217+ d_results (2 ) &= check2;
218+ d_results (3 ) &= check3;
223219 } // end for blk rows
224220
225221 // Test sumIntoValues
@@ -243,14 +239,14 @@ struct TestFunctor {
243239 auto row_ptr = iblockrow.local_row_in_block (relBlk, lrow);
244240 for (auto lcol = 0 ; lcol < A.blockDim (); ++lcol) {
245241 auto entry = iblockrow.local_block_value (relBlk, lrow, lcol);
246- check0 = check0 && (entry == row_ptr[lcol]);
247- check1 = check1 && (entry == view_blk (lrow, lcol));
248- check2 = check2 && (entry == result[lrow * A.blockDim () + lcol]);
242+ check0 &= (entry == row_ptr[lcol]);
243+ check1 &= (entry == view_blk (lrow, lcol));
244+ check2 &= (entry == result[lrow * A.blockDim () + lcol]);
249245 } // end local col in row
250246 } // end local row in blk
251- d_results (4 ) = check0;
252- d_results (5 ) = check1;
253- d_results (6 ) = check2;
247+ d_results (4 ) & = check0;
248+ d_results (5 ) & = check1;
249+ d_results (6 ) & = check2;
254250 }
255251
256252 // Test replaceValues
@@ -273,19 +269,79 @@ struct TestFunctor {
273269 auto row_ptr = iblockrow.local_row_in_block (relBlk, lrow);
274270 for (auto lcol = 0 ; lcol < A.blockDim (); ++lcol) {
275271 auto entry = iblockrow.local_block_value (relBlk, lrow, lcol);
276- check0 = check0 && (entry == row_ptr[lcol]);
277- check1 = check1 && (entry == view_blk (lrow, lcol));
278- check2 = check2 && (entry == valsreplace[lrow * A.blockDim () + lcol]);
272+ check0 &= (entry == row_ptr[lcol]);
273+ check1 &= (entry == view_blk (lrow, lcol));
274+ check2 &= (entry == valsreplace[lrow * A.blockDim () + lcol]);
279275 } // end local col in row
280276 } // end local row in blk
281- d_results (7 ) = check0;
282- d_results (8 ) = check1;
283- d_results (9 ) = check2;
277+ d_results (7 ) & = check0;
278+ d_results (8 ) & = check1;
279+ d_results (9 ) & = check2;
284280 }
285-
286281 } // end operator()(i)
287282}; // end TestFunctor
288283
284+ template <class BsrMatrixType , class ResultsType >
285+ struct TestConvFunctor {
286+ typedef typename BsrMatrixType::value_type scalar_t ;
287+ typedef typename BsrMatrixType::ordinal_type lno_t ;
288+ typedef typename BsrMatrixType::size_type size_type;
289+
290+ // Members
291+ BsrMatrixType A_;
292+ BsrMatrixType A_bsr_conv_;
293+ ResultsType d_results_;
294+
295+ // Constructor
296+ TestConvFunctor (BsrMatrixType &A, ResultsType &d_results) : A_(A), d_results_(d_results) {
297+ auto A_crs = A_.convertToCrs ();
298+ A_bsr_conv_ = BsrMatrixType (A_crs, A_.blockDim ());
299+ }
300+
301+ KOKKOS_INLINE_FUNCTION
302+ void operator ()(const int /* rid*/ ) const {
303+ // Test 1: Converting to Crs and then back to Bsr should give us an indentical bsr
304+ bool check0 = true ;
305+ bool check1 = true ;
306+ bool check2 = true ;
307+ bool check3 = true ;
308+ bool check4 = true ;
309+ bool check5 = true ;
310+ bool check6 = true ;
311+ int result_idx = 0 ;
312+
313+ check0 = A_bsr_conv_.numRows () == A_.numRows ();
314+ check1 = A_bsr_conv_.numCols () == A_.numCols ();
315+ check2 = A_bsr_conv_.blockDim () == A_.blockDim ();
316+ check3 = A_bsr_conv_.nnz () == A_.nnz ();
317+
318+ const auto blockRowMap1 = A_.graph .row_map ;
319+ const auto blockEntries1 = A_.graph .entries ;
320+ const auto blockValues1 = A_.values ;
321+
322+ const auto blockRowMap2 = A_.graph .row_map ;
323+ const auto blockEntries2 = A_.graph .entries ;
324+ const auto blockValues2 = A_.values ;
325+
326+ for (lno_t i = 0 ; i < A_.numRows () + 1 ; ++i) {
327+ check4 &= (blockRowMap1 (i) == blockRowMap2 (i));
328+ }
329+
330+ for (size_type i = 0 ; i < A_.nnz (); ++i) {
331+ check5 &= (blockEntries1 (i) == blockEntries2 (i));
332+ check6 &= (blockValues1 (i) == blockValues2 (i));
333+ }
334+
335+ d_results_ (result_idx++) = check0;
336+ d_results_ (result_idx++) = check1;
337+ d_results_ (result_idx++) = check2;
338+ d_results_ (result_idx++) = check3;
339+ d_results_ (result_idx++) = check4;
340+ d_results_ (result_idx++) = check5;
341+ d_results_ (result_idx++) = check6;
342+ } // end operator()(i)
343+ }; // end TestConvFunctor
344+
289345} // namespace Test_Bsr
290346
291347// Create a CrsMatrix and BsrMatrix and test member functions.
@@ -299,13 +355,26 @@ void testBsrMatrix() {
299355 crs_matrix_type crsA = makeCrsMatrix_BlockStructure<crs_matrix_type>();
300356 bsr_matrix_type A = makeBsrMatrix<bsr_matrix_type>();
301357
302- const int num_entries = 10 ;
358+ static constexpr int num_entries = 10 ;
303359 typedef Kokkos::View<bool [num_entries], device> result_view_type;
304360 result_view_type d_results (" d_results" );
361+ Kokkos::deep_copy (d_results, true );
305362 auto h_results = Kokkos::create_mirror_view (d_results);
363+ Test_Bsr::TestFunctor<bsr_matrix_type, result_view_type> functor (A, d_results);
364+
365+ Kokkos::parallel_for (" KokkosSparse::Test_Bsr::BsrMatrix" , Kokkos::RangePolicy<typename device::execution_space>(0 , 1 ),
366+ functor);
367+
368+ Kokkos::deep_copy (h_results, d_results);
369+
370+ for (decltype (h_results.extent (0 )) i = 0 ; i < h_results.extent (0 ); ++i) {
371+ EXPECT_EQ (h_results[i], true );
372+ }
306373
374+ Kokkos::deep_copy (d_results, true );
375+ Test_Bsr::TestConvFunctor<bsr_matrix_type, result_view_type> conv_functor (A, d_results);
307376 Kokkos::parallel_for (" KokkosSparse::Test_Bsr::BsrMatrix" , Kokkos::RangePolicy<typename device::execution_space>(0 , 1 ),
308- Test_Bsr::TestFunctor<bsr_matrix_type, result_view_type>(A, d_results) );
377+ conv_functor );
309378
310379 Kokkos::deep_copy (h_results, d_results);
311380
0 commit comments