/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * @file testBAD.cpp * @date September 18, 2014 * @author Frank Dellaert * @brief unit tests for Block Automatic Differentiation */ #include #include #include #include #include using namespace std; using namespace gtsam; /// This class might have to become a class hierarchy ? template class Expression { public: /// Constructor with a single key Expression(Key key) { } /// Constructor with a value, yielding a constant Expression(const T& t) { } }; /// Expression version of transform Expression transformTo(const Expression& x, const Expression& p) { return Expression(0); } /// Expression version of project Expression project(const Expression& p) { return Expression(0); } /// Expression version of uncalibrate Expression uncalibrate(const Expression& K, const Expression& p) { return Expression(0); } /// Expression version of Point2.sub Expression operator -(const Expression& p, const Expression& q) { return Expression(0); } /// AD Factor template class BADFactor: NoiseModelFactor { public: /// Constructor BADFactor(const Expression& t) { } Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { if (H) H->push_back(zeros(2,2)); return Vector(); } }; /* ************************************************************************* */ TEST(BAD, test) { // Create leaves Expression x(1); Expression p(2); Expression K(3); Expression uv(Point2(300, 62)); // Create expression tree Expression p_cam = transformTo(x, p); Expression projection = project(p_cam); Expression uv_hat = uncalibrate(K, projection); Expression e = uv - uv_hat; // Create factor BADFactor f(e); // evaluate, with derivatives Values values; vector jacobians; Vector actual = f.unwhitenedError(values, jacobians); // Check value Vector expected = (Vector(2) << 0, 0); EXPECT(assert_equal(expected, actual)); // Check derivatives Matrix expectedHx = zeros(2,3); EXPECT(assert_equal(expectedHx, jacobians[0])); } /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr); } /* ************************************************************************* */