 |
Ginkgo
Generated from pipelines/2662685947 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_{};
108 template <
typename ValueType = default_precision>
121 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
125 this->reduction_factor = value;
139 explicit ResidualNorm(std::shared_ptr<const gko::Executor> exec)
146 factory->get_parameters().reduction_factor,
147 factory->get_parameters().baseline),
148 parameters_{factory->get_parameters()}
170 template <
typename ValueType = default_precision>
183 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
187 this->reduction_factor = value;
204 bool check_impl(
uint8 stoppingId,
bool setFinalized,
216 factory->get_parameters().reduction_factor,
217 factory->get_parameters().baseline),
218 parameters_{factory->get_parameters()}
281 GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
303 template <
typename ValueType = default_precision>
304 class GKO_DEPRECATED(
305 "Please use the class
ResidualNorm with the factory parameter baseline =
"
306 "mode::initial_resnorm
") ResidualNormReduction
307 : public ResidualNormBase<ValueType> {
309 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
310 using NormVector = matrix::Dense<remove_complex<ValueType>>;
311 using Vector = matrix::Dense<ValueType>;
313 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
318 remove_complex<ValueType> reduction_factor{
319 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
321 parameters_type& with_reduction_factor(remove_complex<ValueType> value)
323 this->reduction_factor = value;
327 GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
329 GKO_ENABLE_BUILD_METHOD(Factory);
332 explicit ResidualNormReduction(std::shared_ptr<const gko::Executor> exec)
333 : ResidualNormBase<ValueType>(exec)
336 explicit ResidualNormReduction(const Factory* factory,
337 const CriterionArgs& args)
338 : ResidualNormBase<ValueType>(
339 factory->get_executor(), args,
340 factory->get_parameters().reduction_factor,
341 mode::initial_resnorm),
342 parameters_{factory->get_parameters()}
365 template <typename ValueType = default_precision>
366 class GKO_DEPRECATED(
367 "Please use the
class ResidualNorm with the factory parameter baseline =
"
368 "mode::rhs_norm
") RelativeResidualNorm
369 : public ResidualNormBase<ValueType> {
371 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
372 using NormVector = matrix::Dense<remove_complex<ValueType>>;
373 using Vector = matrix::Dense<ValueType>;
375 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
380 remove_complex<ValueType> tolerance{
381 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
384 parameters_type& with_tolerance(remove_complex<ValueType> value)
386 this->tolerance = value;
390 GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
392 GKO_ENABLE_BUILD_METHOD(Factory);
395 explicit RelativeResidualNorm(std::shared_ptr<const gko::Executor> exec)
396 : ResidualNormBase<ValueType>(exec)
399 explicit RelativeResidualNorm(const Factory* factory,
400 const CriterionArgs& args)
401 : ResidualNormBase<ValueType>(factory->get_executor(), args,
402 factory->get_parameters().tolerance,
404 parameters_{factory->get_parameters()}
426 template <typename ValueType = default_precision>
427 class GKO_DEPRECATED(
428 "Please use the
class ResidualNorm with the factory parameter baseline =
"
429 "mode::absolute
") AbsoluteResidualNorm
430 : public ResidualNormBase<ValueType> {
432 using NormVector = matrix::Dense<remove_complex<ValueType>>;
433 using Vector = matrix::Dense<ValueType>;
435 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
440 remove_complex<ValueType> tolerance{
441 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
443 parameters_type& with_tolerance(remove_complex<ValueType> value)
445 this->tolerance = value;
449 GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
451 GKO_ENABLE_BUILD_METHOD(Factory);
454 explicit AbsoluteResidualNorm(std::shared_ptr<const gko::Executor> exec)
455 : ResidualNormBase<ValueType>(exec)
458 explicit AbsoluteResidualNorm(const Factory* factory,
459 const CriterionArgs& args)
460 : ResidualNormBase<ValueType>(factory->get_executor(), args,
461 factory->get_parameters().tolerance,
463 parameters_{factory->get_parameters()}
468 GKO_END_DISABLE_DEPRECATION_WARNINGS
475 #endif // GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
This struct is used to pass parameters to the EnableDefaultCriterionFactoryCriterionFactory::generate...
Definition: criterion.hpp:205
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:119
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:437
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition: array.hpp:26
The ResidualNorm class is a stopping criterion which stops the iteration process when the actual resi...
Definition: residual_norm.hpp:109
Definition: residual_norm.hpp:198
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:135
The Updater class serves for convenient argument passing to the Criterion's check function.
Definition: criterion.hpp:55
Definition: residual_norm.hpp:115
Definition: residual_norm.hpp:177
#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
#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
The ImplicitResidualNorm class is a stopping criterion which stops the iteration process when the imp...
Definition: residual_norm.hpp:171
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:62
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:264
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 ....