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/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>
60 bool check_impl(
uint8 stoppingId,
bool setFinalized,
66 device_storage_{exec, 2}
71 absolute_type reduction_factor,
mode baseline);
74 std::unique_ptr<NormVector> starting_tau_{};
75 std::unique_ptr<NormVector> u_dense_tau_{};
80 mode baseline_{mode::rhs_norm};
81 std::shared_ptr<const LinOp> system_matrix_{};
82 std::shared_ptr<const LinOp> b_{};
84 std::shared_ptr<const Vector> one_{};
85 std::shared_ptr<const Vector> neg_one_{};
109 template <
typename ValueType = default_precision>
134 explicit ResidualNorm(std::shared_ptr<const gko::Executor> exec)
140 factory->get_executor(), args,
141 factory->get_parameters().reduction_factor,
142 factory->get_parameters().baseline),
143 parameters_{factory->get_parameters()}
165 template <
typename ValueType = default_precision>
193 bool check_impl(
uint8 stoppingId,
bool setFinalized,
204 factory->get_executor(), args,
205 factory->get_parameters().reduction_factor,
206 factory->get_parameters().baseline),
207 parameters_{factory->get_parameters()}
215 GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
237 template <
typename ValueType = default_precision>
238 class GKO_DEPRECATED(
239 "Please use the class
ResidualNorm with the factory parameter baseline =
"
240 "mode::initial_resnorm
") ResidualNormReduction
241 : public ResidualNormBase<ValueType> {
243 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
244 using NormVector = matrix::Dense<remove_complex<ValueType>>;
245 using Vector = matrix::Dense<ValueType>;
247 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
252 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
253 reduction_factor, static_cast<remove_complex<ValueType>>(1e-15));
255 GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
257 GKO_ENABLE_BUILD_METHOD(Factory);
260 explicit ResidualNormReduction(std::shared_ptr<const gko::Executor> exec)
261 : ResidualNormBase<ValueType>(exec)
264 explicit ResidualNormReduction(const Factory* factory,
265 const CriterionArgs& args)
266 : ResidualNormBase<ValueType>(
267 factory->get_executor(), args,
268 factory->get_parameters().reduction_factor,
269 mode::initial_resnorm),
270 parameters_{factory->get_parameters()}
293 template <typename ValueType = default_precision>
294 class GKO_DEPRECATED(
295 "Please use the
class ResidualNorm with the factory parameter baseline =
"
296 "mode::rhs_norm
") RelativeResidualNorm
297 : public ResidualNormBase<ValueType> {
299 using ComplexVector = matrix::Dense<to_complex<ValueType>>;
300 using NormVector = matrix::Dense<remove_complex<ValueType>>;
301 using Vector = matrix::Dense<ValueType>;
303 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
308 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
309 tolerance, static_cast<remove_complex<ValueType>>(1e-15));
311 GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
313 GKO_ENABLE_BUILD_METHOD(Factory);
316 explicit RelativeResidualNorm(std::shared_ptr<const gko::Executor> exec)
317 : ResidualNormBase<ValueType>(exec)
320 explicit RelativeResidualNorm(const Factory* factory,
321 const CriterionArgs& args)
322 : ResidualNormBase<ValueType>(factory->get_executor(), args,
323 factory->get_parameters().tolerance,
325 parameters_{factory->get_parameters()}
347 template <typename ValueType = default_precision>
348 class GKO_DEPRECATED(
349 "Please use the
class ResidualNorm with the factory parameter baseline =
"
350 "mode::absolute
") AbsoluteResidualNorm
351 : public ResidualNormBase<ValueType> {
353 using NormVector = matrix::Dense<remove_complex<ValueType>>;
354 using Vector = matrix::Dense<ValueType>;
356 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
361 remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
362 tolerance, static_cast<remove_complex<ValueType>>(1e-15));
364 GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
366 GKO_ENABLE_BUILD_METHOD(Factory);
369 explicit AbsoluteResidualNorm(std::shared_ptr<const gko::Executor> exec)
370 : ResidualNormBase<ValueType>(exec)
373 explicit AbsoluteResidualNorm(const Factory* factory,
374 const CriterionArgs& args)
375 : ResidualNormBase<ValueType>(factory->get_executor(), args,
376 factory->get_parameters().tolerance,
378 parameters_{factory->get_parameters()}
383 GKO_END_DISABLE_DEPRECATION_WARNINGS
390 #endif // GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_