ginkgo/core/matrix/permutation.hpp Source File

ginkgo/core/matrix/permutation.hpp Source File#

Reference API: ginkgo/core/matrix/permutation.hpp Source File
Reference API
permutation.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_MATRIX_PERMUTATION_HPP_
6#define GKO_PUBLIC_CORE_MATRIX_PERMUTATION_HPP_
7
8
9#include <algorithm>
10#include <memory>
11#include <numeric>
12#include <vector>
13
14#include <ginkgo/core/base/array.hpp>
15#include <ginkgo/core/base/exception.hpp>
16#include <ginkgo/core/base/exception_helpers.hpp>
17#include <ginkgo/core/base/executor.hpp>
18#include <ginkgo/core/base/lin_op.hpp>
19#include <ginkgo/core/base/types.hpp>
20#include <ginkgo/core/base/utils.hpp>
21
22
23namespace gko {
24namespace matrix {
25
26
42enum class permute_mode : unsigned {
44 none = 0b000u,
46 rows = 0b001u,
48 columns = 0b010u,
53 symmetric = 0b011u,
55 inverse = 0b100u,
60 inverse_rows = 0b101u,
65 inverse_columns = 0b110u,
70 inverse_symmetric = 0b111u
71};
72
73
76
77
80
81
84
85
87std::ostream& operator<<(std::ostream& stream, permute_mode mode);
88
89
90using mask_type = gko::uint64;
91
92static constexpr mask_type row_permute = mask_type{1};
93GKO_DEPRECATED("permute mask is no longer supported")
94static constexpr mask_type column_permute = mask_type{1 << 2};
95GKO_DEPRECATED("permute mask is no longer supported")
96static constexpr mask_type inverse_permute = mask_type{1 << 3};
97
109template <typename IndexType = int32>
110class Permutation : public EnableLinOp<Permutation<IndexType>>,
111 public WritableToMatrixData<default_precision, IndexType> {
113
114public:
115 // value_type is only available to enable the usage of gko::write
116 using value_type = default_precision;
117 using index_type = IndexType;
118
124 index_type* get_permutation() noexcept { return permutation_.get_data(); }
125
133 const index_type* get_const_permutation() const noexcept
134 {
135 return permutation_.get_const_data();
136 }
137
145 GKO_DEPRECATED("use get_size()[0] instead")
147
148 GKO_DEPRECATED("permute mask is no longer supported")
149 mask_type get_permute_mask() const;
150
151 GKO_DEPRECATED("permute mask is no longer supported")
152 void set_permute_mask(mask_type permute_mask);
153
160 std::unique_ptr<Permutation> compute_inverse() const;
161
173 std::unique_ptr<Permutation> compose(
174 ptr_param<const Permutation> other) const;
175
176 void write(gko::matrix_data<value_type, index_type>& data) const override;
177
185 static std::unique_ptr<Permutation> create(
186 std::shared_ptr<const Executor> exec, size_type size = 0);
187
203 static std::unique_ptr<Permutation> create(
204 std::shared_ptr<const Executor> exec,
205 array<IndexType> permutation_indices);
206
207 GKO_DEPRECATED(
208 "dim<2> is no longer supported as a dimension parameter, use size_type "
209 "instead")
210 static std::unique_ptr<Permutation> create(
211 std::shared_ptr<const Executor> exec, const dim<2>& size);
212
213 GKO_DEPRECATED("permute mask is no longer supported")
214 static std::unique_ptr<Permutation> create(
215 std::shared_ptr<const Executor> exec, const dim<2>& size,
216 const mask_type& enabled_permute);
217
218 GKO_DEPRECATED("use the overload without dimensions")
219 static std::unique_ptr<Permutation> create(
220 std::shared_ptr<const Executor> exec, const dim<2>& size,
221 array<IndexType> permutation_indices);
222
223 GKO_DEPRECATED("permute mask is no longer supported")
224 static std::unique_ptr<Permutation> create(
225 std::shared_ptr<const Executor> exec, const dim<2>& size,
226 array<index_type> permutation_indices,
227 const mask_type& enabled_permute);
228
240 GKO_DEPRECATED("use create_const without size and permute mask")
241 static std::unique_ptr<const Permutation> create_const(
242 std::shared_ptr<const Executor> exec, size_type size,
243 gko::detail::const_array_view<IndexType>&& perm_idxs,
244 mask_type enabled_permute = row_permute);
256 static std::unique_ptr<const Permutation> create_const(
257 std::shared_ptr<const Executor> exec,
258 gko::detail::const_array_view<IndexType>&& perm_idxs);
259
260protected:
261 Permutation(std::shared_ptr<const Executor> exec, size_type = 0);
262
263 Permutation(std::shared_ptr<const Executor> exec,
264 array<IndexType> permutation_indices);
265
266 void apply_impl(const LinOp* in, LinOp* out) const override;
267
268 void apply_impl(const LinOp*, const LinOp* in, const LinOp*,
269 LinOp* out) const override;
270
271private:
272 array<index_type> permutation_;
273};
274
275
276} // namespace matrix
277} // namespace gko
278
279
280#endif // GKO_PUBLIC_CORE_MATRIX_PERMUTATION_HPP_
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition executor.hpp:615
Definition lin_op.hpp:117
Definition lin_op.hpp:660
Definition array.hpp:166
value_type * get_data() noexcept
Definition array.hpp:673
const value_type * get_const_data() const noexcept
Definition array.hpp:682
Definition permutation.hpp:111
static std::unique_ptr< Permutation > create(std::shared_ptr< const Executor > exec, size_type size=0)
size_type get_permutation_size() const noexcept
std::unique_ptr< Permutation > compose(ptr_param< const Permutation > other) const
index_type * get_permutation() noexcept
Definition permutation.hpp:124
static std::unique_ptr< const Permutation > create_const(std::shared_ptr< const Executor > exec, size_type size, gko::detail::const_array_view< IndexType > &&perm_idxs, mask_type enabled_permute=row_permute)
const index_type * get_const_permutation() const noexcept
Definition permutation.hpp:133
std::unique_ptr< Permutation > compute_inverse() const
Definition utils_helper.hpp:41
permute_mode operator|(permute_mode a, permute_mode b)
permute_mode operator&(permute_mode a, permute_mode b)
permute_mode operator^(permute_mode a, permute_mode b)
std::ostream & operator<<(std::ostream &stream, permute_mode mode)
permute_mode
Definition permutation.hpp:42
The Ginkgo namespace.
Definition abstract_factory.hpp:20
double default_precision
Definition types.hpp:171
std::size_t size_type
Definition types.hpp:89
std::uint64_t uint64
Definition types.hpp:135
std::decay_t< T > * as(U *obj)
Definition utils_helper.hpp:307
STL namespace.
Definition dim.hpp:26
Definition matrix_data.hpp:126