mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 08:34:37 +08:00
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:
@@ -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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user