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_{};
110 template <
typename ValueType = default_precision>
135 explicit ResidualNorm(std::shared_ptr<const gko::Executor> exec)
141 factory->get_executor(), args,
142 factory->get_parameters().reduction_factor,
143 factory->get_parameters().baseline),
144 parameters_{factory->get_parameters()}
166 template <
typename ValueType = default_precision>
194 bool check_impl(
uint8 stoppingId,
bool setFinalized,
205 factory->get_executor(), args,
206 factory->get_parameters().reduction_factor,
207 factory->get_parameters().baseline),
208 parameters_{factory->get_parameters()}
216 GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
238 template <
typename ValueType = default_precision>
239 class GKO_DEPRECATED(
240 "Please use the class
ResidualNorm with the factory parameter baseline =
"
241 "mode::initial_resnorm
") ResidualNormReduction
242 : public ResidualNormBase<ValueType> {
244 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
245 using NormVector = matrix::Dense<remove_complex<ValueType>>;
246 using Vector = matrix::Dense<ValueType>;
248 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
253 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
254 reduction_factor, static_cast<remove_complex<ValueType>>(1e-15));
256 GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
258 GKO_ENABLE_BUILD_METHOD(Factory);
261 explicit ResidualNormReduction(std::shared_ptr<const gko::Executor> exec)
262 : ResidualNormBase<ValueType>(exec)
265 explicit ResidualNormReduction(const Factory* factory,
266 const CriterionArgs& args)
267 : ResidualNormBase<ValueType>(
268 factory->get_executor(), args,
269 factory->get_parameters().reduction_factor,
270 mode::initial_resnorm),
271 parameters_{factory->get_parameters()}
294 template <typename ValueType = default_precision>
295 class GKO_DEPRECATED(
296 "Please use the
class ResidualNorm with the factory parameter baseline =
"
297 "mode::rhs_norm
") RelativeResidualNorm
298 : public ResidualNormBase<ValueType> {
300 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
301 using NormVector = matrix::Dense<remove_complex<ValueType>>;
302 using Vector = matrix::Dense<ValueType>;
304 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
309 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
310 tolerance, static_cast<remove_complex<ValueType>>(1e-15));
312 GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
314 GKO_ENABLE_BUILD_METHOD(Factory);
317 explicit RelativeResidualNorm(std::shared_ptr<const gko::Executor> exec)
318 : ResidualNormBase<ValueType>(exec)
321 explicit RelativeResidualNorm(const Factory* factory,
322 const CriterionArgs& args)
323 : ResidualNormBase<ValueType>(factory->get_executor(), args,
324 factory->get_parameters().tolerance,
326 parameters_{factory->get_parameters()}
348 template <typename ValueType = default_precision>
349 class GKO_DEPRECATED(
350 "Please use the
class ResidualNorm with the factory parameter baseline =
"
351 "mode::absolute
") AbsoluteResidualNorm
352 : public ResidualNormBase<ValueType> {
354 using NormVector = matrix::Dense<remove_complex<ValueType>>;
355 using Vector = matrix::Dense<ValueType>;
357 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
362 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
363 tolerance, static_cast<remove_complex<ValueType>>(1e-15));
365 GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
367 GKO_ENABLE_BUILD_METHOD(Factory);
370 explicit AbsoluteResidualNorm(std::shared_ptr<const gko::Executor> exec)
371 : ResidualNormBase<ValueType>(exec)
374 explicit AbsoluteResidualNorm(const Factory* factory,
375 const CriterionArgs& args)
376 : ResidualNormBase<ValueType>(factory->get_executor(), args,
377 factory->get_parameters().tolerance,
379 parameters_{factory->get_parameters()}
384 GKO_END_DISABLE_DEPRECATION_WARNINGS
391 #endif // GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_