Skip to content

Commit

Permalink
deprecate initializer_list constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Feb 19, 2024
1 parent 3e3692b commit 2763be8
Show file tree
Hide file tree
Showing 21 changed files with 244 additions and 157 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 @@ -53,18 +53,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
3 changes: 3 additions & 0 deletions include/ginkgo/core/base/batch_multi_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ class MultiVector
* Executor>, const batch_dim<2>&, array<value_type>)
*/
template <typename InputValueType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing an "
"initializer list")
static std::unique_ptr<MultiVector> create(
std::shared_ptr<const Executor> exec, const batch_dim<2>& size,
std::initializer_list<InputValueType> values)
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/base/device_matrix_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class device_matrix_data {
*/
template <typename InputValueType, typename RowIndexType,
typename ColIndexType>
GKO_DEPRECATED(
"explicitly construct the gko::array arguments instead of passing "
"initializer lists")
device_matrix_data(std::shared_ptr<const Executor> exec, dim<2> size,
std::initializer_list<RowIndexType> row_idxs,
std::initializer_list<ColIndexType> col_idxs,
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/batch_csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ class Csr final
*/
template <typename InputValueType, typename ColIndexType,
typename RowPtrType>
GKO_DEPRECATED(
"explicitly construct the gko::array arguments instead of passing "
"initializer lists")
static std::unique_ptr<Csr> create(
std::shared_ptr<const Executor> exec, const batch_dim<2>& size,
std::initializer_list<InputValueType> values,
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/batch_dense.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ class Dense final : public EnableBatchLinOp<Dense<ValueType>>,
* const batch_dim<2>&, array<value_type>)
*/
template <typename InputValueType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing an"
"initializer list")
static std::unique_ptr<Dense> create(
std::shared_ptr<const Executor> exec, const batch_dim<2>& size,
std::initializer_list<InputValueType> values)
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/batch_ell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ class Ell final
* array<index_type>)
*/
template <typename InputValueType, typename ColIndexType>
GKO_DEPRECATED(
"explicitly construct the gko::array arguments instead of passing "
"initializer lists")
static std::unique_ptr<Ell> create(
std::shared_ptr<const Executor> exec, const batch_dim<2>& size,
const IndexType num_elems_per_row,
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/coo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ class Coo : public EnableLinOp<Coo<ValueType, IndexType>>,
*/
template <typename InputValueType, typename InputColumnIndexType,
typename InputRowIndexType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing "
"initializer lists")
static std::unique_ptr<Coo> create(
std::shared_ptr<const Executor> exec, const dim<2>& size,
std::initializer_list<InputValueType> values,
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,9 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
*/
template <typename InputValueType, typename InputColumnIndexType,
typename InputRowPtrType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing "
"initializer lists")
static std::unique_ptr<Csr> create(
std::shared_ptr<const Executor> exec, const dim<2>& size,
std::initializer_list<InputValueType> values,
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/dense.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,9 @@ class Dense
* const dim<2>&, array<value_type>, size_type)
*/
template <typename InputValueType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing an"
"initializer list")
static std::unique_ptr<Dense> create(
std::shared_ptr<const Executor> exec, const dim<2>& size,
std::initializer_list<InputValueType> values, size_type stride)
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/diagonal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ class Diagonal
* Executor>, const size_type, array<value_type>)
*/
template <typename InputValueType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing an"
"initializer list")
static std::unique_ptr<Diagonal> create(
std::shared_ptr<const Executor> exec, const size_type size,
std::initializer_list<InputValueType> values)
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/ell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ class Ell : public EnableLinOp<Ell<ValueType, IndexType>>,
* size_type)
*/
template <typename InputValueType, typename InputColumnIndexType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing "
"initializer lists")
static std::unique_ptr<Ell> create(
std::shared_ptr<const Executor> exec, const dim<2>& size,
std::initializer_list<InputValueType> values,
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/fbcsr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ class Fbcsr : public EnableLinOp<Fbcsr<ValueType, IndexType>>,
*/
template <typename InputValueType, typename InputColumnIndexType,
typename InputRowPtrType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing "
"initializer lists")
static std::unique_ptr<Fbcsr> create(
std::shared_ptr<const Executor> exec, const dim<2>& size,
int block_size, std::initializer_list<InputValueType> values,
Expand Down
3 changes: 3 additions & 0 deletions include/ginkgo/core/matrix/sparsity_csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ class SparsityCsr : public EnableLinOp<SparsityCsr<ValueType, IndexType>>,
* value_type)
*/
template <typename ColIndexType, typename RowPtrType>
GKO_DEPRECATED(
"explicitly construct the gko::array argument instead of passing "
"initializer lists")
static std::unique_ptr<SparsityCsr> create(
std::shared_ptr<const Executor> exec, const dim<2>& size,
std::initializer_list<ColIndexType> col_idxs,
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 @@ -38,13 +38,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},
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},
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
19 changes: 12 additions & 7 deletions reference/test/distributed/matrix_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ 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) {
Expand Down Expand Up @@ -139,19 +141,22 @@ 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>{ref, {0, 0, 2, 3, 3, 4, 4, 5, 5, 6}},
gko::array<global_index_type>{ref, {0, 3, 2, 0, 3, 4, 6, 4, 5, 5}},
gko::array<value_type>{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>{ref,
{0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6}},
gko::array<global_index_type>{ref,
{0, 3, 1, 2, 2, 0, 3, 4, 6, 4, 5, 5}},
gko::array<value_type>{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 @@ -48,7 +48,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
53 changes: 28 additions & 25 deletions reference/test/factorization/par_ilu_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ TYPED_TEST(ParIlu, KernelAddDiagonalElementsEmpty)
using Csr = typename TestFixture::Csr;
auto expected_mtx =
Csr::create(this->ref, this->empty_csr->get_size(),
std::initializer_list<value_type>{0., 0., 0.},
std::initializer_list<index_type>{0, 1, 2},
std::initializer_list<index_type>{0, 1, 2, 3});
gko::array<value_type>{this->ref, {0., 0., 0.}},
gko::array<index_type>{this->ref, {0, 1, 2}},
gko::array<index_type>{this->ref, {0, 1, 2, 3}});
auto empty_mtx = this->empty_csr->clone();

gko::kernels::reference::factorization::add_diagonal_elements(
Expand All @@ -209,15 +209,16 @@ TYPED_TEST(ParIlu, KernelAddDiagonalElementsEmpty)

TYPED_TEST(ParIlu, KernelAddDiagonalElementsNonSquare)
{
using index_type = typename TestFixture::index_type;
using value_type = typename TestFixture::value_type;
using Csr = typename TestFixture::Csr;
auto matrix = gko::initialize<Csr>(
{{0., 0., 0.}, {1., 0., 0.}, {1., 1., 1.}, {1., 1., 1.}}, this->ref);
auto exp_values = {0., 1., 0., 1., 1., 1., 1., 1., 1.};
auto exp_col_idxs = {0, 0, 1, 0, 1, 2, 0, 1, 2};
auto exp_row_ptrs = {0, 1, 3, 6, 9};
auto expected_mtx =
Csr::create(this->ref, matrix->get_size(), std::move(exp_values),
std::move(exp_col_idxs), std::move(exp_row_ptrs));
auto expected_mtx = Csr::create(
this->ref, matrix->get_size(),
gko::array<value_type>{this->ref, {0., 1., 0., 1., 1., 1., 1., 1., 1.}},
gko::array<index_type>{this->ref, {0, 0, 1, 0, 1, 2, 0, 1, 2}},
gko::array<index_type>{this->ref, {0, 1, 3, 6, 9}});

gko::kernels::reference::factorization::add_diagonal_elements(
this->ref, matrix.get(), true);
Expand All @@ -229,14 +230,15 @@ TYPED_TEST(ParIlu, KernelAddDiagonalElementsNonSquare)

TYPED_TEST(ParIlu, KernelAddDiagonalElementsNonSquare2)
{
using index_type = typename TestFixture::index_type;
using value_type = typename TestFixture::value_type;
using Csr = typename TestFixture::Csr;
auto matrix = gko::initialize<Csr>({{1., 0., 0.}, {1., 0., 0.}}, this->ref);
auto exp_values = {1., 1., 0.};
auto exp_col_idxs = {0, 0, 1};
auto exp_row_ptrs = {0, 1, 3};
auto expected_mtx =
Csr::create(this->ref, matrix->get_size(), std::move(exp_values),
std::move(exp_col_idxs), std::move(exp_row_ptrs));
Csr::create(this->ref, matrix->get_size(),
gko::array<value_type>{this->ref, {1., 1., 0.}},
gko::array<index_type>{this->ref, {0, 0, 1}},
gko::array<index_type>{this->ref, {0, 1, 3}});

gko::kernels::reference::factorization::add_diagonal_elements(
this->ref, matrix.get(), true);
Expand All @@ -248,24 +250,25 @@ TYPED_TEST(ParIlu, KernelAddDiagonalElementsNonSquare2)

TYPED_TEST(ParIlu, KernelAddDiagonalElementsUnsorted)
{
using index_type = typename TestFixture::index_type;
using value_type = typename TestFixture::value_type;
using Csr = typename TestFixture::Csr;
auto size = gko::dim<2>{3, 3};
/* matrix:
1 2 3
1 0 3
1 2 0
*/
auto mtx_values = {3., 2., 1., 3., 1., 2., 1.};
auto mtx_col_idxs = {2, 1, 0, 2, 0, 1, 0};
auto mtx_row_ptrs = {0, 3, 5, 7};
auto matrix = Csr::create(this->ref, size, std::move(mtx_values),
std::move(mtx_col_idxs), std::move(mtx_row_ptrs));
auto exp_values = {1., 2., 3., 1., 0., 3., 1., 2., 0.};
auto exp_col_idxs = {0, 1, 2, 0, 1, 2, 0, 1, 2};
auto exp_row_ptrs = {0, 3, 6, 9};
auto expected_mtx =
Csr::create(this->ref, size, std::move(exp_values),
std::move(exp_col_idxs), std::move(exp_row_ptrs));
auto matrix = Csr::create(
this->ref, size,
gko::array<value_type>{this->ref, {3., 2., 1., 3., 1., 2., 1.}},
gko::array<index_type>{this->ref, {2, 1, 0, 2, 0, 1, 0}},
gko::array<index_type>{this->ref, {0, 3, 5, 7}});
auto expected_mtx = Csr::create(
this->ref, size,
gko::array<value_type>{this->ref, {1., 2., 3., 1., 0., 3., 1., 2., 0.}},
gko::array<index_type>{this->ref, {0, 1, 2, 0, 1, 2, 0, 1, 2}},
gko::array<index_type>{this->ref, {0, 3, 6, 9}});

gko::kernels::reference::factorization::add_diagonal_elements(
this->ref, matrix.get(), false);
Expand Down
6 changes: 4 additions & 2 deletions reference/test/matrix/dense_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ TYPED_TEST(Dense, AddsScaledDiag)
using Mtx = typename TestFixture::Mtx;
using T = typename TestFixture::value_type;
auto alpha = gko::initialize<Mtx>({2.0}, this->exec);
auto diag = gko::matrix::Diagonal<T>::create(this->exec, 2, I<T>{3.0, 2.0});
auto diag = gko::matrix::Diagonal<T>::create(
this->exec, 2, gko::array<T>{this->exec, {3.0, 2.0}});

this->mtx2->add_scaled(alpha, diag);

Expand All @@ -493,7 +494,8 @@ TYPED_TEST(Dense, SubtractsScaledDiag)
using Mtx = typename TestFixture::Mtx;
using T = typename TestFixture::value_type;
auto alpha = gko::initialize<Mtx>({-2.0}, this->exec);
auto diag = gko::matrix::Diagonal<T>::create(this->exec, 2, I<T>{3.0, 2.0});
auto diag = gko::matrix::Diagonal<T>::create(
this->exec, 2, gko::array<T>{this->exec, {3.0, 2.0}});

this->mtx2->sub_scaled(alpha, diag);

Expand Down
29 changes: 17 additions & 12 deletions reference/test/multigrid/fixed_coarsening_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,14 @@ TYPED_TEST(FixedCoarsening, GenerateMgLevelOnUnsortedCsrMatrix)
* 0 -3 0 5 0
* 0 -2 -2 0 5
*/
auto mtx_values = {-3, -3, 5, -3, -2, -1, 5, -3, -1, 5, -3, 5, -2, -2, 5};
auto mtx_col_idxs = {1, 2, 0, 0, 3, 4, 1, 0, 4, 2, 1, 3, 1, 2, 4};
auto mtx_row_ptrs = {0, 3, 7, 10, 12, 15};
auto matrix = gko::share(
Mtx::create(this->exec, gko::dim<2>{5, 5}, std::move(mtx_values),
std::move(mtx_col_idxs), std::move(mtx_row_ptrs)));
auto matrix = gko::share(Mtx::create(
this->exec, gko::dim<2>{5, 5},
gko::array<value_type>{
this->exec,
{-3, -3, 5, -3, -2, -1, 5, -3, -1, 5, -3, 5, -2, -2, 5}},
gko::array<index_type>{this->exec,
{1, 2, 0, 0, 3, 4, 1, 0, 4, 2, 1, 3, 1, 2, 4}},
gko::array<index_type>{this->exec, {0, 3, 7, 10, 12, 15}}));
auto prolong_op = gko::share(Mtx::create(this->exec, gko::dim<2>{5, 3}, 0));
// 0-2-3
prolong_op->read({{5, 3}, {{0, 0, 1}, {2, 1, 1}, {3, 2, 1}}});
Expand Down Expand Up @@ -357,12 +359,15 @@ TYPED_TEST(FixedCoarsening, GenerateMgLevelOnUnsortedCooMatrix)
* 0 -3 0 5 0
* 0 -2 -2 0 5
*/
auto mtx_values = {-3, -3, 5, -3, -2, -1, 5, -3, -1, 5, -3, 5, -2, -2, 5};
auto mtx_col_idxs = {1, 2, 0, 0, 3, 4, 1, 0, 4, 2, 1, 3, 1, 2, 4};
auto mtx_row_idxs = {0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4};
auto matrix = gko::share(
CooMtx::create(this->exec, gko::dim<2>{5, 5}, std::move(mtx_values),
std::move(mtx_col_idxs), std::move(mtx_row_idxs)));
auto matrix = gko::share(CooMtx::create(
this->exec, gko::dim<2>{5, 5},
gko::array<value_type>{
this->exec,
{-3, -3, 5, -3, -2, -1, 5, -3, -1, 5, -3, 5, -2, -2, 5}},
gko::array<index_type>{this->exec,
{1, 2, 0, 0, 3, 4, 1, 0, 4, 2, 1, 3, 1, 2, 4}},
gko::array<index_type>{this->exec,
{0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4}}));
auto prolong_op = gko::share(Mtx::create(this->exec, gko::dim<2>{5, 3}, 0));
// 0-2-3
prolong_op->read({{5, 3}, {{0, 0, 1}, {2, 1, 1}, {3, 2, 1}}});
Expand Down
Loading

0 comments on commit 2763be8

Please sign in to comment.