Skip to content

Commit

Permalink
make permuting_reuse_info default-constructible
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Feb 18, 2025
1 parent a524589 commit cccf80d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions core/matrix/csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ transform_reusable(const Csr<ValueType, IndexType>* input, gko::dim<2> out_size,
}


template <typename ValueType, typename IndexType>
Csr<ValueType, IndexType>::permuting_reuse_info::permuting_reuse_info()
: permuting_reuse_info{nullptr}
{}


template <typename ValueType, typename IndexType>
Csr<ValueType, IndexType>::permuting_reuse_info::permuting_reuse_info(
std::unique_ptr<Permutation<index_type>> value_permutation)
Expand All @@ -681,6 +687,9 @@ template <typename ValueType, typename IndexType>
void Csr<ValueType, IndexType>::permuting_reuse_info::update_values(
ptr_param<const Csr> input, ptr_param<Csr> output) const
{
if (!value_permutation) {
GKO_NOT_SUPPORTED(value_permutation);
}
input->create_const_value_view()->permute(
value_permutation, output->create_value_view(), permute_mode::rows);
}
Expand Down
12 changes: 11 additions & 1 deletion core/test/matrix/csr.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand All @@ -8,6 +8,7 @@
#include <ginkgo/core/matrix/csr.hpp>

#include "core/test/utils.hpp"
#include "ginkgo/core/base/exception.hpp"


namespace {
Expand Down Expand Up @@ -419,4 +420,13 @@ TYPED_TEST(Csr, GeneratesCorrectMatrixData)
}


TYPED_TEST(Csr, PermutingReuseInfoDefaultUpdateException)
{
using Mtx = typename TestFixture::Mtx;
typename Mtx::permuting_reuse_info reuse;

ASSERT_THROW(reuse.update_values(this->mtx, this->mtx), gko::NotSupported);
}


} // namespace
7 changes: 4 additions & 3 deletions include/ginkgo/core/matrix/csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
* values of the matrix into the transformed matrix.
*/
struct permuting_reuse_info {
/** Creates an empty reuse info. */
explicit permuting_reuse_info();

/** Creates a reuse info structure from its value permutation. */
permuting_reuse_info(
std::unique_ptr<Permutation<index_type>> value_permutation);
Expand Down Expand Up @@ -805,9 +808,7 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
* If permute_mode::rows is set, the rows will be permuted.
* If permute_mode::columns is set, the columns will be
* permuted.
* @return an std::pair consisting of the transposed matrix and the reuse
* info struct that can be used to update values in the transposed
* matrix.
* @return The permuted matrix.
*/
std::unique_ptr<Csr> permute(
ptr_param<const Permutation<index_type>> permutation,
Expand Down

0 comments on commit cccf80d

Please sign in to comment.