5#ifndef GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
6#define GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
12#include <ginkgo/core/base/array.hpp>
13#include <ginkgo/core/base/math.hpp>
14#include <ginkgo/core/base/types.hpp>
15#include <ginkgo/core/base/utils.hpp>
16#include <ginkgo/core/matrix/dense.hpp>
17#include <ginkgo/core/stop/criterion.hpp>
38enum class mode { absolute, initial_resnorm, rhs_norm };
50template <
typename ValueType>
61 bool check_impl(
uint8 stoppingId,
bool setFinalized,
65 explicit ResidualNormBase(std::shared_ptr<const gko::Executor> exec)
67 device_storage_{exec, 2}
70 explicit ResidualNormBase(std::shared_ptr<const gko::Executor> exec,
72 absolute_type reduction_factor,
mode baseline);
75 std::unique_ptr<NormVector> starting_tau_{};
76 std::unique_ptr<NormVector> u_dense_tau_{};
81 mode baseline_{mode::rhs_norm};
82 std::shared_ptr<const LinOp> system_matrix_{};
83 std::shared_ptr<const LinOp> b_{};
85 std::shared_ptr<const Vector> one_{};
86 std::shared_ptr<const Vector> neg_one_{};
112template <
typename ValueType = default_precision>
113class ResidualNorm :
public ResidualNormBase<ValueType> {
134 GKO_ENABLE_CRITERION_FACTORY(ResidualNorm<ValueType>, parameters, Factory);
138 explicit ResidualNorm(std::shared_ptr<const gko::Executor> exec)
139 : ResidualNormBase<ValueType>(exec)
143 : ResidualNormBase<ValueType>(
144 factory->get_executor(), args,
145 factory->get_parameters().reduction_factor,
146 factory->get_parameters().baseline),
147 parameters_{factory->get_parameters()}
169template <
typename ValueType = default_precision>
170class ImplicitResidualNorm :
public ResidualNormBase<ValueType> {
191 GKO_ENABLE_CRITERION_FACTORY(ImplicitResidualNorm<ValueType>, parameters,
198 bool check_impl(
uint8 stoppingId,
bool setFinalized,
202 explicit ImplicitResidualNorm(std::shared_ptr<const gko::Executor> exec)
203 : ResidualNormBase<ValueType>(exec)
206 explicit ImplicitResidualNorm(
const Factory* factory,
208 : ResidualNormBase<ValueType>(
209 factory->get_executor(), args,
210 factory->get_parameters().reduction_factor,
211 factory->get_parameters().baseline),
212 parameters_{factory->get_parameters()}
220GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
242template <
typename ValueType = default_precision>
244 "Please use the class ResidualNorm with the factory parameter baseline = "
245 "mode::initial_resnorm") ResidualNormReduction
246 :
public ResidualNormBase<ValueType> {
261 GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
266 explicit ResidualNormReduction(std::shared_ptr<const gko::Executor> exec)
267 : ResidualNormBase<ValueType>(exec)
270 explicit ResidualNormReduction(
const Factory* factory,
272 : ResidualNormBase<ValueType>(
273 factory->get_executor(), args,
274 factory->get_parameters().reduction_factor,
275 mode::initial_resnorm),
276 parameters_{factory->get_parameters()}
299template <
typename ValueType = default_precision>
301 "Please use the class ResidualNorm with the factory parameter baseline = "
302 "mode::rhs_norm") RelativeResidualNorm
303 :
public ResidualNormBase<ValueType> {
318 GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
323 explicit RelativeResidualNorm(std::shared_ptr<const gko::Executor> exec)
324 : ResidualNormBase<ValueType>(exec)
327 explicit RelativeResidualNorm(
const Factory* factory,
329 : ResidualNormBase<ValueType>(factory->get_executor(), args,
330 factory->get_parameters().tolerance,
332 parameters_{factory->get_parameters()}
354template <
typename ValueType = default_precision>
356 "Please use the class ResidualNorm with the factory parameter baseline = "
357 "mode::absolute") AbsoluteResidualNorm
358 :
public ResidualNormBase<ValueType> {
372 GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
377 explicit AbsoluteResidualNorm(std::shared_ptr<const gko::Executor> exec)
378 : ResidualNormBase<ValueType>(exec)
381 explicit AbsoluteResidualNorm(
const Factory* factory,
383 : ResidualNormBase<ValueType>(factory->get_executor(), args,
384 factory->get_parameters().tolerance,
386 parameters_{factory->get_parameters()}
391GKO_END_DISABLE_DEPRECATION_WARNINGS
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:120
Definition residual_norm.hpp:373
The Updater class serves for convenient argument passing to the Criterion's check function.
Definition criterion.hpp:55
The Criterion class is a base class for all stopping criteria.
Definition criterion.hpp:36
Definition residual_norm.hpp:192
Definition residual_norm.hpp:319
Definition residual_norm.hpp:262
Definition residual_norm.hpp:134
#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:280
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition abstract_factory.hpp:445
#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:394
mode
The mode for the residual norm criterion.
Definition residual_norm.hpp:38
The Stopping criterion namespace.
Definition logger.hpp:50
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:119
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
remove_complex< ValueType > tolerance
Absolute residual norm goal.
Definition residual_norm.hpp:370
This struct is used to pass parameters to the EnableDefaultCriterionFactoryCriterionFactory::generate...
Definition criterion.hpp:205
remove_complex< ValueType > reduction_factor
Implicit Residual norm goal.
Definition residual_norm.hpp:183
mode baseline
The quantity the reduction is relative to.
Definition residual_norm.hpp:189
remove_complex< ValueType > tolerance
Relative residual norm goal.
Definition residual_norm.hpp:316
remove_complex< ValueType > reduction_factor
Factor by which the residual norm will be reduced.
Definition residual_norm.hpp:259
remove_complex< ValueType > reduction_factor
Residual norm reduction factor.
Definition residual_norm.hpp:126
mode baseline
The quantity the reduction is relative to.
Definition residual_norm.hpp:132