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>
38template <
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) {
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;
This mixin implements a static create() method on ConcreteType that dynamically allocates the memory,...
Definition polymorphic_object.hpp:748
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:880
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:663
Definition lin_op.hpp:118
The Perturbation class can be used to construct a LinOp to represent the operation (identity + scalar...
Definition perturbation.hpp:40
const std::shared_ptr< const LinOp > get_basis() const noexcept
Returns the basis of the perturbation.
Definition perturbation.hpp:52
const std::shared_ptr< const LinOp > get_projector() const noexcept
Returns the projector of the perturbation.
Definition perturbation.hpp:62
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:72
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 sparsity_csr.hpp:26
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:1540
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:775
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:27