33#ifndef GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_
34#define GKO_PUBLIC_CORE_BASE_PERTURBATION_HPP_
40#include <ginkgo/core/base/lin_op.hpp>
41#include <ginkgo/core/matrix/dense.hpp>
66template <
typename ValueType = default_precision>
73 using value_type = ValueType;
119 explicit Perturbation(std::shared_ptr<const Executor> exec)
131 explicit Perturbation(std::shared_ptr<const LinOp>
scalar,
132 std::shared_ptr<const LinOp>
basis)
148 explicit Perturbation(std::shared_ptr<const LinOp>
scalar,
149 std::shared_ptr<const LinOp>
basis,
153 scalar_{std::move(
scalar)},
154 basis_{std::move(
basis)},
157 this->validate_perturbation();
160 void apply_impl(
const LinOp* b, LinOp* x)
const override;
162 void apply_impl(
const LinOp* alpha,
const LinOp* b,
const LinOp* beta,
163 LinOp* x)
const override;
170 void validate_perturbation()
172 GKO_ASSERT_CONFORMANT(basis_, projector_);
173 GKO_ASSERT_CONFORMANT(projector_, basis_);
174 GKO_ASSERT_EQUAL_DIMENSIONS(scalar_, dim<2>(1, 1));
178 std::shared_ptr<const LinOp> basis_;
179 std::shared_ptr<const LinOp> projector_;
180 std::shared_ptr<const LinOp> scalar_;
183 mutable struct cache_struct {
184 cache_struct() =
default;
185 ~cache_struct() =
default;
186 cache_struct(
const cache_struct& other) {}
187 cache_struct& operator=(
const cache_struct& other) {
return *
this; }
192 void allocate(std::shared_ptr<const Executor> exec, dim<2> size)
195 if (one ==
nullptr) {
198 if (alpha_scalar ==
nullptr) {
201 if (intermediate ==
nullptr || intermediate->get_size() != size) {
202 intermediate = vec::create(exec, size);
206 std::unique_ptr<LinOp> intermediate;
207 std::unique_ptr<LinOp> one;
208 std::unique_ptr<LinOp> alpha_scalar;
This mixin implements a static create() method on ConcreteType that dynamically allocates the memory,...
Definition polymorphic_object.hpp:776
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
The Perturbation class can be used to construct a LinOp to represent the operation (identity + scalar...
Definition perturbation.hpp:68
const std::shared_ptr< const LinOp > get_basis() const noexcept
Returns the basis of the perturbation.
Definition perturbation.hpp:80
const std::shared_ptr< const LinOp > get_projector() const noexcept
Returns the projector of the perturbation.
Definition perturbation.hpp:90
const std::shared_ptr< const LinOp > get_scalar() const noexcept
Returns the scalar of the perturbation.
Definition perturbation.hpp:100
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition polymorphic_object.hpp:263
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:136
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::decay_t< T > * as(U *obj)
Performs polymorphic type conversion.
Definition utils_helper.hpp:337
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:55