5 #ifndef GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_
6 #define GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_
11 #include <ginkgo/core/base/lin_op.hpp>
12 #include <ginkgo/core/matrix/dense.hpp>
37 template <
typename ValueType = default_precision>
43 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
46 using value_type = ValueType;
53 const std::shared_ptr<const LinOp>
get_basis() const noexcept
73 const std::shared_ptr<const LinOp>
get_scalar() const noexcept
93 static std::unique_ptr<Perturbation>
create(
94 std::shared_ptr<const Executor> exec);
106 static std::unique_ptr<Perturbation>
create(
107 std::shared_ptr<const LinOp> scalar,
108 std::shared_ptr<const LinOp> basis);
119 static std::unique_ptr<Perturbation>
create(
120 std::shared_ptr<const LinOp> scalar, std::shared_ptr<const LinOp> basis,
121 std::shared_ptr<const LinOp> projector);
124 explicit Perturbation(std::shared_ptr<const Executor> exec);
126 explicit Perturbation(std::shared_ptr<const LinOp> scalar,
127 std::shared_ptr<const LinOp> basis);
129 explicit Perturbation(std::shared_ptr<const LinOp> scalar,
130 std::shared_ptr<const LinOp> basis,
131 std::shared_ptr<const LinOp> projector);
133 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
136 LinOp* x)
const override;
143 void validate_perturbation();
146 std::shared_ptr<const LinOp> basis_;
147 std::shared_ptr<const LinOp> projector_;
148 std::shared_ptr<const LinOp> scalar_;
151 mutable struct cache_struct {
152 cache_struct() =
default;
153 ~cache_struct() =
default;
154 cache_struct(
const cache_struct& other) {}
155 cache_struct& operator=(
const cache_struct& other) {
return *
this; }
160 void allocate(std::shared_ptr<const Executor> exec, dim<2> size)
163 if (
one ==
nullptr) {
164 one = initialize<vec>({gko::one<ValueType>()}, exec);
166 if (alpha_scalar ==
nullptr) {
169 if (intermediate ==
nullptr || intermediate->get_size() != size) {
170 intermediate = vec::create(exec, size);
174 std::unique_ptr<LinOp> intermediate;
175 std::unique_ptr<LinOp>
one;
176 std::unique_ptr<LinOp> alpha_scalar;
184 #endif // GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_