33#ifndef GKO_PUBLIC_CORE_BASE_COMPOSITION_HPP_
34#define GKO_PUBLIC_CORE_BASE_COMPOSITION_HPP_
40#include <ginkgo/core/base/executor.hpp>
41#include <ginkgo/core/base/lin_op.hpp>
66template <
typename ValueType = default_precision>
74 using value_type = ValueType;
120 void add_operators() {}
122 template <
typename...
Rest>
123 void add_operators(std::shared_ptr<const LinOp>
oper,
Rest&&...
rest)
125 if (!operators_.empty()) {
126 GKO_ASSERT_CONFORMANT(
this,
oper);
129 operators_.push_back(std::move(
oper));
130 if (operators_.back()->get_executor() != exec) {
131 operators_.back() =
gko::clone(exec, operators_.back());
133 this->set_size(dim<2>{operators_.front()->get_size()[0],
134 operators_.back()->get_size()[1]});
135 add_operators(std::forward<Rest>(
rest)...);
143 explicit Composition(std::shared_ptr<const Executor> exec)
157 typename = xstd::void_t<
158 typename std::iterator_traits<Iterator>::iterator_category>>
164 return (*begin)->get_executor();
168 for (
auto it = begin;
it != end; ++
it) {
181 template <
typename...
Rest>
185 add_operators(std::move(
oper), std::forward<Rest>(
rest)...);
188 void apply_impl(
const LinOp* b, LinOp* x)
const override;
190 void apply_impl(
const LinOp* alpha,
const LinOp* b,
const LinOp* beta,
191 LinOp* x)
const override;
194 std::vector<std::shared_ptr<const LinOp>> operators_;
205template <
typename ValueType = default_precision>
208 using value_type = ValueType;
233 if (composition_ ==
nullptr) {
236 return composition_->get_operators().at(index);
244 template <
typename...
LinOp>
245 void set_composition(
LinOp&&... linop)
252 std::shared_ptr<Composition<ValueType>> composition_;
The Composition class can be used to compose linear operators op1, op2, ..., opn and obtain the opera...
Definition composition.hpp:69
Composition & operator=(const Composition &)
Copy-assigns a Composition.
Composition(Composition &&)
Move-constructs a Composition.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
Composition(const Composition &)
Copy-constructs a Composition.
Composition & operator=(Composition &&)
Move-assigns a Composition.
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
const std::vector< std::shared_ptr< const LinOp > > & get_operators() const noexcept
Returns a list of operators of the composition.
Definition composition.hpp:82
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 UseComposition class can be used to store the composition information in LinOp.
Definition composition.hpp:206
std::shared_ptr< const LinOp > get_operator_at(size_type index) const
Returns the operator at index-th position of composition.
Definition composition.hpp:231
std::shared_ptr< Composition< ValueType > > get_composition() const
Returns the composition operators.
Definition composition.hpp:214
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
detail::cloned_type< Pointer > clone(const Pointer &p)
Creates a unique clone of the object pointed to by p.
Definition utils_helper.hpp:203