move NonlinearOptimizerParams::equals definition to .cpp file and improve slightly

release/4.3a0
Varun Agrawal 2024-08-24 06:19:00 -04:00
parent 19542053cc
commit 5cf1e0d220
2 changed files with 23 additions and 18 deletions

View File

@ -123,6 +123,28 @@ void NonlinearOptimizerParams::print(const std::string& str) const {
std::cout.flush(); 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( std::string NonlinearOptimizerParams::linearSolverTranslator(
LinearSolverType linearSolverType) const { LinearSolverType linearSolverType) const {

View File

@ -114,24 +114,7 @@ public:
virtual void print(const std::string& str = "") const; virtual void print(const std::string& str = "") const;
bool equals(const NonlinearOptimizerParams& other, double tol = 1e-9) const { bool equals(const NonlinearOptimizerParams& other, double tol = 1e-9);
// 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;
}
inline bool isMultifrontal() const { inline bool isMultifrontal() const {
return (linearSolverType == MULTIFRONTAL_CHOLESKY) return (linearSolverType == MULTIFRONTAL_CHOLESKY)