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
factorization.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_FACTORIZATION_FACTORIZATION_HPP_
34#define GKO_PUBLIC_CORE_FACTORIZATION_FACTORIZATION_HPP_
35
36
37#include <ginkgo/core/base/composition.hpp>
38#include <ginkgo/core/base/lin_op.hpp>
39#include <ginkgo/core/base/types.hpp>
40#include <ginkgo/core/matrix/csr.hpp>
41#include <ginkgo/core/matrix/diagonal.hpp>
42
43
44namespace gko {
45namespace experimental {
46namespace factorization {
47
48
53enum class storage_type {
55 empty,
60 composition,
61 /*
62 * The two factors are stored as a single matrix containing L + U - I, where
63 * L has an implicit unit diagonal.
64 */
65 combined_lu,
66 /*
67 * The factorization L * D * U is stored as L + D + U - 2I, where
68 * L and U have implicit unit diagonals.
69 */
70 combined_ldu,
75 symm_composition,
76 /*
77 * The factorization L * L^H is symmetric and stored as a single matrix
78 * containing L + L^H - diag(L).
79 */
80 symm_combined_cholesky,
81 /*
82 * The factorization is symmetric and stored as a single matrix containing
83 * L + D + L^H - 2 * diag(L), where L and L^H have an implicit unit
84 * diagonal.
85 */
86 symm_combined_ldl,
87};
88
89
103template <typename ValueType, typename IndexType>
104class Factorization : public EnableLinOp<Factorization<ValueType, IndexType>> {
106
107public:
108 using value_type = ValueType;
109 using index_type = IndexType;
113
122 std::unique_ptr<Factorization> unpack() const;
123
125 storage_type get_storage_type() const;
126
131 std::shared_ptr<const matrix_type> get_lower_factor() const;
132
137 std::shared_ptr<const diag_type> get_diagonal() const;
138
143 std::shared_ptr<const matrix_type> get_upper_factor() const;
144
149 std::shared_ptr<const matrix_type> get_combined() const;
150
153
156
157 Factorization& operator=(const Factorization&);
158
159 Factorization& operator=(Factorization&&);
160
170 static std::unique_ptr<Factorization> create_from_composition(
171 std::unique_ptr<composition_type> composition);
172
183 static std::unique_ptr<Factorization> create_from_symm_composition(
184 std::unique_ptr<composition_type> composition);
185
197 static std::unique_ptr<Factorization> create_from_combined_lu(
198 std::unique_ptr<matrix_type> matrix);
199
200 static std::unique_ptr<Factorization> create_from_combined_ldu(
201 std::unique_ptr<matrix_type> matrix);
202
203 static std::unique_ptr<Factorization> create_from_combined_cholesky(
204 std::unique_ptr<matrix_type> matrix);
205
206 static std::unique_ptr<Factorization> create_from_combined_ldl(
207 std::unique_ptr<matrix_type> matrix);
208
209protected:
210 explicit Factorization(std::shared_ptr<const Executor> exec);
211
213 storage_type type);
214
215 void apply_impl(const LinOp* b, LinOp* x) const override;
216
217 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
218 LinOp* x) const override;
219
220private:
221 storage_type storage_type_;
222 std::unique_ptr<Composition<ValueType>> factors_;
223};
224
225
226} // namespace factorization
227} // namespace experimental
228} // namespace gko
229
230#endif // GKO_PUBLIC_CORE_FACTORIZATION_FACTORIZATION_HPP_
The Composition class can be used to compose linear operators op1, op2, ..., opn and obtain the opera...
Definition composition.hpp:69
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
Represents a generic factorization consisting of two triangular factors (upper and lower) and an opti...
Definition factorization.hpp:104
std::shared_ptr< const matrix_type > get_lower_factor() const
Returns the lower triangular factor of the factorization, if available, nullptr otherwise.
std::shared_ptr< const diag_type > get_diagonal() const
Returns the diagonal scaling matrix of the factorization, if available, nullptr otherwise.
static std::unique_ptr< Factorization > create_from_composition(std::unique_ptr< composition_type > composition)
Creates a Factorization from an existing composition.
std::shared_ptr< const matrix_type > get_upper_factor() const
Returns the upper triangular factor of the factorization, if available, nullptr otherwise.
storage_type get_storage_type() const
Returns the storage type used by this factorization.
Factorization(const Factorization &)
Creates a deep copy of the factorization.
static std::unique_ptr< Factorization > create_from_symm_composition(std::unique_ptr< composition_type > composition)
Creates a Factorization from an existing symmetric composition.
std::shared_ptr< const matrix_type > get_combined() const
Returns the matrix storing a compact representation of the factorization, if available,...
std::unique_ptr< Factorization > unpack() const
Transforms the factorization from a compact representation suitable only for triangular solves to a c...
static std::unique_ptr< Factorization > create_from_combined_lu(std::unique_ptr< matrix_type > matrix)
Creates a Factorization from an existing combined representation of an LU factorization.
Factorization(Factorization &&)
Moves from the given factorization, leaving it empty.
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition csr.hpp:146
This class is a utility which efficiently implements the diagonal matrix (a linear operator which sca...
Definition diagonal.hpp:79
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803