Ginkgo  Generated from pipelines/1556235455 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
block_operator.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GINKGO_BLOCK_MATRIX_HPP
6 #define GINKGO_BLOCK_MATRIX_HPP
7 
8 #include <ginkgo/config.hpp>
9 #include <ginkgo/core/base/dense_cache.hpp>
10 #include <ginkgo/core/base/lin_op.hpp>
11 #include <ginkgo/core/base/polymorphic_object.hpp>
12 
13 
14 namespace gko {
15 namespace detail {
16 
17 
22 struct value_span {
23  constexpr value_span(size_type point) noexcept
24  : value_span{point, point + 1}
25  {}
26 
27  constexpr value_span(size_type begin, size_type end) noexcept
28  : begin{begin}, end{end}
29  {}
30 
31  constexpr operator span() const { return {begin, end}; }
32 
33  constexpr value_span(const span& s) noexcept : value_span(s.begin, s.end) {}
34 
35  constexpr bool is_valid() const { return begin <= end; }
36 
37  constexpr size_type length() const { return end - begin; }
38 
39  size_type begin;
40  size_type end;
41 };
42 
43 
44 } // namespace detail
45 
46 
76 class BlockOperator final : public EnableLinOp<BlockOperator> {
78 
79 public:
86  dim<2> get_block_size() const { return block_size_; }
87 
96  const LinOp* block_at(size_type i, size_type j) const
97  {
98  GKO_ENSURE_IN_DIMENSION_BOUNDS(i, j, block_size_);
99  return blocks_[i * block_size_[1] + j].get();
100  }
101 
109  static std::unique_ptr<BlockOperator> create(
110  std::shared_ptr<const Executor> exec);
111 
121  static std::unique_ptr<BlockOperator> create(
122  std::shared_ptr<const Executor> exec,
123  std::vector<std::vector<std::shared_ptr<const LinOp>>> blocks);
124 
129  BlockOperator(const BlockOperator& other);
130 
136  BlockOperator(BlockOperator&& other) noexcept;
137 
142  BlockOperator& operator=(const BlockOperator& other);
143 
151 
152 private:
153  explicit BlockOperator(std::shared_ptr<const Executor> exec);
154 
156  std::shared_ptr<const Executor> exec,
157  std::vector<std::vector<std::shared_ptr<const LinOp>>> blocks);
158 
159  void apply_impl(const LinOp* b, LinOp* x) const override;
160 
161  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
162  LinOp* x) const override;
163 
164  dim<2> block_size_;
165  std::vector<detail::value_span> row_spans_;
166  std::vector<detail::value_span> col_spans_;
167  std::vector<std::shared_ptr<const LinOp>> blocks_;
175  detail::DenseCache<default_precision> one_;
176 };
177 
178 
179 } // namespace gko
180 
181 #endif // GINKGO_BLOCK_MATRIX_HPP
gko::BlockOperator::block_at
const LinOp * block_at(size_type i, size_type j) const
Const access to a specific block.
Definition: block_operator.hpp:96
gko::LinOp
Definition: lin_op.hpp:117
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:86
gko::BlockOperator
A BlockOperator represents a linear operator that is partitioned into multiple blocks.
Definition: block_operator.hpp:76
gko::BlockOperator::operator=
BlockOperator & operator=(const BlockOperator &other)
Copy assigns a BlockOperator.
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::dim< 2 >
gko::BlockOperator::BlockOperator
BlockOperator(const BlockOperator &other)
Copy constructs a BlockOperator.
gko::BlockOperator::get_block_size
dim< 2 > get_block_size() const
Get the block dimension of this, i.e.
Definition: block_operator.hpp:86
gko::BlockOperator::create
static std::unique_ptr< BlockOperator > create(std::shared_ptr< const Executor > exec)
Create empty BlockOperator.
gko::EnableLinOp
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:877
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:661