Add compound with scalar operators for Jets. Change-Id: Ie47771d8c9df22ddeb6b643ae8a751860d892d67
diff --git a/include/ceres/jet.h b/include/ceres/jet.h index 27c39d3..934bc18 100644 --- a/include/ceres/jet.h +++ b/include/ceres/jet.h
@@ -224,6 +224,27 @@ return *this; } + // Compound with scalar operators. + Jet<T, N>& operator+=(const T& s) { + *this = *this + s; + return *this; + } + + Jet<T, N>& operator-=(const T& s) { + *this = *this - s; + return *this; + } + + Jet<T, N>& operator*=(const T& s) { + *this = *this * s; + return *this; + } + + Jet<T, N>& operator/=(const T& s) { + *this = *this / s; + return *this; + } + // The scalar part. T a;
diff --git a/internal/ceres/jet_test.cc b/internal/ceres/jet_test.cc index 8576eb1..16d37c6 100644 --- a/internal/ceres/jet_test.cc +++ b/internal/ceres/jet_test.cc
@@ -391,22 +391,34 @@ { // Check that 1 + x == x + 1. J a = x + 1.0; J b = 1.0 + x; + J c = x; + c += 1.0; ExpectJetsClose(a, b); + ExpectJetsClose(a, c); } { // Check that 1 - x == -(x - 1). J a = 1.0 - x; J b = -(x - 1.0); + J c = x; + c -= 1.0; ExpectJetsClose(a, b); + ExpectJetsClose(a, -c); } - { // Check that x/s == x*s. + { // Check that (x/s)*s == (x*s)/s. J a = x / 5.0; J b = x * 5.0; + J c = x; + c /= 5.0; + J d = x; + d *= 5.0; ExpectJetsClose(5.0 * a, b / 5.0); + ExpectJetsClose(a, c); + ExpectJetsClose(b, d); } { // Check that x / y == 1 / (y / x).