Skip to content

Commit

Permalink
Fix for issue with corner case of reading empty Fbcsr matrix
Browse files Browse the repository at this point in the history
Merge pull request #730
  • Loading branch information
Slaedr committed Apr 9, 2021
2 parents edc18f8 + 1e1cc5f commit 58c9425
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/matrix/fbcsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ void Fbcsr<ValueType, IndexType>::read(const mat_data &data)
blocks.size() * bs * bs, bs);

tmp->row_ptrs_.get_data()[0] = 0;
if (data.nonzeros.size() == 0) {
tmp->move_to(this);
return;
}

index_type cur_brow = 0;
index_type cur_bnz = 0;
index_type cur_bcol = blocks.begin()->first.block_column;
Expand Down
18 changes: 18 additions & 0 deletions core/test/matrix/fbcsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,24 @@ TYPED_TEST(Fbcsr, CanBeReadFromMatrixData)
}


TYPED_TEST(Fbcsr, CanBeReadFromEmptyMatrixData)
{
using Mtx = typename TestFixture::Mtx;
using MtxData = typename TestFixture::MtxData;
auto m = Mtx::create(this->exec);
m->set_block_size(this->fbsample.bs);
MtxData mdata;
mdata.size = gko::dim<2>{0, 0};

m->read(mdata);

ASSERT_EQ(m->get_size(), (gko::dim<2>{0, 0}));
ASSERT_EQ(m->get_const_row_ptrs()[0], 0);
ASSERT_EQ(m->get_const_col_idxs(), nullptr);
ASSERT_EQ(m->get_const_values(), nullptr);
}


TYPED_TEST(Fbcsr, GeneratesCorrectMatrixData)
{
using value_type = typename TestFixture::value_type;
Expand Down

0 comments on commit 58c9425

Please sign in to comment.