String to and from enum conversion routines. Update types.h/cc with stringication and unstringication routines for the newly introduced enums. Change-Id: I0fe2842b5b1c75ba351f4ab87ec9fa60af2f9ed2
diff --git a/include/ceres/types.h b/include/ceres/types.h index 37beeda..9798314 100644 --- a/include/ceres/types.h +++ b/include/ceres/types.h
@@ -192,13 +192,13 @@ enum NonlinearConjugateGradientType { FLETCHER_REEVES, POLAK_RIBIRERE, - HESTENES_STIEFEL + HESTENES_STIEFEL, }; enum LineSearchType { // Backtracking line search with polynomial interpolation or // bisection. - ARMIJO + ARMIJO, }; // Ceres supports different strategies for computing the trust region @@ -354,6 +354,21 @@ const char* DoglegTypeToString(DoglegType type); bool StringToDoglegType(string value, DoglegType* type); +const char* MinimizerTypeToString(MinimizerType type); +bool StringToMinimizerType(string value, MinimizerType* type); + +const char* LineSearchDirectionTypeToString(LineSearchDirectionType type); +bool StringToLineSearchDirectionType(string value, + LineSearchDirectionType* type); + +const char* LineSearchTypeToString(LineSearchType type); +bool StringToLineSearchType(string value, LineSearchType* type); + +const char* NonlinearConjugateGradientTypeToString( + NonlinearConjugateGradientType type); +bool StringToNonlinearConjugateGradientType( + string value, NonlinearConjugateGradientType* type); + const char* LinearSolverTerminationTypeToString( LinearSolverTerminationType type);
diff --git a/internal/ceres/types.cc b/internal/ceres/types.cc index fc33a4c..1c8a986 100644 --- a/internal/ceres/types.cc +++ b/internal/ceres/types.cc
@@ -37,15 +37,14 @@ namespace ceres { #define CASESTR(x) case x: return #x - #define STRENUM(x) if (value == #x) { *type = x; return true;} void UpperCase(string* input) { std::transform(input->begin(), input->end(), input->begin(), ::toupper); } -const char* LinearSolverTypeToString(LinearSolverType solver_type) { - switch (solver_type) { +const char* LinearSolverTypeToString(LinearSolverType type) { + switch (type) { CASESTR(DENSE_NORMAL_CHOLESKY); CASESTR(DENSE_QR); CASESTR(SPARSE_NORMAL_CHOLESKY); @@ -70,9 +69,8 @@ return false; } -const char* PreconditionerTypeToString( - PreconditionerType preconditioner_type) { - switch (preconditioner_type) { +const char* PreconditionerTypeToString(PreconditionerType type) { + switch (type) { CASESTR(IDENTITY); CASESTR(JACOBI); CASESTR(SCHUR_JACOBI); @@ -94,8 +92,8 @@ } const char* SparseLinearAlgebraLibraryTypeToString( - SparseLinearAlgebraLibraryType sparse_linear_algebra_library_type) { - switch (sparse_linear_algebra_library_type) { + SparseLinearAlgebraLibraryType type) { + switch (type) { CASESTR(SUITE_SPARSE); CASESTR(CX_SPARSE); default: @@ -113,9 +111,8 @@ return false; } -const char* TrustRegionStrategyTypeToString( - TrustRegionStrategyType trust_region_strategy_type) { - switch (trust_region_strategy_type) { +const char* TrustRegionStrategyTypeToString(TrustRegionStrategyType type) { + switch (type) { CASESTR(LEVENBERG_MARQUARDT); CASESTR(DOGLEG); default: @@ -131,8 +128,8 @@ return false; } -const char* DoglegTypeToString(DoglegType dogleg_type) { - switch (dogleg_type) { +const char* DoglegTypeToString(DoglegType type) { + switch (type) { CASESTR(TRADITIONAL_DOGLEG); CASESTR(SUBSPACE_DOGLEG); default: @@ -147,9 +144,78 @@ return false; } -const char* SolverTerminationTypeToString( - SolverTerminationType termination_type) { - switch (termination_type) { +const char* MinimizerTypeToString(MinimizerType type) { + switch (type) { + CASESTR(TRUST_REGION); + CASESTR(LINE_SEARCH); + default: + return "UNKNOWN"; + } +} + +bool StringToMinimizerType(string value, MinimizerType* type) { + UpperCase(&value); + STRENUM(TRUST_REGION); + STRENUM(LINE_SEARCH); + return false; +} + +const char* LineSearchDirectionTypeToString(LineSearchDirectionType type) { + switch (type) { + CASESTR(STEEPEST_DESCENT); + CASESTR(NONLINEAR_CONJUGATE_GRADIENT); + CASESTR(LBFGS); + default: + return "UNKNOWN"; + } +} + +bool StringToLineSearchDirectionType(string value, + LineSearchDirectionType* type) { + UpperCase(&value); + STRENUM(STEEPEST_DESCENT); + STRENUM(NONLINEAR_CONJUGATE_GRADIENT); + STRENUM(LBFGS); + return false; +} + +const char* LineSearchTypeToString(LineSearchType type) { + switch (type) { + CASESTR(ARMIJO); + default: + return "UNKNOWN"; + } +} + +bool StringToLineSearchType(string value, LineSearchType* type) { + UpperCase(&value); + STRENUM(ARMIJO); + return false; +} + +const char* NonlinearConjugateGradientTypeToString( + NonlinearConjugateGradientType type) { + switch (type) { + CASESTR(FLETCHER_REEVES); + CASESTR(POLAK_RIBIRERE); + CASESTR(HESTENES_STIEFEL); + default: + return "UNKNOWN"; + } +} + +bool StringToNonlinearConjugateGradientType( + string value, + NonlinearConjugateGradientType* type) { + UpperCase(&value); + STRENUM(FLETCHER_REEVES); + STRENUM(POLAK_RIBIRERE); + STRENUM(HESTENES_STIEFEL); + return false; +} + +const char* SolverTerminationTypeToString(SolverTerminationType type) { + switch (type) { CASESTR(NO_CONVERGENCE); CASESTR(FUNCTION_TOLERANCE); CASESTR(GRADIENT_TOLERANCE); @@ -164,8 +230,8 @@ } const char* LinearSolverTerminationTypeToString( - LinearSolverTerminationType termination_type) { - switch (termination_type) { + LinearSolverTerminationType type) { + switch (type) { CASESTR(TOLERANCE); CASESTR(MAX_ITERATIONS); CASESTR(STAGNATION);