5#ifndef GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_
6#define GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_
12#include <ginkgo/core/base/lin_op.hpp>
30template <
typename ValueType = default_precision>
38 using value_type = ValueType;
95 void add_operators() {}
97 template <
typename...
Rest>
98 void add_operators(std::shared_ptr<const LinOp>
coef,
101 GKO_ASSERT_EQUAL_DIMENSIONS(
coef,
dim<2>(1, 1));
102 GKO_ASSERT_EQUAL_DIMENSIONS(
oper, this->get_size());
104 coefficients_.push_back(std::move(
coef));
105 operators_.push_back(std::move(
oper));
106 if (coefficients_.back()->get_executor() != exec) {
107 coefficients_.back() =
gko::clone(exec, coefficients_.back());
109 if (operators_.back()->get_executor() != exec) {
110 operators_.back() =
gko::clone(exec, operators_.back());
112 add_operators(std::forward<Rest>(
rest)...);
120 explicit Combination(std::shared_ptr<const Executor> exec)
140 typename = xstd::void_t<
141 typename std::iterator_traits<
143 typename std::iterator_traits<OperatorIterator>::iterator_category>>
152 return (*operator_begin)->get_executor();
157 this->set_size((*operator_begin)->get_size());
176 template <
typename...
Rest>
181 this->set_size(
oper->get_size());
182 add_operators(std::move(
coef), std::move(
oper),
183 std::forward<Rest>(
rest)...);
186 void apply_impl(
const LinOp* b, LinOp* x)
const override;
188 void apply_impl(
const LinOp* alpha,
const LinOp* b,
const LinOp* beta,
189 LinOp* x)
const override;
192 std::vector<std::shared_ptr<const LinOp>> coefficients_;
193 std::vector<std::shared_ptr<const LinOp>> operators_;
196 mutable struct cache_struct {
197 cache_struct() =
default;
198 ~cache_struct() =
default;
199 cache_struct(
const cache_struct& other) {}
200 cache_struct& operator=(
const cache_struct& other) {
return *
this; }
202 std::unique_ptr<LinOp> zero;
203 std::unique_ptr<LinOp> one;
204 std::unique_ptr<LinOp> intermediate_x;
The Combination class can be used to construct a linear combination of multiple linear operators c1 *...
Definition combination.hpp:33
Combination & operator=(const Combination &)
Copy-assigns a Combination.
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
Combination(Combination &&)
Move-constructs a Combination.
Combination & operator=(Combination &&)
Move-assigns a Combination.
const std::vector< std::shared_ptr< const LinOp > > & get_operators() const noexcept
Returns a list of operators of the combination.
Definition combination.hpp:57
const std::vector< std::shared_ptr< const LinOp > > & get_coefficients() const noexcept
Returns a list of coefficients of the combination.
Definition combination.hpp:46
Combination(const Combination &)
Copy-constructs a Combination.
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
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition polymorphic_object.hpp:235
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:434
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:775
detail::cloned_type< Pointer > clone(const Pointer &p)
Creates a unique clone of the object pointed to by p.
Definition utils_helper.hpp:175
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:27