Skip to content

Commit

Permalink
Merge simplified GKO_REGISTER_OPERATION
Browse files Browse the repository at this point in the history
This PR uses lambda captures to simplify the GKO_REGISTER_OPERATION
parameter storage, dispatch and error message quality.

Related PR: #859
  • Loading branch information
upsj authored Sep 1, 2021
2 parents 147c175 + 109c48d commit 2bf7411
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 128 deletions.
85 changes: 37 additions & 48 deletions core/matrix/dense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,10 @@ void Dense<ValueType>::move_to(Dense<next_precision<ValueType>> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Coo<ValueType, int32> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_coo<const Dense<ValueType> *&,
decltype(result)>);
// const ref parameters, as make_* functions take parameters by ref
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_coo(in, out);
});
}


Expand All @@ -485,10 +485,9 @@ void Dense<ValueType>::move_to(Coo<ValueType, int32> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Coo<ValueType, int64> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_coo<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_coo(in, out);
});
}


Expand All @@ -502,10 +501,9 @@ void Dense<ValueType>::move_to(Coo<ValueType, int64> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Csr<ValueType, int32> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_csr<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_csr(in, out);
});
result->make_srow();
}

Expand All @@ -520,10 +518,9 @@ void Dense<ValueType>::move_to(Csr<ValueType, int32> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Csr<ValueType, int64> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_csr<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_csr(in, out);
});
result->make_srow();
}

Expand All @@ -538,10 +535,9 @@ void Dense<ValueType>::move_to(Csr<ValueType, int64> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Ell<ValueType, int32> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_ell<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_ell(in, out);
});
}


Expand All @@ -555,10 +551,9 @@ void Dense<ValueType>::move_to(Ell<ValueType, int32> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Ell<ValueType, int64> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_ell<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_ell(in, out);
});
}


Expand All @@ -572,10 +567,9 @@ void Dense<ValueType>::move_to(Ell<ValueType, int64> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Hybrid<ValueType, int32> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_hybrid<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_hybrid(in, out);
});
}


Expand All @@ -589,10 +583,9 @@ void Dense<ValueType>::move_to(Hybrid<ValueType, int32> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Hybrid<ValueType, int64> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_hybrid<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_hybrid(in, out);
});
}


Expand All @@ -606,10 +599,9 @@ void Dense<ValueType>::move_to(Hybrid<ValueType, int64> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Sellp<ValueType, int32> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_sellp<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_sellp(in, out);
});
}


Expand All @@ -623,10 +615,9 @@ void Dense<ValueType>::move_to(Sellp<ValueType, int32> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(Sellp<ValueType, int64> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_sellp<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_sellp(in, out);
});
}


Expand All @@ -640,10 +631,9 @@ void Dense<ValueType>::move_to(Sellp<ValueType, int64> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(SparsityCsr<ValueType, int32> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_sparsity_csr<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_sparsity_csr(in, out);
});
}


Expand All @@ -657,10 +647,9 @@ void Dense<ValueType>::move_to(SparsityCsr<ValueType, int32> *result)
template <typename ValueType>
void Dense<ValueType>::convert_to(SparsityCsr<ValueType, int64> *result) const
{
conversion_helper(
result, this,
dense::template make_convert_to_sparsity_csr<const Dense<ValueType> *&,
decltype(result)>);
conversion_helper(result, this, [](const auto &in, const auto &out) {
return dense::make_convert_to_sparsity_csr(in, out);
});
}


Expand Down
Loading

0 comments on commit 2bf7411

Please sign in to comment.