Ginkgo: ginkgo/core/matrix/scaled_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
scaled_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_SCALED_PERMUTATION_HPP_
6#define GKO_PUBLIC_CORE_MATRIX_SCALED_PERMUTATION_HPP_
7
8
9#include <memory>
10
11#include <ginkgo/core/base/array.hpp>
12#include <ginkgo/core/base/executor.hpp>
13#include <ginkgo/core/base/lin_op.hpp>
14#include <ginkgo/core/base/types.hpp>
15#include <ginkgo/core/base/utils.hpp>
16#include <ginkgo/core/matrix/permutation.hpp>
17
18
19namespace gko {
20namespace matrix {
21
22
35template <typename ValueType = default_precision, typename IndexType = int32>
36 class ScaledPermutation final
37 : public EnableLinOp<ScaledPermutation<ValueType, IndexType>>,
38 public WritableToMatrixData<ValueType, IndexType> {
39 friend class EnablePolymorphicObject<ScaledPermutation, LinOp>;
40 GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
41
42public:
43 using value_type = ValueType;
44 using index_type = IndexType;
45
51 value_type* get_scaling_factors() noexcept { return scale_.get_data(); }
52
60 const value_type* get_const_scaling_factors() const noexcept
61 {
62 return scale_.get_const_data();
63 }
64
70 index_type* get_permutation() noexcept { return permutation_.get_data(); }
71
79 const index_type* get_const_permutation() const noexcept
80 {
81 return permutation_.get_const_data();
82 }
83
92 std::unique_ptr<ScaledPermutation> compute_inverse() const;
93
102 std::unique_ptr<ScaledPermutation> compose(
103 ptr_param<const ScaledPermutation> other) const;
104
105 void write(gko::matrix_data<value_type, index_type>& data) const override;
106
115 static std::unique_ptr<ScaledPermutation> create(
116 std::shared_ptr<const Executor> exec, size_type size = 0);
117
126 static std::unique_ptr<ScaledPermutation> create(
127 ptr_param<const Permutation<IndexType>> permutation);
128
138 static std::unique_ptr<ScaledPermutation> create(
139 std::shared_ptr<const Executor> exec, array<value_type> scaling_factors,
140 array<index_type> permutation_indices);
141
153 static std::unique_ptr<const ScaledPermutation> create_const(
154 std::shared_ptr<const Executor> exec,
155 gko::detail::const_array_view<value_type>&& scale,
156 gko::detail::const_array_view<index_type>&& perm_idxs);
157
158private:
159 ScaledPermutation(std::shared_ptr<const Executor> exec, size_type size = 0);
160
161 ScaledPermutation(std::shared_ptr<const Executor> exec,
162 array<value_type> scaling_factors,
163 array<index_type> permutation_indices);
164
165 void apply_impl(const LinOp* in, LinOp* out) const override;
166
167 void apply_impl(const LinOp*, const LinOp* in, const LinOp*,
168 LinOp* out) const override;
169
170 array<value_type> scale_;
171 array<index_type> permutation_;
172};
173
174
175} // namespace matrix
176} // namespace gko
177
178
179#endif // GKO_PUBLIC_CORE_MATRIX_SCALED_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::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
Permutation is a matrix format that represents a permutation matrix, i.e.
Definition permutation.hpp:112
gko::matrix::ScaledPermutation::get_const_scaling_factors
const value_type * get_const_scaling_factors() const noexcept
Returns a pointer to the scaling factors.
Definition scaled_permutation.hpp:60
gko::matrix::ScaledPermutation::get_permutation
index_type * get_permutation() noexcept
Returns a pointer to the permutation indices.
Definition scaled_permutation.hpp:70
gko::matrix::ScaledPermutation::get_const_permutation
const index_type * get_const_permutation() const noexcept
Returns a pointer to the permutation indices.
Definition scaled_permutation.hpp:79
gko::matrix::ScaledPermutation::create
static std::unique_ptr< ScaledPermutation > create(std::shared_ptr< const Executor > exec, array< value_type > scaling_factors, array< index_type > permutation_indices)
Creates a ScaledPermutation matrix from already allocated arrays.
gko::matrix::ScaledPermutation::create
static std::unique_ptr< ScaledPermutation > create(ptr_param< const Permutation< IndexType > > permutation)
Create a ScaledPermutation from a Permutation.
gko::matrix::ScaledPermutation::create
static std::unique_ptr< ScaledPermutation > create(std::shared_ptr< const Executor > exec, size_type size=0)
Creates an uninitialized ScaledPermutation matrix.
gko::matrix::ScaledPermutation::compose
std::unique_ptr< ScaledPermutation > compose(ptr_param< const ScaledPermutation > other) const
Composes this scaled permutation with another scaled permutation.
gko::matrix::ScaledPermutation::compute_inverse
std::unique_ptr< ScaledPermutation > compute_inverse() const
Returns the inverse of this operator as a scaled permutation.
gko::matrix::ScaledPermutation::create_const
static std::unique_ptr< const ScaledPermutation > create_const(std::shared_ptr< const Executor > exec, gko::detail::const_array_view< value_type > &&scale, gko::detail::const_array_view< index_type > &&perm_idxs)
Creates a constant (immutable) ScaledPermutation matrix from constant arrays.
gko::matrix::ScaledPermutation::get_scaling_factors
value_type * get_scaling_factors() noexcept
Returns a pointer to the scaling factors.
Definition scaled_permutation.hpp:51
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
The Ginkgo namespace.
Definition abstract_factory.hpp:20
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
gko::matrix_data
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:126