Skip to content

Commit

Permalink
fixup! add csr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelKoch committed Dec 4, 2023
1 parent 3e539bd commit 8a3d846
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions core/test/matrix/coo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ TYPED_TEST(Coo, CanBeReadFromMatrixData)
}


TYPED_TEST(Coo, CanBeReadFromMatrixDataIntoViews)
{
using Mtx = typename TestFixture::Mtx;
using value_type = typename TestFixture::value_type;
using index_type = typename TestFixture::index_type;
auto row_idxs = gko::array<index_type>(this->exec, 4);
auto col_idxs = gko::array<index_type>(this->exec, 4);
auto values = gko::array<value_type>(this->exec, 4);
auto m = Mtx::create(this->exec, gko::dim<2>{2, 3}, values.as_view(),
col_idxs.as_view(), row_idxs.as_view());

m->read({{2, 3}, {{0, 0, 1.0}, {0, 1, 3.0}, {0, 2, 2.0}, {1, 1, 5.0}}});

this->assert_equal_to_original_mtx(m);
ASSERT_EQ(row_idxs.get_data(), m->get_row_idxs());
ASSERT_EQ(col_idxs.get_data(), m->get_col_idxs());
ASSERT_EQ(values.get_data(), m->get_values());
}


TYPED_TEST(Coo, CanBeReadFromMatrixAssemblyData)
{
using Mtx = typename TestFixture::Mtx;
Expand Down
21 changes: 21 additions & 0 deletions core/test/matrix/csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,27 @@ TYPED_TEST(Csr, CanBeReadFromMatrixData)
}


TYPED_TEST(Csr, CanBeReadFromMatrixDataIntoViews)
{
using Mtx = typename TestFixture::Mtx;
using value_type = typename TestFixture::value_type;
using index_type = typename TestFixture::index_type;
auto row_ptrs = gko::array<index_type>(this->exec, 3);
auto col_idxs = gko::array<index_type>(this->exec, 4);
auto values = gko::array<value_type>(this->exec, 4);
auto m = Mtx::create(this->exec, gko::dim<2>{2, 3}, values.as_view(),
col_idxs.as_view(), row_ptrs.as_view(),
std::make_shared<typename Mtx::load_balance>(2));

m->read({{2, 3}, {{0, 0, 1.0}, {0, 1, 3.0}, {0, 2, 2.0}, {1, 1, 5.0}}});

this->assert_equal_to_original_mtx(m);
ASSERT_EQ(row_ptrs.get_data(), m->get_row_ptrs());
ASSERT_EQ(col_idxs.get_data(), m->get_col_idxs());
ASSERT_EQ(values.get_data(), m->get_values());
}


TYPED_TEST(Csr, CanBeReadFromMatrixAssemblyData)
{
using Mtx = typename TestFixture::Mtx;
Expand Down

0 comments on commit 8a3d846

Please sign in to comment.