Ginkgo  Generated from pipelines/1574056115 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
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 
16 namespace gko {
17 namespace experimental {
18 namespace factorization {
19 
20 
25 enum 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 
75 template <typename ValueType, typename IndexType>
76 class Factorization : public EnableLinOp<Factorization<ValueType, IndexType>> {
78 
79 public:
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 
181 protected:
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 
192 private:
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_
gko::experimental::factorization::Factorization
Represents a generic factorization consisting of two triangular factors (upper and lower) and an opti...
Definition: factorization.hpp:76
gko::matrix::Csr
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition: matrix.hpp:28
gko::LinOp
Definition: lin_op.hpp:117
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_combined
std::shared_ptr< const matrix_type > get_combined() const
Returns the matrix storing a compact representation of the factorization, if available,...
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
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::Composition
The Composition class can be used to compose linear operators op1, op2, ..., opn and obtain the opera...
Definition: composition.hpp:39
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::matrix::Diagonal
This class is a utility which efficiently implements the diagonal matrix (a linear operator which sca...
Definition: lin_op.hpp:31
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::Factorization
Factorization(const Factorization &)
Creates a deep copy of the factorization.
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::EnableLinOp
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:877
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::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:661
gko::experimental::factorization::Factorization::get_storage_type
storage_type get_storage_type() const
Returns the storage type used by this factorization.