Moved testing machinery to correct spot
parent
7ff3e11efd
commit
76d478c0e0
|
|
@ -20,44 +20,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtsam/nonlinear/ExpressionFactor.h>
|
#include <gtsam/nonlinear/ExpressionFactor.h>
|
||||||
#include <gtsam/nonlinear/Expression.h>
|
|
||||||
#include <gtsam/nonlinear/factorTesting.h>
|
#include <gtsam/nonlinear/factorTesting.h>
|
||||||
#include <gtsam/base/Matrix.h>
|
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/linear/VectorValues.h>
|
|
||||||
|
|
||||||
#include <CppUnitLite/TestResult.h>
|
|
||||||
#include <CppUnitLite/Test.h>
|
|
||||||
#include <CppUnitLite/Failure.h>
|
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
// CPPUnitLite-style test for linearization of a factor
|
|
||||||
bool testFactorJacobians(TestResult& result_, const std::string& name_,
|
|
||||||
const NoiseModelFactor& factor, const gtsam::Values& values, double delta,
|
|
||||||
double tolerance) {
|
|
||||||
|
|
||||||
// Create expected value by numerical differentiation
|
|
||||||
JacobianFactor expected = linearizeNumerically(factor, values, delta);
|
|
||||||
|
|
||||||
// Create actual value by linearize
|
|
||||||
boost::shared_ptr<JacobianFactor> actual = //
|
|
||||||
boost::dynamic_pointer_cast<JacobianFactor>(factor.linearize(values));
|
|
||||||
|
|
||||||
// Check cast result and then equality
|
|
||||||
return actual && assert_equal(expected, *actual, tolerance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Check the Jacobians produced by a factor against finite differences.
|
|
||||||
/// \param factor The factor to test.
|
|
||||||
/// \param values Values filled in for testing the Jacobians.
|
|
||||||
/// \param numerical_derivative_step The step to use when computing the numerical derivative Jacobians
|
|
||||||
/// \param tolerance The numerical tolerance to use when comparing Jacobians.
|
|
||||||
#define EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, numerical_derivative_step, tolerance) \
|
|
||||||
{ EXPECT(gtsam::internal::testFactorJacobians(result_, name_, factor, values, numerical_derivative_step, tolerance)); }
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
// CPPUnitLite-style test for linearization of an ExpressionFactor
|
// CPPUnitLite-style test for linearization of an ExpressionFactor
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@
|
||||||
#include <gtsam/nonlinear/NonlinearFactor.h>
|
#include <gtsam/nonlinear/NonlinearFactor.h>
|
||||||
#include <gtsam/base/numericalDerivative.h>
|
#include <gtsam/base/numericalDerivative.h>
|
||||||
|
|
||||||
|
#include <CppUnitLite/TestResult.h>
|
||||||
|
#include <CppUnitLite/Test.h>
|
||||||
|
#include <CppUnitLite/Failure.h>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -65,4 +69,30 @@ JacobianFactor linearizeNumerically(const NoiseModelFactor& factor,
|
||||||
return JacobianFactor(jacobians, -e);
|
return JacobianFactor(jacobians, -e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
// CPPUnitLite-style test for linearization of a factor
|
||||||
|
bool testFactorJacobians(TestResult& result_, const std::string& name_,
|
||||||
|
const NoiseModelFactor& factor, const gtsam::Values& values, double delta,
|
||||||
|
double tolerance) {
|
||||||
|
|
||||||
|
// Create expected value by numerical differentiation
|
||||||
|
JacobianFactor expected = linearizeNumerically(factor, values, delta);
|
||||||
|
|
||||||
|
// Create actual value by linearize
|
||||||
|
boost::shared_ptr<JacobianFactor> actual = //
|
||||||
|
boost::dynamic_pointer_cast<JacobianFactor>(factor.linearize(values));
|
||||||
|
|
||||||
|
// Check cast result and then equality
|
||||||
|
return actual && assert_equal(expected, *actual, tolerance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Check the Jacobians produced by a factor against finite differences.
|
||||||
|
/// \param factor The factor to test.
|
||||||
|
/// \param values Values filled in for testing the Jacobians.
|
||||||
|
/// \param numerical_derivative_step The step to use when computing the numerical derivative Jacobians
|
||||||
|
/// \param tolerance The numerical tolerance to use when comparing Jacobians.
|
||||||
|
#define EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, numerical_derivative_step, tolerance) \
|
||||||
|
{ EXPECT(gtsam::internal::testFactorJacobians(result_, name_, factor, values, numerical_derivative_step, tolerance)); }
|
||||||
|
|
||||||
} // namespace gtsam
|
} // namespace gtsam
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue