Two changes to TinySolver
1. Change the ordering from NUM_PARAMETERS, NUM_RESIDUALS to
NUM_RESIDUALS, NUM_PARAMETERS in docs and in code.
2. TinySolver::solve -> TinySolver::Solve
Change-Id: I4dca87b971fd9168f1200b53c362669cffc82c1b
diff --git a/include/ceres/tiny_solver.h b/include/ceres/tiny_solver.h
index efe12d5..4d40ee8 100644
--- a/include/ceres/tiny_solver.h
+++ b/include/ceres/tiny_solver.h
@@ -69,15 +69,15 @@
// struct TinySolverCostFunctionTraits {
// typedef double Scalar;
// enum {
-// NUM_PARAMETERS = <int> OR Eigen::Dynamic,
// NUM_RESIDUALS = <int> OR Eigen::Dynamic,
+// NUM_PARAMETERS = <int> OR Eigen::Dynamic,
// };
// bool operator()(const double* parameters,
// double* residuals,
// double* jacobian) const;
//
-// int NumParameters(); -- Needed if NUM_PARAMETERS == Eigen::Dynamic.
// int NumResiduals(); -- Needed if NUM_RESIDUALS == Eigen::Dynamic.
+// int NumParameters(); -- Needed if NUM_PARAMETERS == Eigen::Dynamic.
// }
//
// For operator(), the size of the objects is:
@@ -92,8 +92,8 @@
// struct MyCostFunctionExample {
// typedef double Scalar;
// enum {
-// NUM_PARAMETERS = 3,
// NUM_RESIDUALS = 2,
+// NUM_PARAMETERS = 3,
// };
// bool operator()(const double* parameters,
// double* residuals,
@@ -110,20 +110,21 @@
// jacobian[2 * 2 + 0] = 4; // Third column (z).
// jacobian[2 * 2 + 1] = y;
// }
-// return EvaluateResidualsAndJacobians(parameters, residuals, jacobian);
+// return true;
// }
// };
//
// The solver supports either statically or dynamically sized cost
-// functions. If the number of parameters is dynamic then the Function
+// functions. If the number of residuals is dynamic then the Function
// must define:
//
-// int NumParameters() const;
-//
-// If the number of residuals is dynamic then the Function must define:
-//
// int NumResiduals() const;
//
+// If the number of parameters is dynamic then the Function must
+// define:
+//
+// int NumParameters() const;
+//
template<typename Function,
typename LinearSolver = Eigen::PartialPivLU<
Eigen::Matrix<typename Function::Scalar,
@@ -192,8 +193,8 @@
return RUNNING;
}
- Results solve(const Function& function, Parameters* x_and_min) {
- Initialize<NUM_PARAMETERS, NUM_RESIDUALS>(function);
+ Results Solve(const Function& function, Parameters* x_and_min) {
+ Initialize<NUM_RESIDUALS, NUM_PARAMETERS>(function);
assert(x_and_min);
Parameters& x = *x_and_min;
@@ -270,34 +271,34 @@
};
// The number of parameters and residuals are dynamically sized.
- template <int N, int M>
- typename enable_if<(N == Eigen::Dynamic && M == Eigen::Dynamic), void>::type
+ template <int R, int P>
+ typename enable_if<(R == Eigen::Dynamic && P == Eigen::Dynamic), void>::type
Initialize(const Function& function) {
- Initialize(function.NumParameters(), function.NumResiduals());
+ Initialize(function.NumResiduals(), function.NumParameters());
}
// The number of parameters is dynamically sized and the number of
// residuals is statically sized.
- template <int N, int M>
- typename enable_if<(N == Eigen::Dynamic && M != Eigen::Dynamic), void>::type
+ template <int R, int P>
+ typename enable_if<(R == Eigen::Dynamic && P != Eigen::Dynamic), void>::type
Initialize(const Function& function) {
- Initialize(function.NumParameters(), M);
+ Initialize(function.NumResiduals(), P);
}
// The number of parameters is statically sized and the number of
// residuals is dynamically sized.
- template <int N, int M>
- typename enable_if<(N != Eigen::Dynamic && M == Eigen::Dynamic), void>::type
+ template <int R, int P>
+ typename enable_if<(R != Eigen::Dynamic && P == Eigen::Dynamic), void>::type
Initialize(const Function& function) {
- Initialize(N, function.NumResiduals());
+ Initialize(R, function.NumParameters());
}
// The number of parameters and residuals are statically sized.
- template <int N, int M>
- typename enable_if<(N != Eigen::Dynamic && M != Eigen::Dynamic), void>::type
+ template <int R, int P>
+ typename enable_if<(R != Eigen::Dynamic && P != Eigen::Dynamic), void>::type
Initialize(const Function& /* function */) { }
- void Initialize(int num_parameters, int num_residuals) {
+ void Initialize(int num_residuals, int num_parameters) {
error_.resize(num_residuals);
f_x_new_.resize(num_residuals);
jacobian_.resize(num_residuals, num_parameters);
@@ -308,4 +309,4 @@
} // namespace ceres
-#endif // CERES_PUBLIC_TINY_SOLVER_H_
\ No newline at end of file
+#endif // CERES_PUBLIC_TINY_SOLVER_H_
diff --git a/internal/ceres/tiny_solver_test.cc b/internal/ceres/tiny_solver_test.cc
index 86827d5..747e20d 100644
--- a/internal/ceres/tiny_solver_test.cc
+++ b/internal/ceres/tiny_solver_test.cc
@@ -70,8 +70,8 @@
typedef double Scalar;
enum {
// Can also be Eigen::Dynamic.
- NUM_PARAMETERS = 3,
NUM_RESIDUALS = 2,
+ NUM_PARAMETERS = 3,
};
bool operator()(const double* parameters,
double* residuals,
@@ -84,8 +84,8 @@
public:
typedef double Scalar;
enum {
- NUM_PARAMETERS = Eigen::Dynamic,
NUM_RESIDUALS = 2,
+ NUM_PARAMETERS = Eigen::Dynamic,
};
int NumParameters() const {
@@ -103,8 +103,8 @@
public:
typedef double Scalar;
enum {
- NUM_PARAMETERS = 3,
NUM_RESIDUALS = Eigen::Dynamic,
+ NUM_PARAMETERS = 3,
};
int NumResiduals() const {
@@ -122,18 +122,18 @@
public:
typedef double Scalar;
enum {
- NUM_PARAMETERS = Eigen::Dynamic,
NUM_RESIDUALS = Eigen::Dynamic,
+ NUM_PARAMETERS = Eigen::Dynamic,
};
- int NumParameters() const {
- return 3;
- }
-
int NumResiduals() const {
return 2;
}
+ int NumParameters() const {
+ return 3;
+ }
+
bool operator()(const double* parameters,
double* residuals,
double* jacobian) const {
@@ -149,7 +149,7 @@
EXPECT_GT(residuals.norm(), 1e-10);
TinySolver<Function> solver;
- solver.solve(f, &x);
+ solver.Solve(f, &x);
f(x.data(), residuals.data(), NULL);
EXPECT_NEAR(0.0, residuals.norm(), 1e-10);