Skip to content

Commit

Permalink
remove templated matrix constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Oct 15, 2023
1 parent 2f3720f commit afd3e06
Show file tree
Hide file tree
Showing 21 changed files with 256 additions and 203 deletions.
18 changes: 10 additions & 8 deletions core/test/utils/unsort_matrix_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,20 @@ class UnsortMatrix : public ::testing::Test {
*/
std::unique_ptr<Csr> get_sorted_csr()
{
return Csr::create(exec, gko::dim<2>{5, 5},
I<value_type>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
I<index_type>{0, 1, 0, 1, 2, 3, 2, 2, 3, 4},
I<index_type>{0, 2, 2, 6, 7, 10});
return Csr::create(
exec, gko::dim<2>{5, 5},
gko::array<value_type>{exec, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
gko::array<index_type>{exec, {0, 1, 0, 1, 2, 3, 2, 2, 3, 4}},
gko::array<index_type>{exec, {0, 2, 2, 6, 7, 10}});
}

std::unique_ptr<Coo> get_sorted_coo()
{
return Coo::create(exec, gko::dim<2>{5, 5},
I<value_type>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
I<index_type>{0, 1, 0, 1, 2, 3, 2, 2, 3, 4},
I<index_type>{0, 0, 2, 2, 2, 2, 3, 4, 4, 4});
return Coo::create(
exec, gko::dim<2>{5, 5},
gko::array<value_type>{exec, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
gko::array<index_type>{exec, {0, 1, 0, 1, 2, 3, 2, 2, 3, 4}},
gko::array<index_type>{exec, {0, 0, 2, 2, 2, 2, 3, 4, 4, 4}});
}

bool is_coo_matrix_sorted(gko::ptr_param<Coo> mtx)
Expand Down
5 changes: 2 additions & 3 deletions include/ginkgo/core/base/batch_multi_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,11 @@ class MultiVector
* the wrong executor, an internal copy will be created, and the
* original array data will not be used in the vector.
*/
template <typename ValuesArray>
MultiVector(std::shared_ptr<const Executor> exec, const batch_dim<2>& size,
ValuesArray&& values)
array<value_type> values)
: EnablePolymorphicObject<MultiVector<ValueType>>(exec),
batch_size_(size),
values_{exec, std::forward<ValuesArray>(values)}
values_{exec, std::move(values)}
{
// Ensure that the values array has the correct size
auto num_elems = compute_num_elems(size);
Expand Down
12 changes: 5 additions & 7 deletions include/ginkgo/core/base/device_matrix_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ class device_matrix_data {
* @param col_idxs the array containing the matrix column indices
* @param row_idxs the array containing the matrix row indices
*/
template <typename ValueArray, typename RowIndexArray,
typename ColIndexArray>
device_matrix_data(std::shared_ptr<const Executor> exec, dim<2> size,
RowIndexArray&& row_idxs, ColIndexArray&& col_idxs,
ValueArray&& values)
array<index_type> row_idxs, array<index_type> col_idxs,
array<value_type> values)
: size_{size},
row_idxs_{exec, std::forward<RowIndexArray>(row_idxs)},
col_idxs_{exec, std::forward<ColIndexArray>(col_idxs)},
values_{exec, std::forward<ValueArray>(values)}
row_idxs_{exec, std::move(row_idxs)},
col_idxs_{exec, std::move(col_idxs)},
values_{exec, std::move(values)}
{
GKO_ASSERT_EQ(values_.get_num_elems(), row_idxs_.get_num_elems());
GKO_ASSERT_EQ(values_.get_num_elems(), col_idxs_.get_num_elems());
Expand Down
6 changes: 2 additions & 4 deletions include/ginkgo/core/matrix/batch_dense.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,9 @@ class Dense final : public EnableBatchLinOp<Dense<ValueType>>,
* the wrong executor, an internal copy will be created, and the
* original array data will not be used in the matrix.
*/
template <typename ValuesArray>
Dense(std::shared_ptr<const Executor> exec, const batch_dim<2>& size,
ValuesArray&& values)
: EnableBatchLinOp<Dense>(exec, size),
values_{exec, std::forward<ValuesArray>(values)}
array<value_type> values)
: EnableBatchLinOp<Dense>(exec, size), values_{exec, std::move(values)}
{
// Ensure that the values array has the correct size
auto num_elems = compute_num_elems(size);
Expand Down
11 changes: 5 additions & 6 deletions include/ginkgo/core/matrix/coo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,13 @@ class Coo : public EnableLinOp<Coo<ValueType, IndexType>>,
* created, and the original array data will not be used in the
* matrix.
*/
template <typename ValuesArray, typename ColIdxsArray,
typename RowIdxsArray>
Coo(std::shared_ptr<const Executor> exec, const dim<2>& size,
ValuesArray&& values, ColIdxsArray&& col_idxs, RowIdxsArray&& row_idxs)
array<value_type> values, array<index_type> col_idxs,
array<index_type> row_idxs)
: EnableLinOp<Coo>(exec, size),
values_{exec, std::forward<ValuesArray>(values)},
col_idxs_{exec, std::forward<ColIdxsArray>(col_idxs)},
row_idxs_{exec, std::forward<RowIdxsArray>(row_idxs)}
values_{exec, std::move(values)},
col_idxs_{exec, std::move(col_idxs)},
row_idxs_{exec, std::move(row_idxs)}
{
GKO_ASSERT_EQ(values_.get_num_elems(), col_idxs_.get_num_elems());
GKO_ASSERT_EQ(values_.get_num_elems(), row_idxs_.get_num_elems());
Expand Down
23 changes: 10 additions & 13 deletions include/ginkgo/core/matrix/csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,15 +1106,13 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
* created, and the original array data will not be used in the
* matrix.
*/
template <typename ValuesArray, typename ColIdxsArray,
typename RowPtrsArray>
Csr(std::shared_ptr<const Executor> exec, const dim<2>& size,
ValuesArray&& values, ColIdxsArray&& col_idxs, RowPtrsArray&& row_ptrs,
std::shared_ptr<strategy_type> strategy)
array<value_type> values, array<index_type> col_idxs,
array<index_type> row_ptrs, std::shared_ptr<strategy_type> strategy)
: EnableLinOp<Csr>(exec, size),
values_{exec, std::forward<ValuesArray>(values)},
col_idxs_{exec, std::forward<ColIdxsArray>(col_idxs)},
row_ptrs_{exec, std::forward<RowPtrsArray>(row_ptrs)},
values_{exec, std::move(values)},
col_idxs_{exec, std::move(col_idxs)},
row_ptrs_{exec, std::move(row_ptrs)},
srow_(exec),
strategy_(strategy->copy())
{
Expand All @@ -1130,15 +1128,14 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
* @note This is the same as the previous constructor but with a default
* strategy.
*/
template <typename ValuesArray, typename ColIdxsArray,
typename RowPtrsArray>
Csr(std::shared_ptr<const Executor> exec, const dim<2>& size,
ValuesArray&& values, ColIdxsArray&& col_idxs, RowPtrsArray&& row_ptrs)
array<value_type> values, array<index_type> col_idxs,
array<index_type> row_ptrs)
: Csr{exec,
size,
std::forward<ValuesArray>(values),
std::forward<ColIdxsArray>(col_idxs),
std::forward<RowPtrsArray>(row_ptrs),
std::move(values),
std::move(col_idxs),
std::move(row_ptrs),
Csr::make_default_strategy(exec)}
{}

Expand Down
5 changes: 2 additions & 3 deletions include/ginkgo/core/matrix/dense.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,11 +1051,10 @@ class Dense
* the wrong executor, an internal copy will be created, and the
* original array data will not be used in the matrix.
*/
template <typename ValuesArray>
Dense(std::shared_ptr<const Executor> exec, const dim<2>& size,
ValuesArray&& values, size_type stride)
array<value_type> values, size_type stride)
: EnableLinOp<Dense>(exec, size),
values_{exec, std::forward<ValuesArray>(values)},
values_{exec, std::move(values)},
stride_{stride}
{
if (size[0] > 0 && size[1] > 0) {
Expand Down
5 changes: 2 additions & 3 deletions include/ginkgo/core/matrix/diagonal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,10 @@ class Diagonal
* the wrong executor, an internal copy will be created, and the
* original array data will not be used in the matrix.
*/
template <typename ValuesArray>
Diagonal(std::shared_ptr<const Executor> exec, const size_type size,
ValuesArray&& values)
array<value_type> values)
: EnableLinOp<Diagonal>(exec, dim<2>(size)),
values_{exec, std::forward<ValuesArray>(values)}
values_{exec, std::move(values)}
{
GKO_ENSURE_IN_BOUNDS(size - 1, values_.get_num_elems());
}
Expand Down
7 changes: 3 additions & 4 deletions include/ginkgo/core/matrix/ell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,12 @@ class Ell : public EnableLinOp<Ell<ValueType, IndexType>>,
* an internal copy of that array will be created, and the original
* array data will not be used in the matrix.
*/
template <typename ValuesArray, typename ColIdxsArray>
Ell(std::shared_ptr<const Executor> exec, const dim<2>& size,
ValuesArray&& values, ColIdxsArray&& col_idxs,
array<value_type> values, array<index_type> col_idxs,
size_type num_stored_elements_per_row, size_type stride)
: EnableLinOp<Ell>(exec, size),
values_{exec, std::forward<ValuesArray>(values)},
col_idxs_{exec, std::forward<ColIdxsArray>(col_idxs)},
values_{exec, std::move(values)},
col_idxs_{exec, std::move(col_idxs)},
num_stored_elements_per_row_{num_stored_elements_per_row},
stride_{stride}
{
Expand Down
12 changes: 5 additions & 7 deletions include/ginkgo/core/matrix/fbcsr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,14 @@ class Fbcsr : public EnableLinOp<Fbcsr<ValueType, IndexType>>,
* created, and the original array data will not be used in the
* matrix.
*/
template <typename ValuesArray, typename ColIdxsArray,
typename RowPtrsArray>
Fbcsr(std::shared_ptr<const Executor> exec, const dim<2>& size,
int block_size, ValuesArray&& values, ColIdxsArray&& col_idxs,
RowPtrsArray&& row_ptrs)
int block_size, array<value_type> values, array<index_type> col_idxs,
array<index_type> row_ptrs)
: EnableLinOp<Fbcsr>(exec, size),
bs_{block_size},
values_{exec, std::forward<ValuesArray>(values)},
col_idxs_{exec, std::forward<ColIdxsArray>(col_idxs)},
row_ptrs_{exec, std::forward<RowPtrsArray>(row_ptrs)}
values_{exec, std::move(values)},
col_idxs_{exec, std::move(col_idxs)},
row_ptrs_{exec, std::move(row_ptrs)}
{
GKO_ASSERT_EQ(values_.get_num_elems(),
col_idxs_.get_num_elems() * bs_ * bs_);
Expand Down
5 changes: 2 additions & 3 deletions include/ginkgo/core/matrix/permutation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ class Permutation : public EnableLinOp<Permutation<IndexType>>,
* IndexType, or is on the wrong executor, an internal copy will be created,
* and the original array data will not be used in the matrix.
*/
template <typename IndicesArray>
Permutation(std::shared_ptr<const Executor> exec, const dim<2>& size,
IndicesArray&& permutation_indices,
array<index_type> permutation_indices,
const mask_type& enabled_permute = row_permute)
: EnableLinOp<Permutation>(exec, size),
permutation_{exec, std::forward<IndicesArray>(permutation_indices)},
permutation_{exec, std::move(permutation_indices)},
row_size_(size[0]),
col_size_(size[1]),
enabled_permute_(enabled_permute)
Expand Down
5 changes: 2 additions & 3 deletions include/ginkgo/core/matrix/row_gatherer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ class RowGatherer : public EnableLinOp<RowGatherer<IndexType>>,
* IndexType, or is on the wrong executor, an internal copy will be created,
* and the original array data will not be used in the matrix.
*/
template <typename IndicesArray>
RowGatherer(std::shared_ptr<const Executor> exec, const dim<2>& size,
IndicesArray&& row_idxs)
array<index_type> row_idxs)
: EnableLinOp<RowGatherer>(exec, size),
row_idxs_{exec, std::forward<IndicesArray>(row_idxs)}
row_idxs_{exec, std::move(row_idxs)}
{
GKO_ASSERT_EQ(size[0], row_idxs_.get_num_elems());
}
Expand Down
7 changes: 3 additions & 4 deletions include/ginkgo/core/matrix/sparsity_csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,12 @@ class SparsityCsr
* created, and the original array data will not be used in the
* matrix.
*/
template <typename ColIdxsArray, typename RowPtrsArray>
SparsityCsr(std::shared_ptr<const Executor> exec, const dim<2>& size,
ColIdxsArray&& col_idxs, RowPtrsArray&& row_ptrs,
array<index_type> col_idxs, array<index_type> row_ptrs,
value_type value = one<ValueType>())
: EnableLinOp<SparsityCsr>(exec, size),
col_idxs_{exec, std::forward<ColIdxsArray>(col_idxs)},
row_ptrs_{exec, std::forward<RowPtrsArray>(row_ptrs)},
col_idxs_{exec, std::move(col_idxs)},
row_ptrs_{exec, std::move(row_ptrs)},
value_{exec, {value}}
{
GKO_ASSERT_EQ(this->get_size()[0] + 1, row_ptrs_.get_num_elems());
Expand Down
17 changes: 10 additions & 7 deletions reference/test/base/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ class ConvertToWithSorting : public ::testing::Test {
ConvertToWithSorting()
: ref{gko::ReferenceExecutor::create()},
mtx{gko::initialize<Dense>({{1, 2, 3}, {6, 0, 7}, {-1, 8, 0}}, ref)},
unsorted_coo{Coo::create(ref, gko::dim<2>{3, 3},
I<value_type>{1, 3, 2, 7, 6, -1, 8},
I<index_type>{0, 2, 1, 2, 0, 0, 1},
I<index_type>{0, 0, 0, 1, 1, 2, 2})},
unsorted_csr{Csr::create(
ref, gko::dim<2>{3, 3}, I<value_type>{1, 3, 2, 7, 6, -1, 8},
I<index_type>{0, 2, 1, 2, 0, 0, 1}, I<index_type>{0, 3, 5, 7})}
unsorted_coo{
Coo::create(ref, gko::dim<2>{3, 3},

Check warning on line 70 in reference/test/base/utils.cpp

View check run for this annotation

Codecov / codecov/patch

reference/test/base/utils.cpp#L70

Added line #L70 was not covered by tests
gko::array<value_type>{ref, {1, 3, 2, 7, 6, -1, 8}},
gko::array<index_type>{ref, {0, 2, 1, 2, 0, 0, 1}},
gko::array<index_type>{ref, {0, 0, 0, 1, 1, 2, 2}})},
unsorted_csr{
Csr::create(ref, gko::dim<2>{3, 3},

Check warning on line 75 in reference/test/base/utils.cpp

View check run for this annotation

Codecov / codecov/patch

reference/test/base/utils.cpp#L75

Added line #L75 was not covered by tests
gko::array<value_type>{ref, {1, 3, 2, 7, 6, -1, 8}},
gko::array<index_type>{ref, {0, 2, 1, 2, 0, 0, 1}},
gko::array<index_type>{ref, {0, 3, 5, 7}})}

{}

Expand Down
37 changes: 25 additions & 12 deletions reference/test/distributed/matrix_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,24 @@ class Matrix : public ::testing::Test {
std::vector<gko::array<comm_index_type>> ref_recv_sizes;

auto input = gko::device_matrix_data<value_type, global_index_type>{
ref, size, input_rows, input_cols, input_vals};
ref, size, gko::array<global_index_type>{ref, input_rows},
gko::array<global_index_type>{ref, input_cols},
gko::array<value_type>{ref, input_vals}};
this->recv_sizes.resize_and_reset(
static_cast<gko::size_type>(row_partition->get_num_parts()));
for (auto entry : local_entries) {
ref_locals.emplace_back(ref, std::get<0>(entry), std::get<1>(entry),
std::get<2>(entry), std::get<3>(entry));
ref_locals.emplace_back(
ref, std::get<0>(entry),
gko::array<local_index_type>{ref, std::get<1>(entry)},
gko::array<local_index_type>{ref, std::get<2>(entry)},
gko::array<value_type>{ref, std::get<3>(entry)});
}
for (auto entry : non_local_entries) {
ref_non_locals.emplace_back(ref, std::get<0>(entry),
std::get<1>(entry), std::get<2>(entry),
std::get<3>(entry));
ref_non_locals.emplace_back(
ref, std::get<0>(entry),
gko::array<local_index_type>{ref, std::get<1>(entry)},
gko::array<local_index_type>{ref, std::get<2>(entry)},
gko::array<value_type>{ref, std::get<3>(entry)});
}
for (auto entry : gather_idx_entries) {
ref_gather_idxs.emplace_back(ref, entry);
Expand Down Expand Up @@ -167,19 +174,25 @@ class Matrix : public ::testing::Test {
{
return gko::device_matrix_data<value_type, global_index_type>{
this->ref, gko::dim<2>{7, 7},
I<global_index_type>{0, 0, 2, 3, 3, 4, 4, 5, 5, 6},
I<global_index_type>{0, 3, 2, 0, 3, 4, 6, 4, 5, 5},
I<value_type>{1, 2, 5, 6, 7, 8, 9, 10, 11, 12}};
gko::array<global_index_type>{this->ref,
{0, 0, 2, 3, 3, 4, 4, 5, 5, 6}},
gko::array<global_index_type>{this->ref,
{0, 3, 2, 0, 3, 4, 6, 4, 5, 5}},
gko::array<value_type>{this->ref,
{1, 2, 5, 6, 7, 8, 9, 10, 11, 12}}};
}

gko::device_matrix_data<value_type, global_index_type>
create_input_full_rank()
{
return gko::device_matrix_data<value_type, global_index_type>{
this->ref, gko::dim<2>{7, 7},
I<global_index_type>{0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6},
I<global_index_type>{0, 3, 1, 2, 2, 0, 3, 4, 6, 4, 5, 5},
I<value_type>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}};
gko::array<global_index_type>{this->ref,
{0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6}},
gko::array<global_index_type>{this->ref,
{0, 3, 1, 2, 2, 0, 3, 4, 6, 4, 5, 5}},
gko::array<value_type>{this->ref,
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}}};
}

std::shared_ptr<const gko::ReferenceExecutor> ref;
Expand Down
4 changes: 3 additions & 1 deletion reference/test/distributed/vector_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class Vector : public ::testing::Test {
{
std::vector<I<I<value_type>>> ref_outputs;
auto input = gko::device_matrix_data<value_type, global_index_type>{
ref, size, input_rows, input_cols, input_vals};
ref, size, gko::array<global_index_type>{ref, input_rows},
gko::array<global_index_type>{ref, input_cols},
gko::array<value_type>{ref, input_vals}};
for (auto entry : output_entries) {
ref_outputs.emplace_back(entry);
}
Expand Down
Loading

0 comments on commit afd3e06

Please sign in to comment.