Skip to content

Commit f4c2992

Browse files
authored
Merge relaxed type requirements for stopping criterion parameters
Previously we had to use with_iterations(1u) or with_iterations(static_cast<unsigned>(count)) to avoid build failures with integer iteration counts, now this is turned into conversion warnings only. Related PR: #1941
2 parents a0bc79b + e8cfcc1 commit f4c2992

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

include/ginkgo/core/stop/iteration.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -30,7 +30,13 @@ class Iteration : public EnablePolymorphicObject<Iteration, Criterion> {
3030
/**
3131
* Maximum number of iterations
3232
*/
33-
size_type GKO_FACTORY_PARAMETER_SCALAR(max_iters, 0);
33+
size_type max_iters{0};
34+
35+
parameters_type& with_max_iters(size_type value)
36+
{
37+
this->max_iters = value;
38+
return *this;
39+
}
3440
};
3541
GKO_ENABLE_CRITERION_FACTORY(Iteration, parameters, Factory);
3642
GKO_ENABLE_BUILD_METHOD(Factory);

include/ginkgo/core/stop/residual_norm.hpp

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -7,7 +7,6 @@
77

88

99
#include <limits>
10-
#include <type_traits>
1110

1211
#include <ginkgo/core/base/array.hpp>
1312
#include <ginkgo/core/base/math.hpp>
@@ -121,9 +120,14 @@ class ResidualNorm : public ResidualNormBase<ValueType> {
121120
/**
122121
* Residual norm reduction factor
123122
*/
124-
remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
125-
reduction_factor,
126-
5 * std::numeric_limits<remove_complex<ValueType>>::epsilon());
123+
remove_complex<ValueType> reduction_factor{
124+
5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
125+
126+
parameters_type& with_reduction_factor(remove_complex<ValueType> value)
127+
{
128+
this->reduction_factor = value;
129+
return *this;
130+
}
127131

128132
/**
129133
* The quantity the reduction is relative to. Choices include
@@ -178,9 +182,14 @@ class ImplicitResidualNorm : public ResidualNormBase<ValueType> {
178182
/**
179183
* Implicit Residual norm goal
180184
*/
181-
remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
182-
reduction_factor,
183-
5 * std::numeric_limits<remove_complex<ValueType>>::epsilon());
185+
remove_complex<ValueType> reduction_factor{
186+
5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
187+
188+
parameters_type& with_reduction_factor(remove_complex<ValueType> value)
189+
{
190+
this->reduction_factor = value;
191+
return *this;
192+
}
184193

185194
/**
186195
* The quantity the reduction is relative to. Choices include
@@ -254,9 +263,14 @@ class GKO_DEPRECATED(
254263
/**
255264
* Factor by which the residual norm will be reduced
256265
*/
257-
remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
258-
reduction_factor,
259-
5 * std::numeric_limits<remove_complex<ValueType>>::epsilon());
266+
remove_complex<ValueType> reduction_factor{
267+
5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
268+
269+
parameters_type& with_reduction_factor(remove_complex<ValueType> value)
270+
{
271+
this->reduction_factor = value;
272+
return *this;
273+
}
260274
};
261275
GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
262276
Factory);
@@ -311,9 +325,15 @@ class GKO_DEPRECATED(
311325
/**
312326
* Relative residual norm goal
313327
*/
314-
remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
315-
tolerance,
316-
5 * std::numeric_limits<remove_complex<ValueType>>::epsilon());
328+
remove_complex<ValueType> tolerance{
329+
5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
330+
331+
332+
parameters_type& with_tolerance(remove_complex<ValueType> value)
333+
{
334+
this->tolerance = value;
335+
return *this;
336+
}
317337
};
318338
GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
319339
Factory);
@@ -365,9 +385,14 @@ class GKO_DEPRECATED(
365385
/**
366386
* Absolute residual norm goal
367387
*/
368-
remove_complex<ValueType> GKO_FACTORY_PARAMETER_SCALAR(
369-
tolerance,
370-
5 * std::numeric_limits<remove_complex<ValueType>>::epsilon());
388+
remove_complex<ValueType> tolerance{
389+
5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
390+
391+
parameters_type& with_tolerance(remove_complex<ValueType> value)
392+
{
393+
this->tolerance = value;
394+
return *this;
395+
}
371396
};
372397
GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
373398
Factory);

0 commit comments

Comments
 (0)