 |
Ginkgo
Generated from pipelines/2837190956 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
|
5 #ifndef GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
6 #define GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
11 #include <ginkgo/core/base/array.hpp>
12 #include <ginkgo/core/base/math.hpp>
13 #include <ginkgo/core/base/types.hpp>
14 #include <ginkgo/core/base/utils.hpp>
15 #include <ginkgo/core/matrix/dense.hpp>
16 #include <ginkgo/core/stop/criterion.hpp>
37 enum class mode { absolute, initial_resnorm, rhs_norm };
49 template <
typename ValueType>
51 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
58 bool check_impl(
uint8 stoppingId,
bool setFinalized,
63 :
Criterion(exec), device_storage_{exec, 2}
68 absolute_type reduction_factor,
mode baseline);
71 std::unique_ptr<NormVector> starting_tau_{};
72 std::unique_ptr<NormVector> u_dense_tau_{};
77 mode baseline_{mode::rhs_norm};
78 std::shared_ptr<const LinOp> system_matrix_{};
79 std::shared_ptr<const LinOp> b_{};
81 std::shared_ptr<const Vector> one_{};
82 std::shared_ptr<const Vector> neg_one_{};
125 template <
typename ValueType = default_precision>
138 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
142 this->reduction_factor = value;
156 explicit ResidualNorm(std::shared_ptr<const gko::Executor> exec)
163 factory->get_parameters().reduction_factor,
164 factory->get_parameters().baseline),
165 parameters_{factory->get_parameters()}
207 template <
typename ValueType = default_precision>
220 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
224 this->reduction_factor = value;
241 bool check_impl(
uint8 stoppingId,
bool setFinalized,
253 factory->get_parameters().reduction_factor,
254 factory->get_parameters().baseline),
255 parameters_{factory->get_parameters()}
319 GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
341 template <
typename ValueType = default_precision>
342 class GKO_DEPRECATED(
343 "Please use the class
ResidualNorm with the factory parameter baseline =
"
344 "mode::initial_resnorm
") ResidualNormReduction
345 : public ResidualNormBase<ValueType> {
347 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
348 using NormVector = matrix::Dense<remove_complex<ValueType>>;
349 using Vector = matrix::Dense<ValueType>;
351 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
356 remove_complex<ValueType> reduction_factor{
357 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
359 parameters_type& with_reduction_factor(remove_complex<ValueType> value)
361 this->reduction_factor = value;
365 GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
367 GKO_ENABLE_BUILD_METHOD(Factory);
370 explicit ResidualNormReduction(std::shared_ptr<const gko::Executor> exec)
371 : ResidualNormBase<ValueType>(exec)
374 explicit ResidualNormReduction(const Factory* factory,
375 const CriterionArgs& args)
376 : ResidualNormBase<ValueType>(
377 factory->get_executor(), args,
378 factory->get_parameters().reduction_factor,
379 mode::initial_resnorm),
380 parameters_{factory->get_parameters()}
403 template <typename ValueType = default_precision>
404 class GKO_DEPRECATED(
405 "Please use the
class ResidualNorm with the factory parameter baseline =
"
406 "mode::rhs_norm
") RelativeResidualNorm
407 : public ResidualNormBase<ValueType> {
409 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
410 using NormVector = matrix::Dense<remove_complex<ValueType>>;
411 using Vector = matrix::Dense<ValueType>;
413 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
418 remove_complex<ValueType> tolerance{
419 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
422 parameters_type& with_tolerance(remove_complex<ValueType> value)
424 this->tolerance = value;
428 GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
430 GKO_ENABLE_BUILD_METHOD(Factory);
433 explicit RelativeResidualNorm(std::shared_ptr<const gko::Executor> exec)
434 : ResidualNormBase<ValueType>(exec)
437 explicit RelativeResidualNorm(const Factory* factory,
438 const CriterionArgs& args)
439 : ResidualNormBase<ValueType>(factory->get_executor(), args,
440 factory->get_parameters().tolerance,
442 parameters_{factory->get_parameters()}
464 template <typename ValueType = default_precision>
465 class GKO_DEPRECATED(
466 "Please use the
class ResidualNorm with the factory parameter baseline =
"
467 "mode::absolute
") AbsoluteResidualNorm
468 : public ResidualNormBase<ValueType> {
470 using NormVector = matrix::Dense<remove_complex<ValueType>>;
471 using Vector = matrix::Dense<ValueType>;
473 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
478 remove_complex<ValueType> tolerance{
479 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
481 parameters_type& with_tolerance(remove_complex<ValueType> value)
483 this->tolerance = value;
487 GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
489 GKO_ENABLE_BUILD_METHOD(Factory);
492 explicit AbsoluteResidualNorm(std::shared_ptr<const gko::Executor> exec)
493 : ResidualNormBase<ValueType>(exec)
496 explicit AbsoluteResidualNorm(const Factory* factory,
497 const CriterionArgs& args)
498 : ResidualNormBase<ValueType>(factory->get_executor(), args,
499 factory->get_parameters().tolerance,
501 parameters_{factory->get_parameters()}
506 GKO_END_DISABLE_DEPRECATION_WARNINGS
513 #endif // GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
This struct is used to pass parameters to the EnableDefaultCriterionFactoryCriterionFactory::generate...
Definition: criterion.hpp:209
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:130
Dense is a matrix format which explicitly stores all values of the matrix.
Definition: dense_cache.hpp:28
deferred_factory_parameter< CriterionFactory > initial_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
deferred_factory_parameter< CriterionFactory > absolute_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
deferred_factory_parameter< CriterionFactory > absolute_implicit_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
deferred_factory_parameter< CriterionFactory > relative_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:469
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition: array.hpp:26
Stopping criterion based on the explicit residual norm .
Definition: residual_norm.hpp:126
Definition: residual_norm.hpp:235
deferred_factory_parameter< CriterionFactory > initial_implicit_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
The Criterion class is a base class for all stopping criteria.
Definition: criterion.hpp:36
mode
The mode for the residual norm criterion.
Definition: residual_norm.hpp:37
Definition: residual_norm.hpp:152
The Updater class serves for convenient argument passing to the Criterion's check function.
Definition: criterion.hpp:59
Definition: residual_norm.hpp:132
Definition: residual_norm.hpp:214
#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:418
#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:304
Stopping criterion based on a solver-maintained squared residual-norm estimate .
Definition: residual_norm.hpp:208
The ResidualNormBase class provides a framework for stopping criteria related to the residual norm.
Definition: residual_norm.hpp:50
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:69
typename detail::remove_complex_s< T >::type remove_complex
Obtain the type which removed the complex of complex/scalar type or the template parameter of class b...
Definition: math.hpp:263
deferred_factory_parameter< CriterionFactory > relative_implicit_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....