33#ifndef GKO_PUBLIC_CORE_REORDER_SCALED_REORDERED_HPP_
34#define GKO_PUBLIC_CORE_REORDER_SCALED_REORDERED_HPP_
37#include <ginkgo/core/base/abstract_factory.hpp>
38#include <ginkgo/core/base/executor.hpp>
39#include <ginkgo/core/base/lin_op.hpp>
40#include <ginkgo/core/base/types.hpp>
41#include <ginkgo/core/matrix/dense.hpp>
42#include <ginkgo/core/matrix/diagonal.hpp>
43#include <ginkgo/core/matrix/identity.hpp>
44#include <ginkgo/core/matrix/permutation.hpp>
45#include <ginkgo/core/reorder/reordering_base.hpp>
49namespace experimental {
71template <
typename ValueType = default_precision,
typename IndexType =
int32>
73 :
public EnableLinOp<ScaledReordered<ValueType, IndexType>> {
78 using value_type = ValueType;
79 using index_type = IndexType;
84 std::shared_ptr<const LinOp> get_system_matrix()
const
86 return system_matrix_;
89 std::shared_ptr<const LinOp> get_inner_operator()
const
91 return inner_operator_;
101 inner_operator,
nullptr);
108 std::shared_ptr<const ReorderingBaseFactory>
114 std::shared_ptr<const matrix::Diagonal<value_type>>
120 std::shared_ptr<const matrix::Diagonal<value_type>>
132 permutation_array_{exec}
136 std::shared_ptr<const LinOp> system_matrix)
138 system_matrix->get_size()),
139 parameters_{factory->get_parameters()},
143 GKO_ASSERT_IS_SQUARE_MATRIX(system_matrix);
147 system_matrix_ =
gko::clone(exec, system_matrix);
151 GKO_ASSERT_EQUAL_DIMENSIONS(parameters_.
row_scaling,
154 row_scaling_->apply(system_matrix_, system_matrix_);
157 GKO_ASSERT_EQUAL_DIMENSIONS(parameters_.
col_scaling,
160 col_scaling_->rapply(system_matrix_, system_matrix_);
166 auto reordering = parameters_.
reordering->generate(system_matrix_);
167 permutation_array_ = reordering->get_permutation_array();
169 ->permute(&permutation_array_);
179 exec, this->get_size());
183 void apply_impl(
const LinOp* b, LinOp* x)
const override;
185 void apply_impl(
const LinOp* alpha,
const LinOp* b,
const LinOp* beta,
186 LinOp* x)
const override;
199 void set_cache_to(
const LinOp* b,
const LinOp* x)
const
201 if (cache_.inner_b ==
nullptr ||
202 cache_.inner_b->get_size() != b->get_size()) {
203 const auto size = b->get_size();
205 matrix::Dense<value_type>::create(this->
get_executor(), size);
207 matrix::Dense<value_type>::create(this->
get_executor(), size);
208 cache_.intermediate =
209 matrix::Dense<value_type>::create(this->
get_executor(), size);
211 cache_.inner_b->copy_from(b);
212 if (inner_operator_->apply_uses_initial_guess()) {
213 cache_.inner_x->copy_from(x);
218 std::shared_ptr<LinOp> system_matrix_{};
219 std::shared_ptr<const LinOp> inner_operator_{};
220 std::shared_ptr<const matrix::Diagonal<value_type>> row_scaling_{};
221 std::shared_ptr<const matrix::Diagonal<value_type>> col_scaling_{};
222 array<index_type> permutation_array_{};
234 mutable struct cache_struct {
235 cache_struct() =
default;
237 ~cache_struct() =
default;
239 cache_struct(
const cache_struct&) {}
241 cache_struct(cache_struct&&) {}
243 cache_struct& operator=(
const cache_struct&) {
return *
this; }
245 cache_struct& operator=(cache_struct&&) {
return *
this; }
247 std::unique_ptr<matrix::Dense<value_type>> inner_b{};
248 std::unique_ptr<matrix::Dense<value_type>> inner_x{};
249 std::unique_ptr<matrix::Dense<value_type>> intermediate{};
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition abstract_factory.hpp:75
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:908
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:691
Definition lin_op.hpp:146
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition polymorphic_object.hpp:263
Definition scaled_reordered.hpp:123
Provides an interface to wrap reorderings like Rcm and diagonal scaling like equilibration around a L...
Definition scaled_reordered.hpp:73
This class is a utility which efficiently implements the identity matrix (a linear operator which map...
Definition identity.hpp:65
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
This Macro will generate a new type containing the parameters for the factory _factory_name.
Definition abstract_factory.hpp:308
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition abstract_factory.hpp:473
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Defines a build method for the factory, simplifying its construction by removing the repetitive typin...
Definition abstract_factory.hpp:422
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
This macro will generate a default implementation of a LinOpFactory for the LinOp subclass it is defi...
Definition lin_op.hpp:1046
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
detail::cloned_type< Pointer > clone(const Pointer &p)
Creates a unique clone of the object pointed to by p.
Definition utils_helper.hpp:203
std::shared_ptr< const ReorderingBaseFactory > reordering
The reordering that is to be applied to the system matrix.
Definition scaled_reordered.hpp:109
std::shared_ptr< const LinOpFactory > inner_operator
The inner operator factory that is to be generated on the scaled and reordered system matrix.
Definition scaled_reordered.hpp:101
std::shared_ptr< const matrix::Diagonal< value_type > > row_scaling
The row scaling that is to be applied to the system matrix.
Definition scaled_reordered.hpp:115
std::shared_ptr< const matrix::Diagonal< value_type > > col_scaling
The column scaling that is to be applied to the system matrix.
Definition scaled_reordered.hpp:121
This struct is used to pass parameters to the EnableDefaultReorderingBaseFactory::generate() method.
Definition reordering_base.hpp:94