Ginkgo Generated from branch based on main. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
 
Loading...
Searching...
No Matches
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
14namespace gko {
15namespace detail {
16
17
22struct 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
76class BlockOperator final : public EnableLinOp<BlockOperator> {
78
79public:
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
130
136 BlockOperator(BlockOperator&& other) noexcept;
137
143
151
152private:
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
BlockOperator & operator=(const BlockOperator &other)
Copy assigns a BlockOperator.
static std::unique_ptr< BlockOperator > create(std::shared_ptr< const Executor > exec, std::vector< std::vector< std::shared_ptr< const LinOp > > > blocks)
Create BlockOperator from the given blocks.
BlockOperator(BlockOperator &&other) noexcept
Move constructs a BlockOperator.
BlockOperator & operator=(BlockOperator &&other)
Move assigns a BlockOperator.
dim< 2 > get_block_size() const
Get the block dimension of this, i.e.
Definition block_operator.hpp:86
const LinOp * block_at(size_type i, size_type j) const
Const access to a specific block.
Definition block_operator.hpp:96
BlockOperator(const BlockOperator &other)
Copy constructs a BlockOperator.
static std::unique_ptr< BlockOperator > create(std::shared_ptr< const Executor > exec)
Create empty BlockOperator.
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:879
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:662
Definition lin_op.hpp:117
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:89
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:26