33#ifndef GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_
34#define GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_
40#include <ginkgo/core/base/lin_op.hpp>
58template <
typename ValueType = default_precision>
66 using value_type = ValueType;
123 void add_operators() {}
125 template <
typename...
Rest>
126 void add_operators(std::shared_ptr<const LinOp>
coef,
129 GKO_ASSERT_EQUAL_DIMENSIONS(
coef,
dim<2>(1, 1));
130 GKO_ASSERT_EQUAL_DIMENSIONS(
oper, this->get_size());
132 coefficients_.push_back(std::move(
coef));
133 operators_.push_back(std::move(
oper));
134 if (coefficients_.back()->get_executor() != exec) {
135 coefficients_.back() =
gko::clone(exec, coefficients_.back());
137 if (operators_.back()->get_executor() != exec) {
138 operators_.back() =
gko::clone(exec, operators_.back());
140 add_operators(std::forward<Rest>(
rest)...);
148 explicit Combination(std::shared_ptr<const Executor> exec)
168 typename = xstd::void_t<
169 typename std::iterator_traits<
171 typename std::iterator_traits<OperatorIterator>::iterator_category>>
180 return (*operator_begin)->get_executor();
185 this->set_size((*operator_begin)->get_size());
204 template <
typename...
Rest>
209 this->set_size(
oper->get_size());
210 add_operators(std::move(
coef), std::move(
oper),
211 std::forward<Rest>(
rest)...);
214 void apply_impl(
const LinOp* b, LinOp* x)
const override;
216 void apply_impl(
const LinOp* alpha,
const LinOp* b,
const LinOp* beta,
217 LinOp* x)
const override;
220 std::vector<std::shared_ptr<const LinOp>> coefficients_;
221 std::vector<std::shared_ptr<const LinOp>> operators_;
224 mutable struct cache_struct {
225 cache_struct() =
default;
226 ~cache_struct() =
default;
227 cache_struct(
const cache_struct& other) {}
228 cache_struct& operator=(
const cache_struct& other) {
return *
this; }
230 std::unique_ptr<LinOp> zero;
231 std::unique_ptr<LinOp> one;
232 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:61
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:85
const std::vector< std::shared_ptr< const LinOp > > & get_coefficients() const noexcept
Returns a list of coefficients of the combination.
Definition combination.hpp:74
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: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
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition polymorphic_object.hpp:263
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:462
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
detail::cloned_type< Pointer > clone(const Pointer &p)
Creates a unique clone of the object pointed to by p.
Definition utils_helper.hpp:203
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:55