Skip to content

Commit

Permalink
Add testing for transpose corner cases (#2234)
Browse files Browse the repository at this point in the history
* Add testing for transpose corner cases

crs, bsr, graph: test cases that are 0x0, 100x0 and 0x100. In these cases make
sure the matrix generator doesn't try to insert any entries (nnz = 0).

* Update sparse/unit_test/Test_Sparse_Transpose.hpp

Co-authored-by: Luc Berger <lberge@sandia.gov>

* Update sparse/unit_test/Test_Sparse_Transpose.hpp

Co-authored-by: Luc Berger <lberge@sandia.gov>

---------

Co-authored-by: Luc Berger <lberge@sandia.gov>
  • Loading branch information
brian-kelley and lucbv authored Jun 10, 2024
1 parent d06924a commit 1696b1c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sparse/unit_test/Test_Sparse_Transpose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void testTranspose(int numRows, int numCols, bool doValues) {
using rowmap_t = typename crsMat_t::row_map_type::non_const_type;
using entries_t = typename crsMat_t::index_type::non_const_type;
using values_t = typename crsMat_t::values_type::non_const_type;
size_type nnz = 10 * numRows;
size_type nnz = (numRows * numCols > 0) ? 10 * numRows : 0;
// Generate a matrix that has 0 entries in some rows
crsMat_t input_mat = KokkosSparse::Impl::kk_generate_sparse_matrix<crsMat_t>(
numRows, numCols, nnz, 3 * 10, numRows / 2);
Expand Down Expand Up @@ -250,7 +250,7 @@ void testTransposeBsr(int numRows, int numCols, int blockSize) {
using values_t = typename bsrMat_t::values_type::non_const_type;

// Generate a matrix that has 0 entries in some rows
size_type nnz = 10 * numRows;
size_type nnz = (numRows * numCols > 0) ? 10 * numRows : 0;
bsrMat_t A = KokkosSparse::Impl::kk_generate_sparse_matrix<bsrMat_t>(
blockSize, numRows, numCols, nnz, 3, numRows / 4);

Expand Down Expand Up @@ -294,6 +294,9 @@ void testTransposeBsr(int numRows, int numCols, int blockSize) {

TEST_F(TestCategory, sparse_transpose_matrix) {
// Test both matrix and graph transpose with various sizes
testTranspose<TestDevice>(0, 0, true);
testTranspose<TestDevice>(100, 0, true);
testTranspose<TestDevice>(0, 100, true);
testTranspose<TestDevice>(100, 100, true);
testTranspose<TestDevice>(500, 50, true);
testTranspose<TestDevice>(50, 500, true);
Expand All @@ -303,6 +306,9 @@ TEST_F(TestCategory, sparse_transpose_matrix) {
}

TEST_F(TestCategory, sparse_transpose_graph) {
testTranspose<TestDevice>(0, 0, false);
testTranspose<TestDevice>(100, 0, false);
testTranspose<TestDevice>(0, 100, false);
testTranspose<TestDevice>(100, 100, false);
testTranspose<TestDevice>(500, 50, false);
testTranspose<TestDevice>(50, 500, false);
Expand All @@ -314,6 +320,9 @@ TEST_F(TestCategory, sparse_transpose_graph) {
TEST_F(TestCategory, sparse_transpose_bsr_matrix) {
testTransposeBsrRef<TestDevice>();
// Test bsrMatrix transpose with various sizes
testTransposeBsr<TestDevice>(0, 0, 5);
testTransposeBsr<TestDevice>(100, 0, 5);
testTransposeBsr<TestDevice>(0, 100, 5);
testTransposeBsr<TestDevice>(100, 100, 3);
testTransposeBsr<TestDevice>(500, 50, 5);
testTransposeBsr<TestDevice>(50, 500, 16);
Expand Down

0 comments on commit 1696b1c

Please sign in to comment.