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>
13 #include <ginkgo/core/matrix/multivector.hpp>
38 template <
typename ValueType = default_precision>
44 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
47 using value_type = ValueType;
54 const std::shared_ptr<const LinOp>
get_basis() const noexcept
74 const std::shared_ptr<const matrix::MultiVector<ValueType>>
get_scalar()
95 static std::unique_ptr<Perturbation>
create(
96 std::shared_ptr<const Executor> exec);
108 static std::unique_ptr<Perturbation>
create(
110 std::shared_ptr<const LinOp> basis);
121 static std::unique_ptr<Perturbation>
create(
123 std::shared_ptr<const LinOp> basis,
124 std::shared_ptr<const LinOp> projector);
127 explicit Perturbation(std::shared_ptr<const Executor> exec);
131 std::shared_ptr<const LinOp> basis);
135 std::shared_ptr<const LinOp> basis,
136 std::shared_ptr<const LinOp> projector);
151 void validate_perturbation();
154 std::shared_ptr<const LinOp> basis_;
155 std::shared_ptr<const LinOp> projector_;
156 std::shared_ptr<const matrix::MultiVector<ValueType>> scalar_;
159 mutable struct cache_struct {
160 cache_struct() =
default;
161 ~cache_struct() =
default;
162 cache_struct(
const cache_struct& other) {}
163 cache_struct& operator=(
const cache_struct& other) {
return *
this; }
168 void allocate(std::shared_ptr<const Executor> exec, dim<2> size)
170 using vec = matrix::MultiVector<ValueType>;
171 if (
one ==
nullptr) {
172 one = initialize<vec>({gko::one<ValueType>()}, exec);
174 if (alpha_scalar ==
nullptr) {
177 if (intermediate ==
nullptr || intermediate->get_size() != size) {
178 intermediate = vec::create(exec, size);
182 std::unique_ptr<AbstractMultiVector> intermediate;
183 std::unique_ptr<matrix::MultiVector<ValueType>>
one;
184 std::unique_ptr<matrix::MultiVector<ValueType>> alpha_scalar;
192 #endif // GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_