Refactor the array validation routines into their own file, as they are used by
more than just the residual block evaluation routines now.
Check the step computed by the linear solver for finiteness, and terminate early
if it is not. This will prevent bugs where the solver continues to run after
encountering an nan.
diff --git a/internal/ceres/residual_block_utils.cc b/internal/ceres/residual_block_utils.cc
index ed3499b..395f469 100644
--- a/internal/ceres/residual_block_utils.cc
+++ b/internal/ceres/residual_block_utils.cc
@@ -34,6 +34,7 @@
#include <cstddef>
#include <limits>
#include <glog/logging.h>
+#include "ceres/array_utils.h"
#include "ceres/residual_block.h"
#include "ceres/parameter_block.h"
#include "ceres/stringprintf.h"
@@ -43,32 +44,6 @@
namespace ceres {
namespace internal {
-// It is a near impossibility that user code generates this exact
-// value in normal operation, thus we will use it to fill arrays
-// before passing them to user code. If on return an element of the
-// array still contains this value, we will assume that the user code
-// did not write to that memory location.
-static const double kImpossibleValue = 1e302;
-
-bool IsArrayValid(const int size, const double* x) {
- if (x != NULL) {
- for (int i = 0; i < size; ++i) {
- if (!isfinite(x[i]) || (x[i] == kImpossibleValue)) {
- return false;
- }
- }
- }
- return true;
-}
-
-void InvalidateArray(const int size, double* x) {
- if (x != NULL) {
- for (int i = 0; i < size; ++i) {
- x[i] = kImpossibleValue;
- }
- }
-}
-
void InvalidateEvaluation(const ResidualBlock& block,
double* cost,
double* residuals,