5 #ifndef GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
6 #define GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
10 #include <type_traits>
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>
38 enum class mode { absolute, initial_resnorm, rhs_norm };
50 template <
typename ValueType>
61 bool check_impl(
uint8 stoppingId,
bool setFinalized,
67 device_storage_{exec, 2}
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_{};
112 template <
typename ValueType = default_precision>
138 explicit ResidualNorm(std::shared_ptr<const gko::Executor> exec)
144 factory->get_executor(), args,
145 factory->get_parameters().reduction_factor,
146 factory->get_parameters().baseline),
147 parameters_{factory->get_parameters()}
169 template <
typename ValueType = default_precision>
198 bool check_impl(
uint8 stoppingId,
bool setFinalized,
209 factory->get_executor(), args,
210 factory->get_parameters().reduction_factor,
211 factory->get_parameters().baseline),
212 parameters_{factory->get_parameters()}
220 GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
242 template <
typename ValueType = default_precision>
243 class GKO_DEPRECATED(
244 "Please use the class
ResidualNorm with the factory parameter baseline =
"
245 "mode::initial_resnorm
") ResidualNormReduction
246 : public ResidualNormBase<ValueType> {
248 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
249 using NormVector = matrix::Dense<remove_complex<ValueType>>;
250 using Vector = matrix::Dense<ValueType>;
252 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
257 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
259 5 * std::numeric_limits<remove_complex<ValueType>>::epsilon());
261 GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
263 GKO_ENABLE_BUILD_METHOD(Factory);
266 explicit ResidualNormReduction(std::shared_ptr<const gko::Executor> exec)
267 : ResidualNormBase<ValueType>(exec)
270 explicit ResidualNormReduction(const Factory* factory,
271 const CriterionArgs& args)
272 : ResidualNormBase<ValueType>(
273 factory->get_executor(), args,
274 factory->get_parameters().reduction_factor,
275 mode::initial_resnorm),
276 parameters_{factory->get_parameters()}
299 template <typename ValueType = default_precision>
300 class GKO_DEPRECATED(
301 "Please use the
class ResidualNorm with the factory parameter baseline =
"
302 "mode::rhs_norm
") RelativeResidualNorm
303 : public ResidualNormBase<ValueType> {
305 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
306 using NormVector = matrix::Dense<remove_complex<ValueType>>;
307 using Vector = matrix::Dense<ValueType>;
309 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
314 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
316 5 * std::numeric_limits<remove_complex<ValueType>>::epsilon());
318 GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
320 GKO_ENABLE_BUILD_METHOD(Factory);
323 explicit RelativeResidualNorm(std::shared_ptr<const gko::Executor> exec)
324 : ResidualNormBase<ValueType>(exec)
327 explicit RelativeResidualNorm(const Factory* factory,
328 const CriterionArgs& args)
329 : ResidualNormBase<ValueType>(factory->get_executor(), args,
330 factory->get_parameters().tolerance,
332 parameters_{factory->get_parameters()}
354 template <typename ValueType = default_precision>
355 class GKO_DEPRECATED(
356 "Please use the
class ResidualNorm with the factory parameter baseline =
"
357 "mode::absolute
") AbsoluteResidualNorm
358 : public ResidualNormBase<ValueType> {
360 using NormVector = matrix::Dense<remove_complex<ValueType>>;
361 using Vector = matrix::Dense<ValueType>;
363 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
368 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
370 5 * std::numeric_limits<remove_complex<ValueType>>::epsilon());
372 GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
374 GKO_ENABLE_BUILD_METHOD(Factory);
377 explicit AbsoluteResidualNorm(std::shared_ptr<const gko::Executor> exec)
378 : ResidualNormBase<ValueType>(exec)
381 explicit AbsoluteResidualNorm(const Factory* factory,
382 const CriterionArgs& args)
383 : ResidualNormBase<ValueType>(factory->get_executor(), args,
384 factory->get_parameters().tolerance,
386 parameters_{factory->get_parameters()}
391 GKO_END_DISABLE_DEPRECATION_WARNINGS
398 #endif // GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_