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,
99 std::shared_ptr<const LinOp> oper, Rest&&... rest)
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)...);
139 typename CoefficientIterator,
typename OperatorIterator,
140 typename = std::void_t<
141 typename std::iterator_traits<
142 CoefficientIterator>::iterator_category,
143 typename std::iterator_traits<OperatorIterator>::iterator_category>>
145 CoefficientIterator coefficient_end,
146 OperatorIterator operator_begin,
147 OperatorIterator operator_end)
149 if (operator_begin == operator_end) {
152 return (*operator_begin)->get_executor();
155 GKO_ASSERT_EQ(std::distance(coefficient_begin, coefficient_end),
156 std::distance(operator_begin, operator_end));
157 this->set_size((*operator_begin)->get_size());
158 auto coefficient_it = coefficient_begin;
159 for (
auto operator_it = operator_begin; operator_it != operator_end;
161 add_operators(*coefficient_it, *operator_it);
176 template <
typename... Rest>
178 std::shared_ptr<const LinOp> oper, Rest&&... 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;
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;
Definition combination.hpp:33
Combination & operator=(const Combination &)
std::unique_ptr< LinOp > conj_transpose() const override
std::unique_ptr< LinOp > transpose() const override
Combination(Combination &&)
Combination & operator=(Combination &&)
Combination(std::shared_ptr< const Executor > exec)
Definition combination.hpp:120
Combination(std::shared_ptr< const LinOp > coef, std::shared_ptr< const LinOp > oper, Rest &&... rest)
Definition combination.hpp:177
Combination(CoefficientIterator coefficient_begin, CoefficientIterator coefficient_end, OperatorIterator operator_begin, OperatorIterator operator_end)
Definition combination.hpp:144
const std::vector< std::shared_ptr< const LinOp > > & get_operators() const noexcept
Definition combination.hpp:57
const std::vector< std::shared_ptr< const LinOp > > & get_coefficients() const noexcept
Definition combination.hpp:46
Combination(const Combination &)
Definition polymorphic_object.hpp:767
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:117
Definition exception.hpp:558
std::shared_ptr< const Executor > get_executor() const noexcept
Definition polymorphic_object.hpp:243
Definition lin_op.hpp:433
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Definition math.hpp:630
constexpr T zero()
Definition math.hpp:602
detail::cloned_type< Pointer > clone(const Pointer &p)
Definition utils_helper.hpp:173