5 #ifndef GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_
6 #define GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_
12 #include <ginkgo/core/base/lin_op.hpp>
30 template <
typename ValueType = default_precision>
38 using value_type = ValueType;
63 std::unique_ptr<LinOp>
transpose()
const override;
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)...);
120 explicit Combination(std::shared_ptr<const Executor> exec)
139 typename CoefficientIterator,
typename OperatorIterator,
140 typename = xstd::void_t<
141 typename std::iterator_traits<
142 CoefficientIterator>::iterator_category,
143 typename std::iterator_traits<OperatorIterator>::iterator_category>>
144 explicit Combination(CoefficientIterator coefficient_begin,
145 CoefficientIterator coefficient_end,
146 OperatorIterator operator_begin,
147 OperatorIterator operator_end)
149 if (operator_begin == operator_end) {
150 throw OutOfBoundsError(__FILE__, __LINE__, 1, 0);
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>
177 explicit Combination(std::shared_ptr<const LinOp> coef,
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;
212 #endif // GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_