5 #ifndef GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_
6 #define GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_
12 #include <ginkgo/core/base/lin_op.hpp>
13 #include <ginkgo/core/matrix/multivector.hpp>
31 template <
typename ValueType = default_precision>
36 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
39 using value_type = ValueType;
47 const std::vector<std::shared_ptr<const matrix::MultiVector<ValueType>>>&
64 std::unique_ptr<LinOp>
transpose()
const override;
96 void add_operators() {}
98 template <
typename... Rest>
100 std::shared_ptr<
const matrix::MultiVector<ValueType>> coef,
101 std::shared_ptr<const LinOp> oper, Rest&&... rest)
103 GKO_ASSERT_EQUAL_DIMENSIONS(coef, dim<2>(1, 1));
104 GKO_ASSERT_EQUAL_DIMENSIONS(oper, this->
get_size());
106 coefficients_.push_back(std::move(coef));
107 operators_.push_back(std::move(oper));
108 if (coefficients_.back()->get_executor() != exec) {
109 coefficients_.back() =
gko::clone(exec, coefficients_.back());
111 if (operators_.back()->get_executor() != exec) {
112 operators_.back() =
gko::clone(exec, operators_.back());
114 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>>
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>
178 std::shared_ptr<
const matrix::MultiVector<ValueType>> 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 AbstractMultiVector* b,
188 AbstractMultiVector* x)
const override;
190 void apply_impl(
const AbstractMultiVector* alpha,
191 const AbstractMultiVector* b,
192 const AbstractMultiVector* beta,
193 AbstractMultiVector* x)
const override;
196 std::vector<std::shared_ptr<const matrix::MultiVector<ValueType>>>
198 std::vector<std::shared_ptr<const LinOp>> operators_;
201 mutable struct cache_struct {
202 cache_struct() =
default;
203 ~cache_struct() =
default;
204 cache_struct(
const cache_struct& other) {}
205 cache_struct&
operator=(
const cache_struct& other) {
return *
this; }
207 std::unique_ptr<matrix::MultiVector<ValueType>>
zero;
208 std::unique_ptr<matrix::MultiVector<ValueType>>
one;
209 std::unique_ptr<AbstractMultiVector> intermediate_x;
217 #endif // GKO_PUBLIC_CORE_BASE_COMBINATION_HPP_