Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
scaled_permutation.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_MATRIX_SCALED_PERMUTATION_HPP_
34#define GKO_PUBLIC_CORE_MATRIX_SCALED_PERMUTATION_HPP_
35
36
37#include <memory>
38
39
40#include <ginkgo/core/base/array.hpp>
41#include <ginkgo/core/base/executor.hpp>
42#include <ginkgo/core/base/lin_op.hpp>
43#include <ginkgo/core/base/types.hpp>
44#include <ginkgo/core/base/utils.hpp>
45#include <ginkgo/core/matrix/permutation.hpp>
46
47
48namespace gko {
49namespace matrix {
50
51
64template <typename ValueType = default_precision, typename IndexType = int32>
66 : public EnableLinOp<ScaledPermutation<ValueType, IndexType>>,
67 public WritableToMatrixData<ValueType, IndexType> {
69
70public:
71 using value_type = ValueType;
72 using index_type = IndexType;
73
79 value_type* get_scaling_factors() noexcept { return scale_.get_data(); }
80
89 {
90 return scale_.get_const_data();
91 }
92
98 index_type* get_permutation() noexcept { return permutation_.get_data(); }
99
108 {
109 return permutation_.get_const_data();
110 }
111
120 std::unique_ptr<ScaledPermutation> compute_inverse() const;
121
130 std::unique_ptr<ScaledPermutation> compose(
132
134
141 static std::unique_ptr<ScaledPermutation> create(
142 std::shared_ptr<const Executor> exec, size_type size = 0);
143
151 static std::unique_ptr<ScaledPermutation> create(
153
161 static std::unique_ptr<ScaledPermutation> create(
162 std::shared_ptr<const Executor> exec, array<value_type> scaling_factors,
164
176 static std::unique_ptr<const ScaledPermutation> create_const(
177 std::shared_ptr<const Executor> exec,
178 gko::detail::const_array_view<value_type>&& scale,
179 gko::detail::const_array_view<index_type>&& perm_idxs);
180
181private:
182 ScaledPermutation(std::shared_ptr<const Executor> exec, size_type size = 0);
183
184 ScaledPermutation(std::shared_ptr<const Executor> exec,
187
188 void apply_impl(const LinOp* in, LinOp* out) const override;
189
190 void apply_impl(const LinOp*, const LinOp* in, const LinOp*,
191 LinOp* out) const override;
192
193 array<value_type> scale_;
194 array<index_type> permutation_;
195};
196
197
198} // namespace matrix
199} // namespace gko
200
201
202#endif // GKO_PUBLIC_CORE_MATRIX_SCALED_PERMUTATION_HPP_
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:908
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:691
Definition lin_op.hpp:146
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition lin_op.hpp:689
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:187
value_type * get_data() noexcept
Returns a pointer to the block of memory used to store the elements of the array.
Definition array.hpp:646
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:655
Permutation is a matrix format that represents a permutation matrix, i.e.
Definition permutation.hpp:142
ScaledPermutation is a matrix combining a permutation with scaling factors.
Definition scaled_permutation.hpp:67
const value_type * get_const_scaling_factors() const noexcept
Returns a pointer to the scaling factors.
Definition scaled_permutation.hpp:88
index_type * get_permutation() noexcept
Returns a pointer to the permutation indices.
Definition scaled_permutation.hpp:98
const index_type * get_const_permutation() const noexcept
Returns a pointer to the permutation indices.
Definition scaled_permutation.hpp:107
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.
static std::unique_ptr< ScaledPermutation > create(ptr_param< const Permutation< IndexType > > permutation)
Create a ScaledPermutation from a Permutation.
void write(gko::matrix_data< value_type, index_type > &data) const override
Writes a matrix to a matrix_data structure.
static std::unique_ptr< ScaledPermutation > create(std::shared_ptr< const Executor > exec, size_type size=0)
Creates an uninitialized ScaledPermutation matrix.
std::unique_ptr< ScaledPermutation > compose(ptr_param< const ScaledPermutation > other) const
Composes this scaled permutation with another scaled permutation.
std::unique_ptr< ScaledPermutation > compute_inverse() const
Returns the inverse of this operator as a scaled permutation.
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.
value_type * get_scaling_factors() noexcept
Returns a pointer to the scaling factors.
Definition scaled_permutation.hpp:79
This class is used for function parameters in the place of raw pointers.
Definition utils_helper.hpp:71
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:155