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/utils.hpp>
14 #include <ginkgo/core/matrix/dense.hpp>
15 #include <ginkgo/core/stop/criterion.hpp>
36 enum class mode { absolute, initial_resnorm, rhs_norm };
48 template <
typename ValueType>
59 bool check_impl(
uint8 stoppingId,
bool setFinalized,
65 device_storage_{exec, 2}
70 absolute_type reduction_factor,
mode baseline);
73 std::unique_ptr<NormVector> starting_tau_{};
74 std::unique_ptr<NormVector> u_dense_tau_{};
79 mode baseline_{mode::rhs_norm};
80 std::shared_ptr<const LinOp> system_matrix_{};
81 std::shared_ptr<const LinOp> b_{};
83 std::shared_ptr<const Vector> one_{};
84 std::shared_ptr<const Vector> neg_one_{};
108 template <
typename ValueType = default_precision>
133 explicit ResidualNorm(std::shared_ptr<const gko::Executor> exec)
139 factory->get_executor(), args,
140 factory->get_parameters().reduction_factor,
141 factory->get_parameters().baseline),
142 parameters_{factory->get_parameters()}
164 template <
typename ValueType = default_precision>
192 bool check_impl(
uint8 stoppingId,
bool setFinalized,
203 factory->get_executor(), args,
204 factory->get_parameters().reduction_factor,
205 factory->get_parameters().baseline),
206 parameters_{factory->get_parameters()}
214 GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
236 template <
typename ValueType = default_precision>
237 class GKO_DEPRECATED(
238 "Please use the class
ResidualNorm with the factory parameter baseline =
"
239 "mode::initial_resnorm
") ResidualNormReduction
240 : public ResidualNormBase<ValueType> {
242 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
243 using NormVector = matrix::Dense<remove_complex<ValueType>>;
244 using Vector = matrix::Dense<ValueType>;
246 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
251 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
252 reduction_factor, static_cast<remove_complex<ValueType>>(1e-15));
254 GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
256 GKO_ENABLE_BUILD_METHOD(Factory);
259 explicit ResidualNormReduction(std::shared_ptr<const gko::Executor> exec)
260 : ResidualNormBase<ValueType>(exec)
263 explicit ResidualNormReduction(const Factory* factory,
264 const CriterionArgs& args)
265 : ResidualNormBase<ValueType>(
266 factory->get_executor(), args,
267 factory->get_parameters().reduction_factor,
268 mode::initial_resnorm),
269 parameters_{factory->get_parameters()}
292 template <typename ValueType = default_precision>
293 class GKO_DEPRECATED(
294 "Please use the
class ResidualNorm with the factory parameter baseline =
"
295 "mode::rhs_norm
") RelativeResidualNorm
296 : public ResidualNormBase<ValueType> {
298 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
299 using NormVector = matrix::Dense<remove_complex<ValueType>>;
300 using Vector = matrix::Dense<ValueType>;
302 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
307 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
308 tolerance, static_cast<remove_complex<ValueType>>(1e-15));
310 GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
312 GKO_ENABLE_BUILD_METHOD(Factory);
315 explicit RelativeResidualNorm(std::shared_ptr<const gko::Executor> exec)
316 : ResidualNormBase<ValueType>(exec)
319 explicit RelativeResidualNorm(const Factory* factory,
320 const CriterionArgs& args)
321 : ResidualNormBase<ValueType>(factory->get_executor(), args,
322 factory->get_parameters().tolerance,
324 parameters_{factory->get_parameters()}
346 template <typename ValueType = default_precision>
347 class GKO_DEPRECATED(
348 "Please use the
class ResidualNorm with the factory parameter baseline =
"
349 "mode::absolute
") AbsoluteResidualNorm
350 : public ResidualNormBase<ValueType> {
352 using NormVector = matrix::Dense<remove_complex<ValueType>>;
353 using Vector = matrix::Dense<ValueType>;
355 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
360 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
361 tolerance, static_cast<remove_complex<ValueType>>(1e-15));
363 GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
365 GKO_ENABLE_BUILD_METHOD(Factory);
368 explicit AbsoluteResidualNorm(std::shared_ptr<const gko::Executor> exec)
369 : ResidualNormBase<ValueType>(exec)
372 explicit AbsoluteResidualNorm(const Factory* factory,
373 const CriterionArgs& args)
374 : ResidualNormBase<ValueType>(factory->get_executor(), args,
375 factory->get_parameters().tolerance,
377 parameters_{factory->get_parameters()}
382 GKO_END_DISABLE_DEPRECATION_WARNINGS
389 #endif // GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_