Ginkgo: ginkgo/core/matrix/permutation.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
permutation.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 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
42 enum 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
75 permute_mode operator|(permute_mode a, permute_mode b);
76
77
79 permute_mode operator&(permute_mode a, permute_mode b);
80
81
83 permute_mode operator^(permute_mode a, permute_mode b);
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
110template <typename IndexType = int32>
111 class Permutation : public EnableLinOp<Permutation<IndexType>>,
112 public WritableToMatrixData<default_precision, IndexType> {
113 friend class EnablePolymorphicObject<Permutation, LinOp>;
114
115public:
116 // value_type is only available to enable the usage of gko::write
117 using value_type = default_precision;
118 using index_type = IndexType;
119
125 index_type* get_permutation() noexcept { return permutation_.get_data(); }
126
134 const index_type* get_const_permutation() const noexcept
135 {
136 return permutation_.get_const_data();
137 }
138
146 GKO_DEPRECATED("use get_size()[0] instead")
147 size_type get_permutation_size() const noexcept;
148
149 GKO_DEPRECATED("permute mask is no longer supported")
150 mask_type get_permute_mask() const;
151
152 GKO_DEPRECATED("permute mask is no longer supported")
153 void set_permute_mask(mask_type permute_mask);
154
161 std::unique_ptr<Permutation> compute_inverse() const;
162
174 std::unique_ptr<Permutation> compose(
175 ptr_param<const Permutation> other) const;
176
177 void write(gko::matrix_data<value_type, index_type>& data) const override;
178
186 static std::unique_ptr<Permutation> create(
187 std::shared_ptr<const Executor> exec, size_type size = 0);
188
204 static std::unique_ptr<Permutation> create(
205 std::shared_ptr<const Executor> exec,
206 array<IndexType> permutation_indices);
207
208 GKO_DEPRECATED(
209 "dim<2> is no longer supported as a dimension parameter, use size_type "
210 "instead")
211 static std::unique_ptr<Permutation> create(
212 std::shared_ptr<const Executor> exec, const dim<2>& size);
213
214 GKO_DEPRECATED("permute mask is no longer supported")
215 static std::unique_ptr<Permutation> create(
216 std::shared_ptr<const Executor> exec, const dim<2>& size,
217 const mask_type& enabled_permute);
218
219 GKO_DEPRECATED("use the overload without dimensions")
220 static std::unique_ptr<Permutation> create(
221 std::shared_ptr<const Executor> exec, const dim<2>& size,
222 array<IndexType> permutation_indices);
223
224 GKO_DEPRECATED("permute mask is no longer supported")
225 static std::unique_ptr<Permutation> create(
226 std::shared_ptr<const Executor> exec, const dim<2>& size,
227 array<index_type> permutation_indices,
228 const mask_type& enabled_permute);
229
241 GKO_DEPRECATED("use create_const without size and permute mask")
242 static std::unique_ptr<const Permutation> create_const(
243 std::shared_ptr<const Executor> exec, size_type size,
244 gko::detail::const_array_view<IndexType>&& perm_idxs,
245 mask_type enabled_permute = row_permute);
257 static std::unique_ptr<const Permutation> create_const(
258 std::shared_ptr<const Executor> exec,
259 gko::detail::const_array_view<IndexType>&& perm_idxs);
260
261protected:
262 Permutation(std::shared_ptr<const Executor> exec, size_type = 0);
263
264 Permutation(std::shared_ptr<const Executor> exec,
265 array<IndexType> permutation_indices);
266
267 void apply_impl(const LinOp* in, LinOp* out) const override;
268
269 void apply_impl(const LinOp*, const LinOp* in, const LinOp*,
270 LinOp* out) const override;
271
272private:
273 array<index_type> permutation_;
274};
275
276
277} // namespace matrix
278} // namespace gko
279
280
281#endif // GKO_PUBLIC_CORE_MATRIX_PERMUTATION_HPP_
gko::EnableLinOp
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:879
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
gko::Executor
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:615
gko::LinOp
Definition lin_op.hpp:117
gko::WritableToMatrixData
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition lin_op.hpp:660
gko::array
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
gko::matrix::Permutation< index_type >::create
static std::unique_ptr< Permutation > create(std::shared_ptr< const Executor > exec, size_type size=0)
gko::matrix::Permutation< index_type >::get_permutation_size
size_type get_permutation_size() const noexcept
gko::matrix::Permutation< index_type >::compose
std::unique_ptr< Permutation > compose(ptr_param< const Permutation > other) const
gko::matrix::Permutation::get_permutation
index_type * get_permutation() noexcept
Returns a pointer to the array of permutation.
Definition permutation.hpp:125
gko::matrix::Permutation< index_type >::create_const
static std::unique_ptr< const Permutation > create_const(std::shared_ptr< const Executor > exec, size_type size, gko::detail::const_array_view< index_type > &&perm_idxs, mask_type enabled_permute=row_permute)
gko::matrix::Permutation::get_const_permutation
const index_type * get_const_permutation() const noexcept
Returns a pointer to the array of permutation.
Definition permutation.hpp:134
gko::matrix::Permutation< index_type >::compute_inverse
std::unique_ptr< Permutation > compute_inverse() const
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition utils_helper.hpp:41
gko::matrix
The matrix namespace.
Definition dense_cache.hpp:24
gko::matrix::operator|
permute_mode operator|(permute_mode a, permute_mode b)
Combines two permutation modes.
gko::matrix::operator&
permute_mode operator&(permute_mode a, permute_mode b)
Computes the intersection of two permutation modes.
gko::matrix::operator^
permute_mode operator^(permute_mode a, permute_mode b)
Computes the symmetric difference of two permutation modes.
gko::matrix::operator<<
std::ostream & operator<<(std::ostream &stream, permute_mode mode)
Prints a permutation mode.
gko::matrix::permute_mode
permute_mode
Specifies how a permutation will be applied to a matrix.
Definition permutation.hpp:42
gko::matrix::permute_mode::none
@ none
Neither rows nor columns will be permuted.
Definition permutation.hpp:44
gko::matrix::permute_mode::columns
@ columns
The columns will be permuted.
Definition permutation.hpp:48
gko::matrix::permute_mode::inverse
@ inverse
The permutation will be inverted before being applied.
Definition permutation.hpp:55
gko::matrix::permute_mode::inverse_columns
@ inverse_columns
The columns will be permuted using the inverse permutation.
Definition permutation.hpp:65
gko::matrix::permute_mode::inverse_symmetric
@ inverse_symmetric
The rows and columns will be permuted using the inverse permutation.
Definition permutation.hpp:70
gko::matrix::permute_mode::rows
@ rows
The rows will be permuted.
Definition permutation.hpp:46
gko::matrix::permute_mode::inverse_rows
@ inverse_rows
The rows will be permuted using the inverse permutation.
Definition permutation.hpp:60
gko::matrix::permute_mode::symmetric
@ symmetric
The rows and columns will be permuted.
Definition permutation.hpp:53
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20
gko::uint64
std::uint64_t uint64
64-bit unsigned integral type.
Definition types.hpp:136
gko::default_precision
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:172
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
std
STL namespace.
gko::dim
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:26
gko::matrix_data
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:126