33 #ifndef GKO_CORE_BASE_COMBINATION_HPP_ 34 #define GKO_CORE_BASE_COMBINATION_HPP_ 40 #include <ginkgo/core/base/lin_op.hpp> 54 template <
typename ValueType = default_precision>
61 using value_type = ValueType;
91 explicit Combination(std::shared_ptr<const Executor> exec)
110 typename CoefficientIterator,
typename OperatorIterator,
111 typename = xstd::void_t<
112 typename std::iterator_traits<
113 CoefficientIterator>::iterator_category,
114 typename std::iterator_traits<OperatorIterator>::iterator_category>>
115 explicit Combination(CoefficientIterator coefficient_begin,
116 CoefficientIterator coefficient_end,
117 OperatorIterator operator_begin,
118 OperatorIterator operator_end)
120 if (operator_begin == operator_end) {
123 return (*operator_begin)->get_executor();
125 coefficients_(coefficient_begin, coefficient_end),
126 operators_(operator_begin, operator_end)
128 for (
const auto &c : coefficients_) {
129 GKO_ASSERT_EQUAL_DIMENSIONS(c,
dim<2>(1, 1));
131 this->set_size(operators_[0]->
get_size());
132 for (
const auto &o : operators_) {
133 GKO_ASSERT_EQUAL_DIMENSIONS(o, this->
get_size());
147 template <
typename... Rest>
148 explicit Combination(std::shared_ptr<const LinOp> coef,
149 std::shared_ptr<const LinOp> oper, Rest &&... rest)
150 : Combination(std::forward<Rest>(rest)...)
152 GKO_ASSERT_EQUAL_DIMENSIONS(coef,
dim<2>(1, 1));
153 GKO_ASSERT_EQUAL_DIMENSIONS(oper, this->
get_size());
154 coefficients_.insert(begin(coefficients_), coef);
155 operators_.insert(begin(operators_), oper);
171 explicit Combination(std::shared_ptr<const LinOp> coef,
172 std::shared_ptr<const LinOp> oper)
178 void apply_impl(
const LinOp *b, LinOp *x)
const override;
180 void apply_impl(
const LinOp *alpha,
const LinOp *b,
const LinOp *beta,
181 LinOp *x)
const override;
184 std::vector<std::shared_ptr<const LinOp>> coefficients_;
185 std::vector<std::shared_ptr<const LinOp>> operators_;
188 mutable struct cache_struct {
189 cache_struct() =
default;
190 cache_struct(
const cache_struct &other) {}
191 cache_struct &operator=(
const cache_struct &other) {
return *
this; }
193 std::unique_ptr<LinOp>
zero;
194 std::unique_ptr<LinOp>
one;
195 std::unique_ptr<LinOp> intermediate_x;
203 #endif // GKO_CORE_BASE_COMBINATION_HPP_
This mixin implements a static create() method on ConcreteType that dynamically allocates the memory...
Definition: polymorphic_object.hpp:576
constexpr T zero()
Returns the additive identity for T.
Definition: math.hpp:292
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:505
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
const std::vector< std::shared_ptr< const LinOp > > & get_coefficients() const noexcept
Returns a list of coefficients of the combination.
Definition: combination.hpp:68
OutOfBoundsError is thrown if a memory access is detected to be out-of-bounds.
Definition: exception.hpp:297
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:509
const dim< 2 > & get_size() const noexcept
Returns the size of the operator.
Definition: lin_op.hpp:221
const std::vector< std::shared_ptr< const LinOp > > & get_operators() const noexcept
Returns a list of operators of the combination.
Definition: combination.hpp:79
The Combination class can be used to construct a linear combination of multiple linear operators `c1 ...
Definition: combination.hpp:55
constexpr T one()
Returns the multiplicative identity for T.
Definition: math.hpp:319