Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill device_matrix_data #1683

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/base/device_matrix_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ device_matrix_data<ValueType, IndexType>::create_from_host(
}


template <typename ValueType, typename IndexType>
void device_matrix_data<ValueType, IndexType>::fill_zero()
{
row_idxs_.fill(0);
col_idxs_.fill(0);
values_.fill(ValueType{0});
}


template <typename ValueType, typename IndexType>
void device_matrix_data<ValueType, IndexType>::sort_row_major()
{
Expand Down
5 changes: 5 additions & 0 deletions include/ginkgo/core/base/device_matrix_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class device_matrix_data {
static device_matrix_data create_from_host(
std::shared_ptr<const Executor> exec, const host_type& data);

/**
* Fills the matrix entries with zeros
*/
void fill_zero();

/**
* Sorts the matrix entries in row-major order
* This means that they will be sorted by row index first, and then by
Expand Down
22 changes: 22 additions & 0 deletions test/base/device_matrix_data_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@ TYPED_TEST(DeviceMatrixData, CopiesToHost)
}


TYPED_TEST(DeviceMatrixData, CanFillEntriesWithZeros)
{
using value_type = typename TestFixture::value_type;
using index_type = typename TestFixture::index_type;
using device_matrix_data = gko::device_matrix_data<value_type, index_type>;
auto device_data = device_matrix_data{this->exec, gko::dim<2>{4, 3}, 10};

device_data.fill_zero();

auto arrays = device_data.empty_out();
auto expected_row_idxs = gko::array<index_type>(this->exec, 10);
auto expected_col_idxs = gko::array<index_type>(this->exec, 10);
auto expected_values = gko::array<value_type>(this->exec, 10);
expected_row_idxs.fill(0);
expected_col_idxs.fill(0);
expected_values.fill(0.0);
GKO_ASSERT_ARRAY_EQ(arrays.row_idxs, expected_row_idxs);
GKO_ASSERT_ARRAY_EQ(arrays.col_idxs, expected_col_idxs);
GKO_ASSERT_ARRAY_EQ(arrays.values, expected_values);
}


TYPED_TEST(DeviceMatrixData, SortsRowMajor)
{
using value_type = typename TestFixture::value_type;
Expand Down
Loading