diff --git a/gtsam/nonlinear/NonlinearOptimizerParams.cpp b/gtsam/nonlinear/NonlinearOptimizerParams.cpp index 671dbe34d..800db02a0 100644 --- a/gtsam/nonlinear/NonlinearOptimizerParams.cpp +++ b/gtsam/nonlinear/NonlinearOptimizerParams.cpp @@ -123,6 +123,28 @@ void NonlinearOptimizerParams::print(const std::string& str) const { std::cout.flush(); } +/* ************************************************************************* */ +bool NonlinearOptimizerParams::equals(const NonlinearOptimizerParams& other, + double tol) const { + // Check for equality of shared ptrs + bool iterative_params_equal = iterativeParams == other.iterativeParams; + // Check equality of components + if (iterativeParams && other.iterativeParams) { + iterative_params_equal = iterativeParams->equals(*other.iterativeParams); + } else { + // If one or both shared pointers are null, we can't assume they are equal + iterative_params_equal = false; + } + + return maxIterations == other.getMaxIterations() && + std::abs(relativeErrorTol - other.getRelativeErrorTol()) <= tol && + std::abs(absoluteErrorTol - other.getAbsoluteErrorTol()) <= tol && + std::abs(errorTol - other.getErrorTol()) <= tol && + verbosityTranslator(verbosity) == other.getVerbosity() && + orderingType == other.orderingType && ordering == other.ordering && + linearSolverType == other.linearSolverType && iterative_params_equal; +} + /* ************************************************************************* */ std::string NonlinearOptimizerParams::linearSolverTranslator( LinearSolverType linearSolverType) const { diff --git a/gtsam/nonlinear/NonlinearOptimizerParams.h b/gtsam/nonlinear/NonlinearOptimizerParams.h index 92e22e064..0b4d8b2fd 100644 --- a/gtsam/nonlinear/NonlinearOptimizerParams.h +++ b/gtsam/nonlinear/NonlinearOptimizerParams.h @@ -114,24 +114,7 @@ public: virtual void print(const std::string& str = "") const; - bool equals(const NonlinearOptimizerParams& other, double tol = 1e-9) const { - // Check for equality of shared ptrs - bool iterative_params_equal = false; - if (iterativeParams == other.iterativeParams) { - iterative_params_equal = true; - } - if (iterativeParams && other.iterativeParams) { - iterative_params_equal = iterativeParams->equals(*other.iterativeParams); - } - - return maxIterations == other.getMaxIterations() && - std::abs(relativeErrorTol - other.getRelativeErrorTol()) <= tol && - std::abs(absoluteErrorTol - other.getAbsoluteErrorTol()) <= tol && - std::abs(errorTol - other.getErrorTol()) <= tol && - verbosityTranslator(verbosity) == other.getVerbosity() && - orderingType == other.orderingType && ordering == other.ordering && - linearSolverType == other.linearSolverType && iterative_params_equal; - } + bool equals(const NonlinearOptimizerParams& other, double tol = 1e-9); inline bool isMultifrontal() const { return (linearSolverType == MULTIFRONTAL_CHOLESKY)