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>
37template <
typename ValueType = default_precision>
38class Perturbation :
public EnableLinOp<Perturbation<ValueType>>,
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) {
164 if (alpha_scalar ==
nullptr) {
165 alpha_scalar = vec::create(exec, gko::dim<2>(1));
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;
This mixin implements a static create() method on ConcreteType that dynamically allocates the memory,...
Definition polymorphic_object.hpp:767
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:879
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:117
The Perturbation class can be used to construct a LinOp to represent the operation (identity + scalar...
Definition perturbation.hpp:39
const std::shared_ptr< const LinOp > get_basis() const noexcept
Returns the basis of the perturbation.
Definition perturbation.hpp:51
const std::shared_ptr< const LinOp > get_projector() const noexcept
Returns the projector of the perturbation.
Definition perturbation.hpp:61
static std::unique_ptr< Perturbation > create(std::shared_ptr< const Executor > exec)
Creates an empty perturbation operator (0x0 operator).
static std::unique_ptr< Perturbation > create(std::shared_ptr< const LinOp > scalar, std::shared_ptr< const LinOp > basis)
Creates a perturbation with scalar and basis by setting projector to the conjugate transpose of basis...
const std::shared_ptr< const LinOp > get_scalar() const noexcept
Returns the scalar of the perturbation.
Definition perturbation.hpp:71
static std::unique_ptr< Perturbation > create(std::shared_ptr< const LinOp > scalar, std::shared_ptr< const LinOp > basis, std::shared_ptr< const LinOp > projector)
Creates a perturbation of scalar, basis and projector.
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:120
std::unique_ptr< Matrix > initialize(size_type stride, std::initializer_list< typename Matrix::value_type > vals, std::shared_ptr< const Executor > exec, TArgs &&... create_args)
Creates and initializes a column-vector.
Definition dense.hpp:1574
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:654