Ginkgo  Generated from pipelines/2662685947 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
scaled_permutation.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 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 
19 namespace gko {
20 namespace matrix {
21 
22 
35 template <typename ValueType = default_precision, typename IndexType = int32>
36 class ScaledPermutation final
37  : public LinOp,
38  public EnableCloneable<ScaledPermutation<ValueType, IndexType>>,
39  public WritableToMatrixData<ValueType, IndexType> {
40  friend class EnableCloneable<ScaledPermutation>;
41  GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
42 
43 public:
44  using value_type = ValueType;
45  using index_type = IndexType;
46 
52  value_type* get_scaling_factors() noexcept { return scale_.get_data(); }
53 
61  const value_type* get_const_scaling_factors() const noexcept
62  {
63  return scale_.get_const_data();
64  }
65 
71  index_type* get_permutation() noexcept { return permutation_.get_data(); }
72 
80  const index_type* get_const_permutation() const noexcept
81  {
82  return permutation_.get_const_data();
83  }
84 
93  std::unique_ptr<ScaledPermutation> compute_inverse() const;
94 
103  std::unique_ptr<ScaledPermutation> compose(
105 
106  void write(gko::matrix_data<value_type, index_type>& data) const override;
107 
116  static std::unique_ptr<ScaledPermutation> create(
117  std::shared_ptr<const Executor> exec, size_type size = 0);
118 
127  static std::unique_ptr<ScaledPermutation> create(
128  ptr_param<const Permutation<IndexType>> permutation);
129 
139  static std::unique_ptr<ScaledPermutation> create(
140  std::shared_ptr<const Executor> exec, array<value_type> scaling_factors,
141  array<index_type> permutation_indices);
142 
154  static std::unique_ptr<const ScaledPermutation> create_const(
155  std::shared_ptr<const Executor> exec,
156  gko::detail::const_array_view<value_type>&& scale,
157  gko::detail::const_array_view<index_type>&& perm_idxs);
158 
159 private:
160  ScaledPermutation(std::shared_ptr<const Executor> exec, size_type size = 0);
161 
162  ScaledPermutation(std::shared_ptr<const Executor> exec,
163  array<value_type> scaling_factors,
164  array<index_type> permutation_indices);
165 
166  void apply_impl(const LinOp* in, LinOp* out) const override;
167 
168  void apply_impl(const LinOp*, const LinOp* in, const LinOp*,
169  LinOp* out) const override;
170 
171  array<value_type> scale_;
172  array<index_type> permutation_;
173 };
174 
175 
176 } // namespace matrix
177 } // namespace gko
178 
179 
180 #endif // GKO_PUBLIC_CORE_MATRIX_SCALED_PERMUTATION_HPP_
gko::matrix::ScaledPermutation::write
void write(gko::matrix_data< value_type, index_type > &data) const override
Writes a matrix to a matrix_data structure.
gko::LinOp
Definition: lin_op.hpp:117
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:61
gko::matrix::ScaledPermutation
ScaledPermutation is a matrix combining a permutation with scaling factors.
Definition: scaled_permutation.hpp:36
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:90
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::Permutation
Permutation is a matrix format that represents a permutation matrix, i.e.
Definition: csr.hpp:52
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
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::get_const_permutation
const index_type * get_const_permutation() const noexcept
Returns a pointer to the permutation indices.
Definition: scaled_permutation.hpp:80
gko::array< value_type >
gko::matrix::ScaledPermutation::compute_inverse
std::unique_ptr< ScaledPermutation > compute_inverse() const
Returns the inverse of this operator as a scaled permutation.
gko::matrix_data
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:126
gko::matrix::ScaledPermutation::get_permutation
index_type * get_permutation() noexcept
Returns a pointer to the permutation indices.
Definition: scaled_permutation.hpp:71
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::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:43
gko::array::get_data
value_type * get_data() noexcept
Returns a pointer to the block of memory used to store the elements of the array.
Definition: array.hpp:687
gko::WritableToMatrixData
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:619
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:369
gko::array::get_const_data
const value_type * get_const_data() const noexcept
Returns a constant pointer to the block of memory used to store the elements of the array.
Definition: array.hpp:696
gko::matrix::ScaledPermutation::get_scaling_factors
value_type * get_scaling_factors() noexcept
Returns a pointer to the scaling factors.
Definition: scaled_permutation.hpp:52