5 #ifndef GKO_PUBLIC_CORE_REORDER_SCALED_REORDERED_HPP_
6 #define GKO_PUBLIC_CORE_REORDER_SCALED_REORDERED_HPP_
9 #include <ginkgo/core/base/abstract_factory.hpp>
10 #include <ginkgo/core/base/executor.hpp>
11 #include <ginkgo/core/base/lin_op.hpp>
12 #include <ginkgo/core/base/types.hpp>
13 #include <ginkgo/core/matrix/diagonal.hpp>
14 #include <ginkgo/core/matrix/identity.hpp>
15 #include <ginkgo/core/matrix/multivector.hpp>
16 #include <ginkgo/core/matrix/permutation.hpp>
17 #include <ginkgo/core/reorder/reordering_base.hpp>
21 namespace experimental {
46 template <
typename ValueType = default_precision,
typename IndexType =
int32>
48 GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
51 using value_type = ValueType;
52 using index_type = IndexType;
57 std::shared_ptr<const LinOp> get_system_matrix()
const
59 return system_matrix_;
62 std::shared_ptr<const LinOp> get_inner_operator()
const
64 return inner_operator_;
74 inner_operator,
nullptr);
81 std::shared_ptr<const ReorderingBaseFactory>
87 std::shared_ptr<const matrix::Diagonal<value_type>>
93 std::shared_ptr<const matrix::Diagonal<value_type>>
104 :
LinOp(std::move(exec)), permutation_array_{exec}
108 std::shared_ptr<const LinOp> system_matrix)
110 parameters_{factory->get_parameters()},
112 factory->get_executor())),
113 permutation_array_{factory->get_executor()}
116 GKO_ASSERT_IS_SQUARE_MATRIX(system_matrix);
120 as<ConvertibleTo<matrix::Csr<ValueType, IndexType>>>(system_matrix)
121 ->convert_to(system_matrix_);
125 GKO_ASSERT_EQUAL_DIMENSIONS(parameters_.
row_scaling,
128 row_scaling_->apply(system_matrix_, system_matrix_);
131 GKO_ASSERT_EQUAL_DIMENSIONS(parameters_.
col_scaling,
134 col_scaling_->rapply(system_matrix_, system_matrix_);
140 auto reordering = parameters_.
reordering->generate(system_matrix_);
141 permutation_array_ = reordering->get_permutation_array();
142 system_matrix_ = as<matrix::Csr<ValueType, IndexType>>(
143 system_matrix_->permute(&permutation_array_));
157 void apply_impl(
const AbstractMultiVector* b,
158 AbstractMultiVector* x)
const override;
160 void apply_impl(
const AbstractMultiVector* alpha,
161 const AbstractMultiVector* b,
162 const AbstractMultiVector* beta,
163 AbstractMultiVector* x)
const override;
176 void set_cache_to(
const AbstractMultiVector* b,
177 const AbstractMultiVector* x)
const
179 if (cache_.inner_b ==
nullptr ||
180 cache_.inner_b->get_size() != b->get_size()) {
181 const auto size = b->get_size();
189 cache_.inner_b->copy_from(
as<matrix::MultiVector<ValueType>>(b));
190 if (inner_operator_->apply_uses_initial_guess()) {
191 cache_.inner_x->copy_from(
as<matrix::MultiVector<ValueType>>(x));
196 std::shared_ptr<matrix::Csr<ValueType, IndexType>> system_matrix_{};
197 std::shared_ptr<const LinOp> inner_operator_{};
198 std::shared_ptr<const matrix::Diagonal<value_type>> row_scaling_{};
199 std::shared_ptr<const matrix::Diagonal<value_type>> col_scaling_{};
200 array<index_type> permutation_array_{};
212 mutable struct cache_struct {
213 cache_struct() =
default;
215 ~cache_struct() =
default;
217 cache_struct(
const cache_struct&) {}
219 cache_struct(cache_struct&&) noexcept {}
221 cache_struct&
operator=(
const cache_struct&) {
return *
this; }
223 cache_struct&
operator=(cache_struct&&) noexcept {
return *
this; }
225 std::unique_ptr<matrix::MultiVector<value_type>> inner_b{};
226 std::unique_ptr<matrix::MultiVector<value_type>> inner_x{};
227 std::unique_ptr<matrix::MultiVector<value_type>> intermediate{};
237 #endif // GKO_PUBLIC_CORE_REORDER_SCALED_REORDERED_HPP_