Ginkgo: ginkgo/core/factorization/factorization.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
factorization.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 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>
76 class Factorization : public EnableLinOp<Factorization<ValueType, IndexType>> {
77 friend class EnablePolymorphicObject<Factorization, LinOp>;
78 GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
79
80public:
81 using value_type = ValueType;
82 using index_type = IndexType;
83 using matrix_type = matrix::Csr<ValueType, IndexType>;
84 using diag_type = matrix::Diagonal<ValueType>;
85 using composition_type = Composition<ValueType>;
86
95 std::unique_ptr<Factorization> unpack() const;
96
98 storage_type get_storage_type() const;
99
104 std::shared_ptr<const matrix_type> get_lower_factor() const;
105
110 std::shared_ptr<const diag_type> get_diagonal() const;
111
116 std::shared_ptr<const matrix_type> get_upper_factor() const;
117
122 std::shared_ptr<const matrix_type> get_combined() const;
123
125 Factorization(const Factorization&);
126
128 Factorization(Factorization&&);
129
130 Factorization& operator=(const Factorization&);
131
132 Factorization& operator=(Factorization&&);
133
143 static std::unique_ptr<Factorization> create_from_composition(
144 std::unique_ptr<composition_type> composition);
145
156 static std::unique_ptr<Factorization> create_from_symm_composition(
157 std::unique_ptr<composition_type> composition);
158
170 static std::unique_ptr<Factorization> create_from_combined_lu(
171 std::unique_ptr<matrix_type> matrix);
172
173 static std::unique_ptr<Factorization> create_from_combined_ldu(
174 std::unique_ptr<matrix_type> matrix);
175
176 static std::unique_ptr<Factorization> create_from_combined_cholesky(
177 std::unique_ptr<matrix_type> matrix);
178
179 static std::unique_ptr<Factorization> create_from_combined_ldl(
180 std::unique_ptr<matrix_type> matrix);
181
182protected:
183 explicit Factorization(std::shared_ptr<const Executor> exec);
184
185 Factorization(std::unique_ptr<Composition<ValueType>> factors,
186 storage_type type);
187
188 void apply_impl(const LinOp* b, LinOp* x) const override;
189
190 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
191 LinOp* x) const override;
192
193private:
194 storage_type storage_type_;
195 std::unique_ptr<Composition<ValueType>> factors_;
196};
197
198
199} // namespace factorization
200} // namespace experimental
201} // namespace gko
202
203#endif // GKO_PUBLIC_CORE_FACTORIZATION_FACTORIZATION_HPP_
gko::Composition
The Composition class can be used to compose linear operators op1, op2, ..., opn and obtain the opera...
Definition composition.hpp:41
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::experimental::factorization::Factorization::get_lower_factor
std::shared_ptr< const matrix_type > get_lower_factor() const
Returns the lower triangular factor of the factorization, if available, nullptr otherwise.
gko::experimental::factorization::Factorization::get_diagonal
std::shared_ptr< const diag_type > get_diagonal() const
Returns the diagonal scaling matrix of the factorization, if available, nullptr otherwise.
gko::experimental::factorization::Factorization::create_from_composition
static std::unique_ptr< Factorization > create_from_composition(std::unique_ptr< composition_type > composition)
Creates a Factorization from an existing composition.
gko::experimental::factorization::Factorization::get_upper_factor
std::shared_ptr< const matrix_type > get_upper_factor() const
Returns the upper triangular factor of the factorization, if available, nullptr otherwise.
gko::experimental::factorization::Factorization::get_storage_type
storage_type get_storage_type() const
Returns the storage type used by this factorization.
gko::experimental::factorization::Factorization::Factorization
Factorization(const Factorization &)
Creates a deep copy of the factorization.
gko::experimental::factorization::Factorization::create_from_symm_composition
static std::unique_ptr< Factorization > create_from_symm_composition(std::unique_ptr< composition_type > composition)
Creates a Factorization from an existing symmetric composition.
gko::experimental::factorization::Factorization::get_combined
std::shared_ptr< const matrix_type > get_combined() const
Returns the matrix storing a compact representation of the factorization, if available,...
gko::experimental::factorization::Factorization::unpack
std::unique_ptr< Factorization > unpack() const
Transforms the factorization from a compact representation suitable only for triangular solves to a c...
gko::experimental::factorization::Factorization::create_from_combined_lu
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.
gko::experimental::factorization::Factorization::Factorization
Factorization(Factorization &&)
Moves from the given factorization, leaving it empty.
gko::matrix::Csr
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition csr.hpp:126
gko::matrix::Diagonal
This class is a utility which efficiently implements the diagonal matrix (a linear operator which sca...
Definition diagonal.hpp:56
gko::matrix
The matrix namespace.
Definition dense_cache.hpp:24
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20