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>
44 using value_type = ValueType;
51 const std::shared_ptr<const LinOp>
get_basis() const noexcept
71 const std::shared_ptr<const LinOp>
get_scalar() const noexcept
91 static std::unique_ptr<Perturbation>
create(
92 std::shared_ptr<const Executor> exec);
104 static std::unique_ptr<Perturbation>
create(
105 std::shared_ptr<const LinOp> scalar,
106 std::shared_ptr<const LinOp> basis);
117 static std::unique_ptr<Perturbation>
create(
118 std::shared_ptr<const LinOp> scalar, std::shared_ptr<const LinOp> basis,
119 std::shared_ptr<const LinOp> projector);
122 explicit Perturbation(std::shared_ptr<const Executor> exec);
124 explicit Perturbation(std::shared_ptr<const LinOp> scalar,
125 std::shared_ptr<const LinOp> basis);
127 explicit Perturbation(std::shared_ptr<const LinOp> scalar,
128 std::shared_ptr<const LinOp> basis,
129 std::shared_ptr<const LinOp> projector);
131 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
134 LinOp* x)
const override;
141 void validate_perturbation();
144 std::shared_ptr<const LinOp> basis_;
145 std::shared_ptr<const LinOp> projector_;
146 std::shared_ptr<const LinOp> scalar_;
149 mutable struct cache_struct {
150 cache_struct() =
default;
151 ~cache_struct() =
default;
152 cache_struct(
const cache_struct& other) {}
153 cache_struct& operator=(
const cache_struct& other) {
return *
this; }
158 void allocate(std::shared_ptr<const Executor> exec, dim<2> size)
161 if (
one ==
nullptr) {
162 one = initialize<vec>({gko::one<ValueType>()}, exec);
164 if (alpha_scalar ==
nullptr) {
167 if (intermediate ==
nullptr || intermediate->get_size() != size) {
168 intermediate = vec::create(exec, size);
172 std::unique_ptr<LinOp> intermediate;
173 std::unique_ptr<LinOp>
one;
174 std::unique_ptr<LinOp> alpha_scalar;
182 #endif // GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_