diff options
Diffstat (limited to 'extern/ceres/internal/ceres/trust_region_step_evaluator.cc')
-rw-r--r-- | extern/ceres/internal/ceres/trust_region_step_evaluator.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/extern/ceres/internal/ceres/trust_region_step_evaluator.cc b/extern/ceres/internal/ceres/trust_region_step_evaluator.cc index c9167e623ef..33b0c41ead6 100644 --- a/extern/ceres/internal/ceres/trust_region_step_evaluator.cc +++ b/extern/ceres/internal/ceres/trust_region_step_evaluator.cc @@ -29,6 +29,7 @@ // Author: sameeragarwal@google.com (Sameer Agarwal) #include <algorithm> +#include <limits> #include "ceres/trust_region_step_evaluator.h" #include "glog/logging.h" @@ -51,6 +52,15 @@ TrustRegionStepEvaluator::TrustRegionStepEvaluator( double TrustRegionStepEvaluator::StepQuality( const double cost, const double model_cost_change) const { + // If the function evaluation for this step was a failure, in which + // case the TrustRegionMinimizer would have set the cost to + // std::numeric_limits<double>::max(). In this case, the division by + // model_cost_change can result in an overflow. To prevent that from + // happening, we will deal with this case explicitly. + if (cost >= std::numeric_limits<double>::max()) { + return std::numeric_limits<double>::lowest(); + } + const double relative_decrease = (current_cost_ - cost) / model_cost_change; const double historical_relative_decrease = (reference_cost_ - cost) / |