Remove spurious conversion from doubles to Jets.
Binary operations between Jets and doubles are well defined
and should not require an explicit conversion to Jets to work.
This was an oversight earlier and lead to overzealous conversions
all over our in our example code.
Change-Id: I1799770818e136edfc0a5802d86037ce9aec4923
diff --git a/docs/source/nnls_modeling.rst b/docs/source/nnls_modeling.rst
index 972ea5b..3b1cc28 100644
--- a/docs/source/nnls_modeling.rst
+++ b/docs/source/nnls_modeling.rst
@@ -223,7 +223,7 @@
template <typename T>
bool operator()(const T* const x , const T* const y, T* e) const {
- e[0] = T(k_) - x[0] * y[0] - x[1] * y[1];
+ e[0] = k_ - x[0] * y[0] - x[1] * y[1];
return true;
}
@@ -281,12 +281,6 @@
independent variables, and there is no limit on the dimensionality
of each of them.
- **WARNING 1** Since the functor will get instantiated with
- different types for ``T``, you must convert from other numeric
- types to ``T`` before mixing computations with other variables
- of type ``T``. In the example above, this is seen where instead of
- using ``k_`` directly, ``k_`` is wrapped with ``T(k_)``.
-
**WARNING 2** A common beginner's error when first using
:class:`AutoDiffCostFunction` is to get the sizing wrong. In particular,
there is a tendency to set the template parameters to (dimension of
@@ -1420,7 +1414,7 @@
delta[0] * delta[0] + delta[1] * delta[1] + delta[2] * delta[2];
T q_delta[4];
- if (squared_norm_delta > T(0.0)) {
+ if (squared_norm_delta > 0.0) {
T norm_delta = sqrt(squared_norm_delta);
const T sin_delta_by_delta = sin(norm_delta) / norm_delta;
q_delta[0] = cos(norm_delta);
@@ -1454,12 +1448,6 @@
Global Size ---------------+ |
Local Size -------------------+
- **WARNING:** Since the functor will get instantiated with different
- types for ``T``, you must to convert from other numeric types to
- ``T`` before mixing computations with other variables of type
- ``T``. In the example above, this is seen where instead of using
- ``k_`` directly, ``k_`` is wrapped with ``T(k_)``.
-
:class:`Problem`
================
diff --git a/examples/curve_fitting.cc b/examples/curve_fitting.cc
index 210411e..3f577f8 100644
--- a/examples/curve_fitting.cc
+++ b/examples/curve_fitting.cc
@@ -125,7 +125,7 @@
template <typename T> bool operator()(const T* const m,
const T* const c,
T* residual) const {
- residual[0] = T(y_) - exp(m[0] * T(x_) + c[0]);
+ residual[0] = y_ - exp(m[0] * x_ + c[0]);
return true;
}
diff --git a/examples/ellipse_approximation.cc b/examples/ellipse_approximation.cc
index 1cd2379..7b2bf12 100644
--- a/examples/ellipse_approximation.cc
+++ b/examples/ellipse_approximation.cc
@@ -342,8 +342,8 @@
template <typename T>
bool operator()(const T* x0, const T* x1, T* residuals) const {
- residuals[0] = T(sqrt_weight_) * (x0[0] - x1[0]);
- residuals[1] = T(sqrt_weight_) * (x0[1] - x1[1]);
+ residuals[0] = sqrt_weight_ * (x0[0] - x1[0]);
+ residuals[1] = sqrt_weight_ * (x0[1] - x1[1]);
return true;
}
diff --git a/examples/helloworld.cc b/examples/helloworld.cc
index 4173b37..22dff55 100644
--- a/examples/helloworld.cc
+++ b/examples/helloworld.cc
@@ -48,7 +48,7 @@
// derivatives.
struct CostFunctor {
template <typename T> bool operator()(const T* const x, T* residual) const {
- residual[0] = T(10.0) - x[0];
+ residual[0] = 10.0 - x[0];
return true;
}
};
diff --git a/examples/libmv_bundle_adjuster.cc b/examples/libmv_bundle_adjuster.cc
index 0c6c0d6..47d0cd7 100644
--- a/examples/libmv_bundle_adjuster.cc
+++ b/examples/libmv_bundle_adjuster.cc
@@ -471,9 +471,9 @@
T r2 = x*x + y*y;
T r4 = r2 * r2;
T r6 = r4 * r2;
- T r_coeff = (T(1) + k1*r2 + k2*r4 + k3*r6);
- T xd = x * r_coeff + T(2)*p1*x*y + p2*(r2 + T(2)*x*x);
- T yd = y * r_coeff + T(2)*p2*x*y + p1*(r2 + T(2)*y*y);
+ T r_coeff = 1.0 + k1 * r2 + k2 * r4 + k3 * r6;
+ T xd = x * r_coeff + 2.0 * p1 * x * y + p2 * (r2 + 2.0 * x * x);
+ T yd = y * r_coeff + 2.0 * p2 * x * y + p1 * (r2 + 2.0 * y * y);
// Apply focal length and principal point to get the final image coordinates.
*image_x = focal_length_x * xd + principal_point_x;
@@ -533,8 +533,8 @@
&predicted_y);
// The error is the difference between the predicted and observed position.
- residuals[0] = predicted_x - T(observed_x);
- residuals[1] = predicted_y - T(observed_y);
+ residuals[0] = predicted_x - observed_x;
+ residuals[1] = predicted_y - observed_y;
return true;
}
diff --git a/examples/more_garbow_hillstrom.cc b/examples/more_garbow_hillstrom.cc
index 835cb7f..5ba6d94 100644
--- a/examples/more_garbow_hillstrom.cc
+++ b/examples/more_garbow_hillstrom.cc
@@ -127,8 +127,8 @@
BEGIN_MGH_PROBLEM(TestProblem1, 2, 2)
const T x1 = x[0];
const T x2 = x[1];
- residual[0] = T(10.0) * (x2 - x1 * x1);
- residual[1] = T(1.0) - x1;
+ residual[0] = 10.0 * (x2 - x1 * x1);
+ residual[1] = 1.0 - x1;
END_MGH_PROBLEM;
const double TestProblem1::initial_x[] = {-1.2, 1.0};
@@ -142,8 +142,8 @@
BEGIN_MGH_PROBLEM(TestProblem2, 2, 2)
const T x1 = x[0];
const T x2 = x[1];
- residual[0] = T(-13.0) + x1 + ((T(5.0) - x2) * x2 - T(2.0)) * x2;
- residual[1] = T(-29.0) + x1 + ((x2 + T(1.0)) * x2 - T(14.0)) * x2;
+ residual[0] = -13.0 + x1 + ((5.0 - x2) * x2 - 2.0) * x2;
+ residual[1] = -29.0 + x1 + ((x2 + 1.0) * x2 - 14.0) * x2;
END_MGH_PROBLEM;
const double TestProblem2::initial_x[] = {0.5, -2.0};
@@ -157,8 +157,8 @@
BEGIN_MGH_PROBLEM(TestProblem3, 2, 2)
const T x1 = x[0];
const T x2 = x[1];
- residual[0] = T(10000.0) * x1 * x2 - T(1.0);
- residual[1] = exp(-x1) + exp(-x2) - T(1.0001);
+ residual[0] = 10000.0 * x1 * x2 - 1.0;
+ residual[1] = exp(-x1) + exp(-x2) - 1.0001;
END_MGH_PROBLEM;
const double TestProblem3::initial_x[] = {0.0, 1.0};
@@ -171,9 +171,9 @@
BEGIN_MGH_PROBLEM(TestProblem4, 2, 3)
const T x1 = x[0];
const T x2 = x[1];
- residual[0] = x1 - T(1000000.0);
- residual[1] = x2 - T(0.000002);
- residual[2] = x1 * x2 - T(2.0);
+ residual[0] = x1 - 1000000.0;
+ residual[1] = x2 - 0.000002;
+ residual[2] = x1 * x2 - 2.0;
END_MGH_PROBLEM;
const double TestProblem4::initial_x[] = {1.0, 1.0};
@@ -186,9 +186,9 @@
BEGIN_MGH_PROBLEM(TestProblem5, 2, 3)
const T x1 = x[0];
const T x2 = x[1];
- residual[0] = T(1.5) - x1 * (T(1.0) - x2);
- residual[1] = T(2.25) - x1 * (T(1.0) - x2 * x2);
- residual[2] = T(2.625) - x1 * (T(1.0) - x2 * x2 * x2);
+ residual[0] = 1.5 - x1 * (1.0 - x2);
+ residual[1] = 2.25 - x1 * (1.0 - x2 * x2);
+ residual[2] = 2.625 - x1 * (1.0 - x2 * x2 * x2);
END_MGH_PROBLEM;
const double TestProblem5::initial_x[] = {1.0, 1.0};
@@ -202,9 +202,9 @@
const T x1 = x[0];
const T x2 = x[1];
for (int i = 1; i <= 10; ++i) {
- residual[i - 1] = T(2.0) + T(2.0 * i) -
- (exp(T(static_cast<double>(i)) * x1) +
- exp(T(static_cast<double>(i) * x2)));
+ residual[i - 1] = 2.0 + 2.0 * i -
+ (exp(static_cast<double>(i) * x1) +
+ exp(static_cast<double>(i) * x2));
}
END_MGH_PROBLEM;
@@ -220,9 +220,9 @@
const T x1 = x[0];
const T x2 = x[1];
const T x3 = x[2];
- const T theta = T(0.5 / M_PI) * atan(x2 / x1) + (x1 > 0.0 ? T(0.0) : T(0.5));
- residual[0] = T(10.0) * (x3 - T(10.0) * theta);
- residual[1] = T(10.0) * (sqrt(x1 * x1 + x2 * x2) - T(1.0));
+ const T theta = (0.5 / M_PI) * atan(x2 / x1) + (x1 > 0.0 ? 0.0 : 0.5);
+ residual[0] = 10.0 * (x3 - 10.0 * theta);
+ residual[1] = 10.0 * (sqrt(x1 * x1 + x2 * x2) - 1.0);
residual[2] = x3;
END_MGH_PROBLEM;
@@ -243,10 +243,10 @@
0.73, 0.96, 1.34, 2.10, 4.39};
for (int i = 1; i <=15; ++i) {
- const T u = T(static_cast<double>(i));
- const T v = T(static_cast<double>(16 - i));
- const T w = T(static_cast<double>(std::min(i, 16 - i)));
- residual[i - 1] = T(y[i - 1]) - (x1 + u / (v * x2 + w * x3));
+ const double u = static_cast<double>(i);
+ const double v = static_cast<double>(16 - i);
+ const double w = static_cast<double>(std::min(i, 16 - i));
+ residual[i - 1] = y[i - 1] - (x1 + u / (v * x2 + w * x3));
}
END_MGH_PROBLEM;
@@ -269,9 +269,8 @@
0.3989,
0.3521, 0.2420, 0.1295, 0.0540, 0.0175, 0.0044, 0.0009};
for (int i = 0; i < 15; ++i) {
- const T t_i = T((8.0 - i - 1.0) / 2.0);
- const T y_i = T(y[i]);
- residual[i] = x1 * exp(-x2 * (t_i - x3) * (t_i - x3) / T(2.0)) - y_i;
+ const double t_i = (8.0 - i - 1.0) / 2.0;
+ residual[i] = x1 * exp(-x2 * (t_i - x3) * (t_i - x3) / 2.0) - y[i];
}
END_MGH_PROBLEM;
@@ -291,9 +290,8 @@
8261, 7030, 6005, 5147, 4427, 3820, 3307, 2872};
for (int i = 0; i < 16; ++i) {
- const T ti = T(45 + 5.0 * (i + 1));
- const T yi = T(y[i]);
- residual[i] = x1 * exp(x2 / (ti + x3)) - yi;
+ const double ti = 45.0 + 5.0 * (i + 1);
+ residual[i] = x1 * exp(x2 / (ti + x3)) - y[i];
}
END_MGH_PROBLEM
@@ -314,7 +312,7 @@
for (int i = 1; i <= 100; ++i) {
const double ti = static_cast<double>(i) / 100.0;
const double yi = 25.0 + pow(-50.0 * log(ti), 2.0 / 3.0);
- residual[i - 1] = exp(-pow(abs(T(yi * 100.0 * i) * x2), x3) / x1) - T(ti);
+ residual[i - 1] = exp(-pow(abs((yi * 100.0 * i) * x2), x3) / x1) - ti;
}
END_MGH_PROBLEM
@@ -330,13 +328,13 @@
const T x2 = x[1];
const T x3 = x[2];
- const T t1 = T(0.1);
- const T t2 = T(0.2);
- const T t3 = T(0.3);
+ const double t1 = 0.1;
+ const double t2 = 0.2;
+ const double t3 = 0.3;
- residual[0] = exp(-t1 * x1) - exp(-t1 * x2) - x3 * (exp(-t1) - exp(-T(10.0) * t1));
- residual[1] = exp(-t2 * x1) - exp(-t2 * x2) - x3 * (exp(-t2) - exp(-T(10.0) * t2));
- residual[2] = exp(-t3 * x1) - exp(-t3 * x2) - x3 * (exp(-t3) - exp(-T(10.0) * t3));
+ residual[0] = exp(-t1 * x1) - exp(-t1 * x2) - x3 * (exp(-t1) - exp(-10.0 * t1));
+ residual[1] = exp(-t2 * x1) - exp(-t2 * x2) - x3 * (exp(-t2) - exp(-10.0 * t2));
+ residual[2] = exp(-t3 * x1) - exp(-t3 * x2) - x3 * (exp(-t3) - exp(-10.0 * t3));
END_MGH_PROBLEM
const double TestProblem12::initial_x[] = {0.0, 10.0, 20.0};
@@ -352,9 +350,9 @@
const T x3 = x[2];
const T x4 = x[3];
- residual[0] = x1 + T(10.0) * x2;
- residual[1] = T(sqrt(5.0)) * (x3 - x4);
- residual[2] = (x2 - T(2.0) * x3) * (x2 - T(2.0) * x3);
+ residual[0] = x1 + 10.0 * x2;
+ residual[1] = sqrt(5.0) * (x3 - x4);
+ residual[2] = (x2 - 2.0 * x3) * (x2 - 2.0 * x3);
residual[3] = sqrt(10.0) * (x1 - x4) * (x1 - x4);
END_MGH_PROBLEM
@@ -374,22 +372,22 @@
const T x3 = x[2];
const T x4 = x[3];
- residual[0] = T(10.0) * (x2 - x1 * x1);
- residual[1] = T(1.0) - x1;
- residual[2] = T(sqrt(90.0)) * (x4 - x3 * x3);
- residual[3] = T(1.0) - x3;
- residual[4] = T(sqrt(10.0)) * (x2 + x4 - T(2.0));
- residual[5] = T(1.0/sqrt(10.0)) * (x2 - x4);
+ residual[0] = 10.0 * (x2 - x1 * x1);
+ residual[1] = 1.0 - x1;
+ residual[2] = sqrt(90.0) * (x4 - x3 * x3);
+ residual[3] = 1.0 - x3;
+ residual[4] = sqrt(10.0) * (x2 + x4 - 2.0);
+ residual[5] = 1.0 / sqrt(10.0) * (x2 - x4);
END_MGH_PROBLEM;
-const double TestProblem14::initial_x[] = {-3.0, -1.0, -3.0, -1.0};
-const double TestProblem14::lower_bounds[] = {-100.0, -100.0, -100.0, -100.0};
-const double TestProblem14::upper_bounds[] = {0.0, 10.0, 100.0, 100.0};
-const double TestProblem14::constrained_optimal_cost = 0.15567008e1;
-const double TestProblem14::unconstrained_optimal_cost = 0.0;
+ const double TestProblem14::initial_x[] = {-3.0, -1.0, -3.0, -1.0};
+ const double TestProblem14::lower_bounds[] = {-100.0, -100.0, -100.0, -100.0};
+ const double TestProblem14::upper_bounds[] = {0.0, 10.0, 100.0, 100.0};
+ const double TestProblem14::constrained_optimal_cost = 0.15567008e1;
+ const double TestProblem14::unconstrained_optimal_cost = 0.0;
-// Kowalik and Osborne function.
-BEGIN_MGH_PROBLEM(TestProblem15, 4, 11)
+ // Kowalik and Osborne function.
+ BEGIN_MGH_PROBLEM(TestProblem15, 4, 11)
const T x1 = x[0];
const T x2 = x[1];
const T x3 = x[2];
@@ -401,9 +399,7 @@
0.0833, 0.0714, 0.0625};
for (int i = 0; i < 11; ++i) {
- const T yi = T(y[i]);
- const T ui = T(u[i]);
- residual[i] = yi - x1 * (ui * ui + ui * x2) / (ui * ui + ui * x3 + x4);
+ residual[i] = y[i] - x1 * (u[i] * u[i] + u[i] * x2) / (u[i] * u[i] + u[i] * x3 + x4);
}
END_MGH_PROBLEM;
@@ -424,7 +420,7 @@
const T x4 = x[3];
for (int i = 0; i < 20; ++i) {
- const T ti = T(static_cast<double>(i + 1) / 5.0);
+ const double ti = static_cast<double>(i + 1) / 5.0;
residual[i] = (x1 + ti * x2 - exp(ti)) * (x1 + ti * x2 - exp(ti)) +
(x3 + x4 * sin(ti) - cos(ti)) * (x3 + x4 * sin(ti) - cos(ti));
}
@@ -450,9 +446,8 @@
0.431, 0.424, 0.420, 0.414, 0.411, 0.406};
for (int i = 0; i < 33; ++i) {
- const T yi = T(y[i]);
- const T ti = T(10.0 * i);
- residual[i] = yi - (x1 + x2 * exp(-ti * x4) + x3 * exp(-ti * x5));
+ const double ti = 10.0 * i;
+ residual[i] = y[i] - (x1 + x2 * exp(-ti * x4) + x3 * exp(-ti * x5));
}
END_MGH_PROBLEM;
@@ -477,8 +472,7 @@
for (int i = 0; i < 13; ++i) {
const double ti = 0.1 * (i + 1.0);
const double yi = exp(-ti) - 5.0 * exp(-10.0 * ti) + 3.0 * exp(-4.0 * ti);
- const T si = T(ti);
- residual[i] =x3 * exp(-si * x1) - x4 * exp(-si * x2) + x6 * exp(-si * x5) - T(yi);
+ residual[i] =x3 * exp(-ti * x1) - x4 * exp(-ti * x2) + x6 * exp(-ti * x5) - yi;
}
END_MGH_PROBLEM
@@ -517,11 +511,11 @@
0.428, 0.292, 0.162, 0.098, 0.054};
for (int i = 0; i < 65; ++i) {
- const T ti = T(static_cast<double>(i) / 10.0);
- residual[i] = T(y[i]) - (x1 * exp(-(ti * x5)) +
- x2 * exp(-(ti - x9) * (ti - x9) * x6) +
- x3 * exp(-(ti - x10) * (ti - x10) * x7) +
- x4 * exp(-(ti - x11) * (ti - x11) * x8));
+ const double ti = static_cast<double>(i) / 10.0;
+ residual[i] = y[i] - (x1 * exp(-(ti * x5)) +
+ x2 * exp(-(ti - x9) * (ti - x9) * x6) +
+ x3 * exp(-(ti - x10) * (ti - x10) * x7) +
+ x4 * exp(-(ti - x11) * (ti - x11) * x8));
}
END_MGH_PROBLEM;
diff --git a/examples/nist.cc b/examples/nist.cc
index 4b640fe..55a3c7c 100644
--- a/examples/nist.cc
+++ b/examples/nist.cc
@@ -180,6 +180,7 @@
public:
explicit NISTProblem(const string& filename) {
ifstream ifs(filename.c_str(), ifstream::in);
+ CHECK(ifs) << "Unable to open : " << filename;
vector<string> pieces;
SkipLines(ifs, 24);
@@ -281,12 +282,12 @@
// y = b1 * (b2+x)**(-1/b3) + e
NIST_BEGIN(Bennet5)
- b[0] * pow(b[1] + x, T(-1.0) / b[2])
+ b[0] * pow(b[1] + x, -1.0 / b[2])
NIST_END
// y = b1*(1-exp[-b2*x]) + e
NIST_BEGIN(BoxBOD)
- b[0] * (T(1.0) - exp(-b[1] * x))
+ b[0] * (1.0 - exp(-b[1] * x))
NIST_END
// y = exp[-b1*x]/(b2+b3*x) + e
@@ -316,14 +317,14 @@
// (1+b5*x+b6*x**2+b7*x**3) + e
NIST_BEGIN(Hahn1)
(b[0] + b[1] * x + b[2] * x * x + b[3] * x * x * x) /
- (T(1.0) + b[4] * x + b[5] * x * x + b[6] * x * x * x)
+ (1.0 + b[4] * x + b[5] * x * x + b[6] * x * x * x)
NIST_END
// y = (b1 + b2*x + b3*x**2) /
// (1 + b4*x + b5*x**2) + e
NIST_BEGIN(Kirby2)
(b[0] + b[1] * x + b[2] * x * x) /
- (T(1.0) + b[3] * x + b[4] * x * x)
+ (1.0 + b[3] * x + b[4] * x * x)
NIST_END
// y = b1*(x**2+x*b2) / (x**2+x*b3+b4) + e
@@ -343,63 +344,63 @@
// y = b1*(1-exp[-b2*x]) + e
NIST_BEGIN(Misra1a)
- b[0] * (T(1.0) - exp(-b[1] * x))
+ b[0] * (1.0 - exp(-b[1] * x))
NIST_END
// y = b1 * (1-(1+b2*x/2)**(-2)) + e
NIST_BEGIN(Misra1b)
- b[0] * (T(1.0) - T(1.0)/ ((T(1.0) + b[1] * x / 2.0) * (T(1.0) + b[1] * x / 2.0))) // NOLINT
+ b[0] * (1.0 - 1.0/ ((1.0 + b[1] * x / 2.0) * (1.0 + b[1] * x / 2.0))) // NOLINT
NIST_END
// y = b1 * (1-(1+2*b2*x)**(-.5)) + e
NIST_BEGIN(Misra1c)
- b[0] * (T(1.0) - pow(T(1.0) + T(2.0) * b[1] * x, -0.5))
+ b[0] * (1.0 - pow(1.0 + 2.0 * b[1] * x, -0.5))
NIST_END
// y = b1*b2*x*((1+b2*x)**(-1)) + e
NIST_BEGIN(Misra1d)
- b[0] * b[1] * x / (T(1.0) + b[1] * x)
+ b[0] * b[1] * x / (1.0 + b[1] * x)
NIST_END
const double kPi = 3.141592653589793238462643383279;
// pi = 3.141592653589793238462643383279E0
// y = b1 - b2*x - arctan[b3/(x-b4)]/pi + e
NIST_BEGIN(Roszman1)
- b[0] - b[1] * x - atan2(b[2], (x - b[3]))/T(kPi)
+ b[0] - b[1] * x - atan2(b[2], (x - b[3])) / kPi
NIST_END
// y = b1 / (1+exp[b2-b3*x]) + e
NIST_BEGIN(Rat42)
- b[0] / (T(1.0) + exp(b[1] - b[2] * x))
+ b[0] / (1.0 + exp(b[1] - b[2] * x))
NIST_END
// y = b1 / ((1+exp[b2-b3*x])**(1/b4)) + e
NIST_BEGIN(Rat43)
- b[0] / pow(T(1.0) + exp(b[1] - b[2] * x), T(1.0) / b[3])
+ b[0] / pow(1.0 + exp(b[1] - b[2] * x), 1.0 / b[3])
NIST_END
// y = (b1 + b2*x + b3*x**2 + b4*x**3) /
// (1 + b5*x + b6*x**2 + b7*x**3) + e
NIST_BEGIN(Thurber)
(b[0] + b[1] * x + b[2] * x * x + b[3] * x * x * x) /
- (T(1.0) + b[4] * x + b[5] * x * x + b[6] * x * x * x)
+ (1.0 + b[4] * x + b[5] * x * x + b[6] * x * x * x)
NIST_END
// y = b1 + b2*cos( 2*pi*x/12 ) + b3*sin( 2*pi*x/12 )
// + b5*cos( 2*pi*x/b4 ) + b6*sin( 2*pi*x/b4 )
// + b8*cos( 2*pi*x/b7 ) + b9*sin( 2*pi*x/b7 ) + e
NIST_BEGIN(ENSO)
- b[0] + b[1] * cos(T(2.0 * kPi) * x / T(12.0)) +
- b[2] * sin(T(2.0 * kPi) * x / T(12.0)) +
- b[4] * cos(T(2.0 * kPi) * x / b[3]) +
- b[5] * sin(T(2.0 * kPi) * x / b[3]) +
- b[7] * cos(T(2.0 * kPi) * x / b[6]) +
- b[8] * sin(T(2.0 * kPi) * x / b[6])
+ b[0] + b[1] * cos(2.0 * kPi * x / 12.0) +
+ b[2] * sin(2.0 * kPi * x / 12.0) +
+ b[4] * cos(2.0 * kPi * x / b[3]) +
+ b[5] * sin(2.0 * kPi * x / b[3]) +
+ b[7] * cos(2.0 * kPi * x / b[6]) +
+ b[8] * sin(2.0 * kPi * x / b[6])
NIST_END
// y = (b1/b2) * exp[-0.5*((x-b3)/b2)**2] + e
NIST_BEGIN(Eckerle4)
- b[0] / b[1] * exp(T(-0.5) * pow((x - b[2])/b[1], 2))
+ b[0] / b[1] * exp(-0.5 * pow((x - b[2])/b[1], 2))
NIST_END
struct Nelson {
@@ -410,7 +411,7 @@
template <typename T>
bool operator()(const T* const b, T* residual) const {
// log[y] = b1 - b2*x1 * exp[-b3*x2] + e
- residual[0] = T(log(y_)) - (b[0] - b[1] * T(x1_) * exp(-b[2] * T(x2_)));
+ residual[0] = log(y_) - (b[0] - b[1] * x1_ * exp(-b[2] * x2_));
return true;
}
@@ -425,10 +426,26 @@
options->ridders_relative_initial_step_size = FLAGS_ridders_step_size;
}
+string JoinPath(const string& dirname, const string& basename) {
+#ifdef _WIN32
+ static const char separator = '\\';
+#else
+ static const char separator = '/';
+#endif // _WIN32
+
+ if ((!basename.empty() && basename[0] == separator) || dirname.empty()) {
+ return basename;
+ } else if (dirname[dirname.size() - 1] == separator) {
+ return dirname + basename;
+ } else {
+ return dirname + string(&separator, 1) + basename;
+ }
+}
+
template <typename Model, int num_residuals, int num_parameters>
int RegressionDriver(const string& filename,
const ceres::Solver::Options& options) {
- NISTProblem nist_problem(FLAGS_nist_data_dir + filename);
+ NISTProblem nist_problem(JoinPath(FLAGS_nist_data_dir, filename));
CHECK_EQ(num_residuals, nist_problem.response_size());
CHECK_EQ(num_parameters, nist_problem.num_parameters());
diff --git a/examples/powell.cc b/examples/powell.cc
index baaa149..e98f12f 100644
--- a/examples/powell.cc
+++ b/examples/powell.cc
@@ -60,7 +60,7 @@
const T* const x2,
T* residual) const {
// f1 = x1 + 10 * x2;
- residual[0] = x1[0] + T(10.0) * x2[0];
+ residual[0] = x1[0] + 10.0 * x2[0];
return true;
}
};
@@ -70,7 +70,7 @@
const T* const x4,
T* residual) const {
// f2 = sqrt(5) (x3 - x4)
- residual[0] = T(sqrt(5.0)) * (x3[0] - x4[0]);
+ residual[0] = sqrt(5.0) * (x3[0] - x4[0]);
return true;
}
};
@@ -80,7 +80,7 @@
const T* const x4,
T* residual) const {
// f3 = (x2 - 2 x3)^2
- residual[0] = (x2[0] - T(2.0) * x4[0]) * (x2[0] - T(2.0) * x4[0]);
+ residual[0] = (x2[0] - 2.0 * x4[0]) * (x2[0] - 2.0 * x4[0]);
return true;
}
};
@@ -90,7 +90,7 @@
const T* const x4,
T* residual) const {
// f4 = sqrt(10) (x1 - x4)^2
- residual[0] = T(sqrt(10.0)) * (x1[0] - x4[0]) * (x1[0] - x4[0]);
+ residual[0] = sqrt(10.0) * (x1[0] - x4[0]) * (x1[0] - x4[0]);
return true;
}
};
diff --git a/examples/robot_pose_mle.cc b/examples/robot_pose_mle.cc
index f08603a..1f5058a 100644
--- a/examples/robot_pose_mle.cc
+++ b/examples/robot_pose_mle.cc
@@ -170,7 +170,7 @@
template <typename T>
bool operator()(const T* const odometry, T* residual) const {
- *residual = (*odometry - T(odometry_mean)) / T(odometry_stddev);
+ *residual = (*odometry - odometry_mean) / odometry_stddev;
return true;
}
@@ -201,8 +201,8 @@
for (int i = 0; i <= pose_index; ++i) {
global_pose += relative_poses[i][0];
}
- residuals[0] = (global_pose + T(range_reading) - T(corridor_length)) /
- T(range_stddev);
+ residuals[0] = (global_pose + range_reading - corridor_length) /
+ range_stddev;
return true;
}
diff --git a/examples/robust_curve_fitting.cc b/examples/robust_curve_fitting.cc
index 67aca03..6186aa1 100644
--- a/examples/robust_curve_fitting.cc
+++ b/examples/robust_curve_fitting.cc
@@ -127,7 +127,7 @@
template <typename T> bool operator()(const T* const m,
const T* const c,
T* residual) const {
- residual[0] = T(y_) - exp(m[0] * T(x_) + c[0]);
+ residual[0] = y_ - exp(m[0] * x_ + c[0]);
return true;
}
diff --git a/examples/simple_bundle_adjuster.cc b/examples/simple_bundle_adjuster.cc
index 8b98852..dec6cd6 100644
--- a/examples/simple_bundle_adjuster.cc
+++ b/examples/simple_bundle_adjuster.cc
@@ -146,7 +146,7 @@
const T& l1 = camera[7];
const T& l2 = camera[8];
T r2 = xp*xp + yp*yp;
- T distortion = T(1.0) + r2 * (l1 + l2 * r2);
+ T distortion = 1.0 + r2 * (l1 + l2 * r2);
// Compute final projected point position.
const T& focal = camera[6];
@@ -154,8 +154,8 @@
T predicted_y = focal * distortion * yp;
// The error is the difference between the predicted and observed position.
- residuals[0] = predicted_x - T(observed_x);
- residuals[1] = predicted_y - T(observed_y);
+ residuals[0] = predicted_x - observed_x;
+ residuals[1] = predicted_y - observed_y;
return true;
}
diff --git a/examples/snavely_reprojection_error.h b/examples/snavely_reprojection_error.h
index a425616..5e51eb4 100644
--- a/examples/snavely_reprojection_error.h
+++ b/examples/snavely_reprojection_error.h
@@ -77,7 +77,7 @@
const T& l1 = camera[7];
const T& l2 = camera[8];
const T r2 = xp*xp + yp*yp;
- const T distortion = T(1.0) + r2 * (l1 + l2 * r2);
+ const T distortion = 1.0 + r2 * (l1 + l2 * r2);
// Compute final projected point position.
@@ -86,8 +86,8 @@
const T predicted_y = focal * distortion * yp;
// The error is the difference between the predicted and observed position.
- residuals[0] = predicted_x - T(observed_x);
- residuals[1] = predicted_y - T(observed_y);
+ residuals[0] = predicted_x - observed_x;
+ residuals[1] = predicted_y - observed_y;
return true;
}
@@ -143,7 +143,7 @@
const T& l2 = camera[9];
const T r2 = xp*xp + yp*yp;
- const T distortion = T(1.0) + r2 * (l1 + l2 * r2);
+ const T distortion = 1.0 + r2 * (l1 + l2 * r2);
// Compute final projected point position.
const T& focal = camera[7];
@@ -151,8 +151,8 @@
const T predicted_y = focal * distortion * yp;
// The error is the difference between the predicted and observed position.
- residuals[0] = predicted_x - T(observed_x);
- residuals[1] = predicted_y - T(observed_y);
+ residuals[0] = predicted_x - observed_x;
+ residuals[1] = predicted_y - observed_y;
return true;
}
diff --git a/internal/ceres/bundle_adjustment_test.cc b/internal/ceres/bundle_adjustment_test.cc
index 5cf2be0..7cbf3f3 100644
--- a/internal/ceres/bundle_adjustment_test.cc
+++ b/internal/ceres/bundle_adjustment_test.cc
@@ -212,8 +212,8 @@
T r2 = xp*xp + yp*yp;
T distortion = T(1.0) + r2 * (l1 + l2 * r2);
- residuals[0] = distortion * xp - T(u);
- residuals[1] = distortion * yp - T(v);
+ residuals[0] = distortion * xp - u;
+ residuals[1] = distortion * yp - v;
return true;
}
diff --git a/internal/ceres/system_test.cc b/internal/ceres/system_test.cc
index 5fb608e..de03c74 100644
--- a/internal/ceres/system_test.cc
+++ b/internal/ceres/system_test.cc
@@ -98,7 +98,7 @@
const T* const x2,
T* residual) const {
// f1 = x1 + 10 * x2;
- *residual = *x1 + T(10.0) * *x2;
+ *residual = *x1 + 10.0 * *x2;
return true;
}
};
@@ -109,7 +109,7 @@
const T* const x4,
T* residual) const {
// f2 = sqrt(5) (x3 - x4)
- *residual = T(sqrt(5.0)) * (*x3 - *x4);
+ *residual = std::sqrt(5.0) * (*x3 - *x4);
return true;
}
};
@@ -120,7 +120,7 @@
const T* const x4,
T* residual) const {
// f3 = (x2 - 2 x3)^2
- residual[0] = (x2[0] - T(2.0) * x4[0]) * (x2[0] - T(2.0) * x4[0]);
+ residual[0] = (x2[0] - 2.0 * x4[0]) * (x2[0] - 2.0 * x4[0]);
return true;
}
};
@@ -131,7 +131,7 @@
const T* const x4,
T* residual) const {
// f4 = sqrt(10) (x1 - x4)^2
- residual[0] = T(sqrt(10.0)) * (x1[0] - x4[0]) * (x1[0] - x4[0]);
+ residual[0] = std::sqrt(10.0) * (x1[0] - x4[0]) * (x1[0] - x4[0]);
return true;
}
};