Added flag for absolute error
parent
2fc87858ce
commit
51b6fd0b43
|
@ -90,7 +90,7 @@ bool equal_with_abs_tol(const Eigen::DenseBase<MATRIX>& A, const Eigen::DenseBas
|
|||
|
||||
for(size_t i=0; i<m1; i++)
|
||||
for(size_t j=0; j<n1; j++) {
|
||||
if(!fpEqual(A(i,j), B(i,j), tol)) {
|
||||
if(!fpEqual(A(i,j), B(i,j), tol, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace gtsam {
|
|||
* 1. https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||
* 2. https://floating-point-gui.de/errors/comparison/
|
||||
* ************************************************************************* */
|
||||
bool fpEqual(double a, double b, double tol) {
|
||||
bool fpEqual(double a, double b, double tol, bool absolute) {
|
||||
using std::abs;
|
||||
using std::isnan;
|
||||
using std::isinf;
|
||||
|
@ -66,7 +66,9 @@ bool fpEqual(double a, double b, double tol) {
|
|||
return true;
|
||||
}
|
||||
// Use relative error
|
||||
else if(abs(a-b) <= tol * min(larger, std::numeric_limits<double>::max())) {
|
||||
else if (abs(a - b) <=
|
||||
tol * min(larger, std::numeric_limits<double>::max()) &&
|
||||
!absolute) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,8 @@ static_assert(
|
|||
*
|
||||
* Return true if two numbers are close wrt tol.
|
||||
*/
|
||||
GTSAM_EXPORT bool fpEqual(double a, double b, double tol);
|
||||
GTSAM_EXPORT bool fpEqual(double a, double b, double tol,
|
||||
bool absolute = false);
|
||||
|
||||
/**
|
||||
* print without optional string, must specify cout yourself
|
||||
|
|
|
@ -807,15 +807,15 @@ TEST(Rot3, RQ_derivative) {
|
|||
test_xyz.push_back(VecAndErr{{0, 0, 0}, error});
|
||||
test_xyz.push_back(VecAndErr{{0, 0.5, -0.5}, error});
|
||||
test_xyz.push_back(VecAndErr{{0.3, 0, 0.2}, error});
|
||||
test_xyz.push_back(VecAndErr{{-0.6, 1.3, 0}, error});
|
||||
test_xyz.push_back(VecAndErr{{-0.6, 1.3, 0}, 1e-8});
|
||||
test_xyz.push_back(VecAndErr{{1.0, 0.7, 0.8}, error});
|
||||
test_xyz.push_back(VecAndErr{{3.0, 0.7, -0.6}, error});
|
||||
test_xyz.push_back(VecAndErr{{M_PI / 2, 0, 0}, error});
|
||||
test_xyz.push_back(VecAndErr{{0, 0, M_PI / 2}, error});
|
||||
|
||||
// Test close to singularity
|
||||
test_xyz.push_back(VecAndErr{{0, M_PI / 2 - 1e-1, 0}, 1e-8});
|
||||
test_xyz.push_back(VecAndErr{{0, 3 * M_PI / 2 + 1e-1, 0}, 1e-8});
|
||||
test_xyz.push_back(VecAndErr{{0, M_PI / 2 - 1e-1, 0}, 1e-7});
|
||||
test_xyz.push_back(VecAndErr{{0, 3 * M_PI / 2 + 1e-1, 0}, 1e-7});
|
||||
test_xyz.push_back(VecAndErr{{0, M_PI / 2 - 1.1e-2, 0}, 1e-4});
|
||||
test_xyz.push_back(VecAndErr{{0, 3 * M_PI / 2 + 1.1e-2, 0}, 1e-4});
|
||||
|
||||
|
|
Loading…
Reference in New Issue