Ginkgo  Generated from pipelines/3133041809 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
block_operator.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 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 #include <ginkgo/core/base/range.hpp>
13 
14 
15 namespace gko {
16 
17 
47 class BlockOperator final : public LinOp,
48  public EnableCloneable<BlockOperator> {
49  friend class EnableCloneable<BlockOperator>;
50 
51 public:
58  dim<2> get_block_size() const { return block_size_; }
59 
68  const LinOp* block_at(size_type i, size_type j) const
69  {
70  GKO_ENSURE_IN_DIMENSION_BOUNDS(i, j, block_size_);
71  return blocks_[i * block_size_[1] + j].get();
72  }
73 
81  static std::unique_ptr<BlockOperator> create(
82  std::shared_ptr<const Executor> exec);
83 
93  static std::unique_ptr<BlockOperator> create(
94  std::shared_ptr<const Executor> exec,
95  std::vector<std::vector<std::shared_ptr<const LinOp>>> blocks);
96 
101  BlockOperator(const BlockOperator& other);
102 
108  BlockOperator(BlockOperator&& other) noexcept;
109 
114  BlockOperator& operator=(const BlockOperator& other);
115 
123 
124 private:
125  explicit BlockOperator(std::shared_ptr<const Executor> exec);
126 
128  std::shared_ptr<const Executor> exec,
129  std::vector<std::vector<std::shared_ptr<const LinOp>>> blocks);
130 
131  void apply_impl(const AbstractMultiVector* b,
132  AbstractMultiVector* x) const override;
133 
134  void apply_impl(const AbstractMultiVector* alpha,
135  const AbstractMultiVector* b,
136  const AbstractMultiVector* beta,
137  AbstractMultiVector* x) const override;
138 
139  dim<2> block_size_;
140  std::vector<local_span> row_spans_;
141  std::vector<local_span> col_spans_;
142  std::vector<std::shared_ptr<const LinOp>> blocks_;
150  detail::DenseCache<default_precision> one_;
151 };
152 
153 
154 } // namespace gko
155 
156 #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:68
gko::LinOp
Definition: lin_op.hpp:163
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:102
gko::BlockOperator
A BlockOperator represents a linear operator that is partitioned into multiple blocks.
Definition: block_operator.hpp:47
gko::BlockOperator::operator=
BlockOperator & operator=(const BlockOperator &other)
Copy assigns a BlockOperator.
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
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:58
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:372
gko::AbstractMultiVector
Abstract interface class for (multi-)vector types.
Definition: multivector.hpp:81
gko::BlockOperator::create
static std::unique_ptr< BlockOperator > create(std::shared_ptr< const Executor > exec)
Create empty BlockOperator.