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>
35 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
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)...);
137 typename CoefficientIterator,
typename OperatorIterator,
138 typename = std::void_t<
139 typename std::iterator_traits<
140 CoefficientIterator>::iterator_category,
141 typename std::iterator_traits<OperatorIterator>::iterator_category>>
142 explicit Combination(CoefficientIterator coefficient_begin,
143 CoefficientIterator coefficient_end,
144 OperatorIterator operator_begin,
145 OperatorIterator operator_end)
147 if (operator_begin == operator_end) {
148 throw OutOfBoundsError(__FILE__, __LINE__, 1, 0);
150 return (*operator_begin)->get_executor();
153 GKO_ASSERT_EQ(std::distance(coefficient_begin, coefficient_end),
154 std::distance(operator_begin, operator_end));
155 this->set_size((*operator_begin)->get_size());
156 auto coefficient_it = coefficient_begin;
157 for (
auto operator_it = operator_begin; operator_it != operator_end;
159 add_operators(*coefficient_it, *operator_it);
174 template <
typename... Rest>
175 explicit Combination(std::shared_ptr<const LinOp> coef,
176 std::shared_ptr<const LinOp> oper, Rest&&... rest)
179 this->set_size(oper->get_size());
180 add_operators(std::move(coef), std::move(oper),
181 std::forward<Rest>(rest)...);
184 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
187 LinOp* x)
const override;
190 std::vector<std::shared_ptr<const LinOp>> coefficients_;
191 std::vector<std::shared_ptr<const LinOp>> operators_;
194 mutable struct cache_struct {
195 cache_struct() =
default;
196 ~cache_struct() =
default;
197 cache_struct(
const cache_struct& other) {}
198 cache_struct&
operator=(
const cache_struct& other) {
return *
this; }
200 std::unique_ptr<LinOp>
zero;
201 std::unique_ptr<LinOp>
one;
202 std::unique_ptr<LinOp> intermediate_x;
210 #endif // GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_