String to and from enum conversion routines.

Update types.h/cc with stringication and unstringication
routines for the newly introduced enums.

Change-Id: I0fe2842b5b1c75ba351f4ab87ec9fa60af2f9ed2
This commit is contained in:
Sameer Agarwal
2012-11-29 10:28:11 -08:00
parent 3e8d192f28
commit 1afd498f50
2 changed files with 101 additions and 20 deletions
+17 -2
View File
@@ -192,13 +192,13 @@ enum LineSearchDirectionType {
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 @@ bool StringToTrustRegionStrategyType(string value,
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);
+84 -18
View File
@@ -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 @@ bool StringToLinearSolverType(string value, LinearSolverType* type) {
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 @@ bool StringToPreconditionerType(string value, PreconditionerType* type) {
}
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 @@ bool StringToSparseLinearAlgebraLibraryType(
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 @@ bool StringToTrustRegionStrategyType(string value,
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 @@ bool StringToDoglegType(string value, DoglegType* type) {
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* SolverTerminationTypeToString(
}
const char* LinearSolverTerminationTypeToString(
LinearSolverTerminationType termination_type) {
switch (termination_type) {
LinearSolverTerminationType type) {
switch (type) {
CASESTR(TOLERANCE);
CASESTR(MAX_ITERATIONS);
CASESTR(STAGNATION);