Ginkgo  Generated from pipelines/2779843039 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
ic.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_FACTORIZATION_IC_HPP_
6 #define GKO_PUBLIC_CORE_FACTORIZATION_IC_HPP_
7 
8 
9 #include <memory>
10 
11 #include <ginkgo/core/base/composition.hpp>
12 #include <ginkgo/core/base/lin_op.hpp>
13 #include <ginkgo/core/base/types.hpp>
14 #include <ginkgo/core/config/config.hpp>
15 #include <ginkgo/core/config/registry.hpp>
16 #include <ginkgo/core/factorization/incomplete_factorization.hpp>
17 #include <ginkgo/core/matrix/csr.hpp>
18 
19 
20 namespace gko {
26 namespace factorization {
27 
28 
43 template <typename ValueType = gko::default_precision,
44  typename IndexType = gko::int32>
45 class Ic : public Composition<ValueType> {
46  GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
47 
48 public:
49  using value_type = ValueType;
50  using index_type = IndexType;
52 
53  std::shared_ptr<const matrix_type> get_l_factor() const
54  {
55  // Can be `static_cast` since the type is guaranteed in this class
56  return std::static_pointer_cast<const matrix_type>(
57  this->get_operators()[0]);
58  }
59 
60  std::shared_ptr<const matrix_type> get_lt_factor() const
61  {
62  if (this->get_operators().size() == 2) {
63  // Can be `static_cast` since the type is guaranteed in this class
64  return std::static_pointer_cast<const matrix_type>(
65  this->get_operators()[1]);
66  } else {
67  return std::static_pointer_cast<const matrix_type>(
68  share(get_l_factor()->conj_transpose()));
69  }
70  }
71 
72  // Remove the possibility of calling `create`, which was enabled by
73  // `Composition`
74  template <typename... Args>
75  static std::unique_ptr<Composition<ValueType>> create(Args&&... args) =
76  delete;
77 
79  {
84  GKO_DEPRECATED("use matrix::csr::spmv_strategy instead")
85  parameters_type& with_l_strategy(
86  std::shared_ptr<typename matrix_type::strategy_type> value)
87  {
88  if (value) {
89  this->l_strategy = value->get_enum();
90  } else {
91  this->l_strategy = matrix::csr::spmv_strategy::classical;
92  }
93  return *this;
94  }
95 
100  parameters_type& with_l_strategy(matrix::csr::spmv_strategy value)
101  {
102  this->l_strategy = value;
103  return *this;
104  }
105 
106  matrix::csr::spmv_strategy l_strategy{
107  matrix::csr::spmv_strategy::classical};
108 
119  bool GKO_FACTORY_PARAMETER_SCALAR(skip_sorting, false);
120 
126  bool GKO_FACTORY_PARAMETER_SCALAR(both_factors, true);
127 
136  algorithm, incomplete_algorithm::sparselib);
137  };
140 
154  static parameters_type parse(
155  const config::pnode& config, const config::registry& context,
156  const config::type_descriptor& td_for_child =
157  config::make_type_descriptor<ValueType, IndexType>());
158 
159 protected:
160  Ic(const Factory* factory, std::shared_ptr<const gko::LinOp> system_matrix)
161  : Composition<ValueType>{factory->get_executor()},
162  parameters_{factory->get_parameters()}
163  {
164  auto comp = generate(system_matrix, parameters_.skip_sorting,
165  parameters_.both_factors);
166  for (auto& op : comp->get_operators()) {
167  this->add_operators(op);
168  }
169  }
170 
171  std::unique_ptr<Composition<ValueType>> generate(
172  const std::shared_ptr<const LinOp>& system_matrix, bool skip_sorting,
173  bool both_factors) const;
174 };
175 
176 
177 } // namespace factorization
178 } // namespace gko
179 
180 
181 #endif // GKO_PUBLIC_CORE_FACTORIZATION_IC_HPP_
gko::matrix::Csr
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition: matrix.hpp:30
gko::config::pnode
pnode describes a tree of properties.
Definition: property_tree.hpp:28
gko::factorization::Ic
Represents an incomplete Cholesky factorization (IC(0)) of a sparse matrix.
Definition: ic.hpp:45
GKO_FACTORY_PARAMETER_SCALAR
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:437
gko::config::type_descriptor
This class describes the value and index types to be used when building a Ginkgo type from a configur...
Definition: type_descriptor.hpp:39
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::factorization::Ic::parse
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType, IndexType >())
Create the parameters from the property_tree.
gko::Composition
The Composition class can be used to compose linear operators op1, op2, ..., opn and obtain the opera...
Definition: composition.hpp:39
GKO_ENABLE_LIN_OP_FACTORY
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
This macro will generate a default implementation of a LinOpFactory for the LinOp subclass it is defi...
Definition: lin_op.hpp:900
gko::Composition::get_operators
const std::vector< std::shared_ptr< const LinOp > > & get_operators() const noexcept
Returns a list of operators of the composition.
Definition: composition.hpp:54
gko::share
detail::shared_type< OwningPointer > share(OwningPointer &&p)
Marks the object pointed to by p as shared.
Definition: utils_helper.hpp:174
gko::factorization::Ic::parameters_type::both_factors
bool both_factors
true will generate both L and L^H, false will only generate the L factor, resulting in a Composition ...
Definition: ic.hpp:126
gko::factorization::Ic::parameters_type::with_l_strategy
parameters_type & with_l_strategy(matrix::csr::spmv_strategy value)
Strategy which will be used by the L matrix.
Definition: ic.hpp:100
gko::factorization::Ic::parameters_type
Definition: ic.hpp:78
gko::factorization::Ic::parameters_type::skip_sorting
bool skip_sorting
The system_matrix, which will be given to this factory, must be sorted (first by row,...
Definition: ic.hpp:119
gko::default_precision
double default_precision
Precision used if no precision is explicitly specified.
Definition: types.hpp:183
gko::int32
std::int32_t int32
32-bit signed integral type.
Definition: types.hpp:118
gko::config::registry
This class stores additional context for creating Ginkgo objects from configuration files.
Definition: registry.hpp:167
gko::factorization::Ic::Factory
Definition: ic.hpp:138
GKO_ENABLE_BUILD_METHOD
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Defines a build method for the factory, simplifying its construction by removing the repetitive typin...
Definition: abstract_factory.hpp:386
GKO_CREATE_FACTORY_PARAMETERS
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
This Macro will generate a new type containing the parameters for the factory _factory_name.
Definition: abstract_factory.hpp:272
gko::Composition::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::factorization::incomplete_algorithm
incomplete_algorithm
An enum class for algorithm selection in the incomplete factorization.
Definition: incomplete_factorization.hpp:19