ginkgo/core/preconditioner/isai.hpp Source File

ginkgo/core/preconditioner/isai.hpp Source File#

Reference API: ginkgo/core/preconditioner/isai.hpp Source File
Reference API
isai.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_PRECONDITIONER_ISAI_HPP_
6#define GKO_PUBLIC_CORE_PRECONDITIONER_ISAI_HPP_
7
8
9#include <memory>
10
11#include <ginkgo/core/base/composition.hpp>
12#include <ginkgo/core/base/exception_helpers.hpp>
13#include <ginkgo/core/base/executor.hpp>
14#include <ginkgo/core/base/lin_op.hpp>
15#include <ginkgo/core/config/config.hpp>
16#include <ginkgo/core/config/registry.hpp>
17#include <ginkgo/core/matrix/csr.hpp>
18#include <ginkgo/core/matrix/dense.hpp>
19
20
21namespace gko {
27namespace preconditioner {
28
29
36enum struct isai_type { lower, upper, general, spd };
37
77template <isai_type IsaiType, typename ValueType, typename IndexType>
78class Isai : public EnableLinOp<Isai<IsaiType, ValueType, IndexType>>,
79 public Transposable {
80 friend class EnableLinOp<Isai>;
81 friend class EnablePolymorphicObject<Isai, LinOp>;
82 friend class Isai<isai_type::general, ValueType, IndexType>;
83 friend class Isai<isai_type::lower, ValueType, IndexType>;
84 friend class Isai<isai_type::upper, ValueType, IndexType>;
85 friend class Isai<isai_type::spd, ValueType, IndexType>;
86
87public:
88 using value_type = ValueType;
89 using index_type = IndexType;
90 using transposed_type =
91 Isai<IsaiType == isai_type::general ? isai_type::general
92 : IsaiType == isai_type::spd ? isai_type::spd
93 : IsaiType == isai_type::lower ? isai_type::upper
94 : isai_type::lower,
95 ValueType, IndexType>;
96 using Comp = Composition<ValueType>;
97 using Csr = matrix::Csr<ValueType, IndexType>;
98 using Dense = matrix::Dense<ValueType>;
99 static constexpr isai_type type{IsaiType};
100
108 std::shared_ptr<const typename std::conditional<IsaiType == isai_type::spd,
109 Comp, Csr>::type>
111 {
112 return as<typename std::conditional<IsaiType == isai_type::spd, Comp,
113 Csr>::type>(approximate_inverse_);
114 }
115
121 Isai& operator=(const Isai& other);
122
129 Isai& operator=(Isai&& other);
130
135 Isai(const Isai& other);
136
142 Isai(Isai&& other);
143
145 {
154 bool GKO_FACTORY_PARAMETER_SCALAR(skip_sorting, false);
155
164 int GKO_FACTORY_PARAMETER_SCALAR(sparsity_power, 1);
165
178
185 std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
186 excess_solver_factory);
187
189 excess_solver_reduction,
190 static_cast<remove_complex<value_type>>(1e-6));
191 };
192
195
210 const config::pnode& config, const config::registry& context,
211 const config::type_descriptor& td_for_child =
212 config::make_type_descriptor<ValueType, IndexType>());
213
214 std::unique_ptr<LinOp> transpose() const override;
215
216 std::unique_ptr<LinOp> conj_transpose() const override;
217
218protected:
219 explicit Isai(std::shared_ptr<const Executor> exec)
220 : EnableLinOp<Isai>(std::move(exec))
221 {}
222
229 explicit Isai(const Factory* factory,
230 std::shared_ptr<const LinOp> system_matrix)
231 : EnableLinOp<Isai>(factory->get_executor(), system_matrix->get_size()),
232 parameters_{factory->get_parameters()}
233 {
234 const auto skip_sorting = parameters_.skip_sorting;
235 const auto power = parameters_.sparsity_power;
236 const auto excess_limit = parameters_.excess_limit;
237 generate_inverse(system_matrix, skip_sorting, power, excess_limit,
238 static_cast<remove_complex<value_type>>(
239 parameters_.excess_solver_reduction));
240 if (IsaiType == isai_type::spd) {
241 auto inv = share(as<Csr>(approximate_inverse_));
242 auto inv_transp = share(inv->conj_transpose());
243 approximate_inverse_ =
244 Composition<ValueType>::create(inv_transp, inv);
245 }
246 }
247
248 void apply_impl(const LinOp* b, LinOp* x) const override
249 {
250 approximate_inverse_->apply(b, x);
251 }
252
253 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
254 LinOp* x) const override
255 {
256 approximate_inverse_->apply(alpha, b, beta, x);
257 }
258
259private:
270 void generate_inverse(std::shared_ptr<const LinOp> to_invert,
271 bool skip_sorting, int power, index_type excess_limit,
272 remove_complex<value_type> excess_solver_reduction);
273
274private:
275 std::shared_ptr<LinOp> approximate_inverse_;
276};
277
278
279template <typename ValueType = default_precision, typename IndexType = int32>
280using LowerIsai = Isai<isai_type::lower, ValueType, IndexType>;
281
282template <typename ValueType = default_precision, typename IndexType = int32>
283using UpperIsai = Isai<isai_type::upper, ValueType, IndexType>;
284
285template <typename ValueType = default_precision, typename IndexType = int32>
286using GeneralIsai = Isai<isai_type::general, ValueType, IndexType>;
287
288template <typename ValueType = default_precision, typename IndexType = int32>
289using SpdIsai = Isai<isai_type::spd, ValueType, IndexType>;
290
291
292} // namespace preconditioner
293} // namespace gko
294
295
296#endif // GKO_PUBLIC_CORE_PRECONDITIONER_ISAI_HPP_
Definition composition.hpp:41
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:117
std::shared_ptr< const Executor > get_executor() const noexcept
Definition polymorphic_object.hpp:243
Definition lin_op.hpp:433
Definition property_tree.hpp:28
Definition registry.hpp:167
Definition type_descriptor.hpp:39
Definition csr.hpp:123
Definition isai.hpp:193
Definition isai.hpp:79
Isai(const Isai &other)
Isai(const Factory *factory, std::shared_ptr< const LinOp > system_matrix)
Definition isai.hpp:229
std::unique_ptr< LinOp > transpose() const override
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 >())
Isai & operator=(Isai &&other)
std::unique_ptr< LinOp > conj_transpose() const override
std::shared_ptr< const typename std::conditional< IsaiType==isai_type::spd, Comp, Csr >::type > get_approximate_inverse() const
Definition isai.hpp:110
Isai & operator=(const Isai &other)
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
Definition abstract_factory.hpp:280
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Definition abstract_factory.hpp:445
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Definition abstract_factory.hpp:394
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
Definition lin_op.hpp:1016
isai_type
Definition isai.hpp:36
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::size_t size_type
Definition types.hpp:89
std::decay_t< T > * as(U *obj)
Definition utils_helper.hpp:307
detail::shared_type< OwningPointer > share(OwningPointer &&p)
Definition utils_helper.hpp:224
typename detail::remove_complex_s< T >::type remove_complex
Definition math.hpp:260
STL namespace.
bool skip_sorting
Optimization parameter that skips the sorting of the input matrix (only skip if it is known that it i...
Definition isai.hpp:154
int sparsity_power
Which power of the input matrix should be used for the sparsity pattern.
Definition isai.hpp:164
size_type excess_limit
Size limit for the excess system.
Definition isai.hpp:177