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>
36 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
39 using value_type = ValueType;
64 std::unique_ptr<LinOp>
transpose()
const override;
96 void add_operators() {}
98 template <
typename... Rest>
99 void add_operators(std::shared_ptr<const LinOp> coef,
100 std::shared_ptr<const LinOp> oper, Rest&&... rest)
102 GKO_ASSERT_EQUAL_DIMENSIONS(coef, dim<2>(1, 1));
103 GKO_ASSERT_EQUAL_DIMENSIONS(oper, this->
get_size());
105 coefficients_.push_back(std::move(coef));
106 operators_.push_back(std::move(oper));
107 if (coefficients_.back()->get_executor() != exec) {
108 coefficients_.back() =
gko::clone(exec, coefficients_.back());
110 if (operators_.back()->get_executor() != exec) {
111 operators_.back() =
gko::clone(exec, operators_.back());
113 add_operators(std::forward<Rest>(rest)...);
121 explicit Combination(std::shared_ptr<const Executor> exec)
140 typename CoefficientIterator,
typename OperatorIterator,
141 typename = std::void_t<
142 typename std::iterator_traits<
143 CoefficientIterator>::iterator_category,
144 typename std::iterator_traits<OperatorIterator>::iterator_category>>
145 explicit Combination(CoefficientIterator coefficient_begin,
146 CoefficientIterator coefficient_end,
147 OperatorIterator operator_begin,
148 OperatorIterator operator_end)
150 if (operator_begin == operator_end) {
151 throw OutOfBoundsError(__FILE__, __LINE__, 1, 0);
153 return (*operator_begin)->get_executor();
156 GKO_ASSERT_EQ(std::distance(coefficient_begin, coefficient_end),
157 std::distance(operator_begin, operator_end));
158 this->set_size((*operator_begin)->get_size());
159 auto coefficient_it = coefficient_begin;
160 for (
auto operator_it = operator_begin; operator_it != operator_end;
162 add_operators(*coefficient_it, *operator_it);
177 template <
typename... Rest>
178 explicit Combination(std::shared_ptr<const LinOp> coef,
179 std::shared_ptr<const LinOp> oper, Rest&&... rest)
182 this->set_size(oper->get_size());
183 add_operators(std::move(coef), std::move(oper),
184 std::forward<Rest>(rest)...);
187 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
190 LinOp* x)
const override;
193 std::vector<std::shared_ptr<const LinOp>> coefficients_;
194 std::vector<std::shared_ptr<const LinOp>> operators_;
197 mutable struct cache_struct {
198 cache_struct() =
default;
199 ~cache_struct() =
default;
200 cache_struct(
const cache_struct& other) {}
201 cache_struct&
operator=(
const cache_struct& other) {
return *
this; }
203 std::unique_ptr<LinOp>
zero;
204 std::unique_ptr<LinOp>
one;
205 std::unique_ptr<LinOp> intermediate_x;
213 #endif // GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_