5 #ifndef GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_
6 #define GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_
12 #include <ginkgo/core/base/lin_op.hpp>
13 #include <ginkgo/core/matrix/dense.hpp>
38 template <
typename ValueType = default_precision>
45 using value_type = ValueType;
52 const std::shared_ptr<const LinOp>
get_basis() const noexcept
72 const std::shared_ptr<const LinOp>
get_scalar() const noexcept
92 static std::unique_ptr<Perturbation>
create(
93 std::shared_ptr<const Executor> exec);
105 static std::unique_ptr<Perturbation>
create(
106 std::shared_ptr<const LinOp> scalar,
107 std::shared_ptr<const LinOp> basis);
118 static std::unique_ptr<Perturbation>
create(
119 std::shared_ptr<const LinOp> scalar, std::shared_ptr<const LinOp> basis,
120 std::shared_ptr<const LinOp> projector);
123 explicit Perturbation(std::shared_ptr<const Executor> exec);
125 explicit Perturbation(std::shared_ptr<const LinOp> scalar,
126 std::shared_ptr<const LinOp> basis);
128 explicit Perturbation(std::shared_ptr<const LinOp> scalar,
129 std::shared_ptr<const LinOp> basis,
130 std::shared_ptr<const LinOp> projector);
132 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
135 LinOp* x)
const override;
142 void validate_perturbation();
145 std::shared_ptr<const LinOp> basis_;
146 std::shared_ptr<const LinOp> projector_;
147 std::shared_ptr<const LinOp> scalar_;
150 mutable struct cache_struct {
151 cache_struct() =
default;
152 ~cache_struct() =
default;
153 cache_struct(
const cache_struct& other) {}
154 cache_struct& operator=(
const cache_struct& other) {
return *
this; }
159 void allocate(std::shared_ptr<const Executor> exec, dim<2> size)
162 if (
one ==
nullptr) {
163 one = initialize<vec>({gko::one<ValueType>()}, exec);
165 if (alpha_scalar ==
nullptr) {
168 if (intermediate ==
nullptr || intermediate->get_size() != size) {
169 intermediate = vec::create(exec, size);
173 std::unique_ptr<LinOp> intermediate;
174 std::unique_ptr<LinOp>
one;
175 std::unique_ptr<LinOp> alpha_scalar;
183 #endif // GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_