Modernize ParameterBlock::Plus with std::clamp

Use std::clamp for projecting the updated parameter state onto its
box constraints. This provides a more idiomatic and concise
implementation than separate std::min/std::max loops, especially
when both lower and upper bounds are present.

Change-Id: I1f6248ed8f0313338cf9a1c98d79a023ae281e6c
This commit is contained in:
Sameer Agarwal
2026-03-23 11:48:42 -07:00
parent 87c406d9d0
commit ea4de24c2e
+7 -4
View File
@@ -236,13 +236,16 @@ class CERES_NO_EXPORT ParameterBlock {
}
// Project onto the box constraints.
if (lower_bounds_.get() != nullptr) {
if (lower_bounds_ && upper_bounds_) {
for (int i = 0; i < size_; ++i) {
x_plus_delta[i] =
std::clamp(x_plus_delta[i], lower_bounds_[i], upper_bounds_[i]);
}
} else if (lower_bounds_) {
for (int i = 0; i < size_; ++i) {
x_plus_delta[i] = std::max(x_plus_delta[i], lower_bounds_[i]);
}
}
if (upper_bounds_.get() != nullptr) {
} else if (upper_bounds_) {
for (int i = 0; i < size_; ++i) {
x_plus_delta[i] = std::min(x_plus_delta[i], upper_bounds_[i]);
}