Ginkgo Generated from branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
factorization.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_FACTORIZATION_FACTORIZATION_HPP_
6#define GKO_PUBLIC_CORE_FACTORIZATION_FACTORIZATION_HPP_
7
8
9#include <ginkgo/core/base/composition.hpp>
10#include <ginkgo/core/base/lin_op.hpp>
11#include <ginkgo/core/base/types.hpp>
12#include <ginkgo/core/matrix/csr.hpp>
13#include <ginkgo/core/matrix/diagonal.hpp>
14
15
16namespace gko {
17namespace experimental {
18namespace factorization {
19
20
25enum class storage_type {
27 empty,
32 composition,
33 /*
34 * The two factors are stored as a single matrix containing L + U - I, where
35 * L has an implicit unit diagonal.
36 */
37 combined_lu,
38 /*
39 * The factorization L * D * U is stored as L + D + U - 2I, where
40 * L and U have implicit unit diagonals.
41 */
42 combined_ldu,
47 symm_composition,
48 /*
49 * The factorization L * L^H is symmetric and stored as a single matrix
50 * containing L + L^H - diag(L).
51 */
52 symm_combined_cholesky,
53 /*
54 * The factorization is symmetric and stored as a single matrix containing
55 * L + D + L^H - 2 * diag(L), where L and L^H have an implicit unit
56 * diagonal.
57 */
58 symm_combined_ldl,
59};
60
61
75template <typename ValueType, typename IndexType>
76class Factorization : public EnableLinOp<Factorization<ValueType, IndexType>> {
78
79public:
80 using value_type = ValueType;
81 using index_type = IndexType;
85
94 std::unique_ptr<Factorization> unpack() const;
95
97 storage_type get_storage_type() const;
98
103 std::shared_ptr<const matrix_type> get_lower_factor() const;
104
109 std::shared_ptr<const diag_type> get_diagonal() const;
110
115 std::shared_ptr<const matrix_type> get_upper_factor() const;
116
121 std::shared_ptr<const matrix_type> get_combined() const;
122
125
128
129 Factorization& operator=(const Factorization&);
130
131 Factorization& operator=(Factorization&&);
132
142 static std::unique_ptr<Factorization> create_from_composition(
143 std::unique_ptr<composition_type> composition);
144
155 static std::unique_ptr<Factorization> create_from_symm_composition(
156 std::unique_ptr<composition_type> composition);
157
169 static std::unique_ptr<Factorization> create_from_combined_lu(
170 std::unique_ptr<matrix_type> matrix);
171
172 static std::unique_ptr<Factorization> create_from_combined_ldu(
173 std::unique_ptr<matrix_type> matrix);
174
175 static std::unique_ptr<Factorization> create_from_combined_cholesky(
176 std::unique_ptr<matrix_type> matrix);
177
178 static std::unique_ptr<Factorization> create_from_combined_ldl(
179 std::unique_ptr<matrix_type> matrix);
180
181protected:
182 explicit Factorization(std::shared_ptr<const Executor> exec);
183
184 Factorization(std::unique_ptr<Composition<ValueType>> factors,
185 storage_type type);
186
187 void apply_impl(const LinOp* b, LinOp* x) const override;
188
189 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
190 LinOp* x) const override;
191
192private:
193 storage_type storage_type_;
194 std::unique_ptr<Composition<ValueType>> factors_;
195};
196
197
198} // namespace factorization
199} // namespace experimental
200} // namespace gko
201
202#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:41
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:880
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:663
Definition lin_op.hpp:118
Represents a generic factorization consisting of two triangular factors (upper and lower) and an opti...
Definition factorization.hpp:76
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 sparsity_csr.hpp:22
This class is a utility which efficiently implements the diagonal matrix (a linear operator which sca...
Definition diagonal.hpp:50
The Ginkgo namespace.
Definition abstract_factory.hpp:20