From b7e60c4043b39dd8d31510376e34bcb13f8cfa64 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 22 Dec 2024 17:30:20 -0500 Subject: [PATCH 01/19] suppress newer GCC warnings in Eigen --- gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h b/gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h index fe0cfec0bc..aa798c0939 100755 --- a/gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h +++ b/gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h @@ -66,6 +66,7 @@ #endif #if __GNUC__>=6 #pragma GCC diagnostic ignored "-Wignored-attributes" + #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif #if __GNUC__==7 // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325 From ff4525582167e08d2a550c2662d596fb8656d409 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 22 Dec 2024 17:30:25 -0500 Subject: [PATCH 02/19] fix warning --- gtsam/hybrid/tests/testHybridMotionModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/hybrid/tests/testHybridMotionModel.cpp b/gtsam/hybrid/tests/testHybridMotionModel.cpp index 747a1b6883..a208febf75 100644 --- a/gtsam/hybrid/tests/testHybridMotionModel.cpp +++ b/gtsam/hybrid/tests/testHybridMotionModel.cpp @@ -100,7 +100,7 @@ std::pair approximateDiscreteMarginal( // Do importance sampling double w0 = 0.0, w1 = 0.0; std::mt19937_64 rng(42); - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { HybridValues sample = q.sample(&rng); sample.insert(given); double weight = hbn.evaluate(sample) / q.evaluate(sample); From ac47d8f27c9bbcb88f4abef6fb400d7e2af52fa1 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 22 Dec 2024 17:31:32 -0500 Subject: [PATCH 03/19] fix class name in comments --- gtsam/navigation/ImuFactor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtsam/navigation/ImuFactor.h b/gtsam/navigation/ImuFactor.h index 7254838fd4..a3d7dce756 100644 --- a/gtsam/navigation/ImuFactor.h +++ b/gtsam/navigation/ImuFactor.h @@ -113,7 +113,7 @@ class GTSAM_EXPORT PreintegratedImuMeasurements: public PreintegrationType { /// equals bool equals(const PreintegratedImuMeasurements& expected, double tol = 1e-9) const; - /// Re-initialize PreintegratedIMUMeasurements + /// Re-initialize PreintegratedImuMeasurements void resetIntegration() override; /** @@ -159,7 +159,7 @@ class GTSAM_EXPORT PreintegratedImuMeasurements: public PreintegrationType { * the vehicle at previous time step), current state (pose and velocity at * current time step), and the bias estimate. Following the preintegration * scheme proposed in [2], the ImuFactor includes many IMU measurements, which - * are "summarized" using the PreintegratedIMUMeasurements class. + * are "summarized" using the PreintegratedImuMeasurements class. * Note that this factor does not model "temporal consistency" of the biases * (which are usually slowly varying quantities), which is up to the caller. * See also CombinedImuFactor for a class that does this for you. From 1a96544308807b1f3eaa36ec476c3569723b6a0d Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 22 Dec 2024 17:34:41 -0500 Subject: [PATCH 04/19] more comprehensive initialization of ImuFactors --- gtsam/navigation/CombinedImuFactor.h | 10 +++++++--- gtsam/navigation/ImuFactor.h | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gtsam/navigation/CombinedImuFactor.h b/gtsam/navigation/CombinedImuFactor.h index 0ffb386a05..5772fc5ae8 100644 --- a/gtsam/navigation/CombinedImuFactor.h +++ b/gtsam/navigation/CombinedImuFactor.h @@ -84,7 +84,7 @@ class GTSAM_EXPORT PreintegratedCombinedMeasurements /// @{ /// Default constructor only for serialization and wrappers - PreintegratedCombinedMeasurements() { preintMeasCov_.setZero(); } + PreintegratedCombinedMeasurements() { resetIntegration(); } /** * Default constructor, initializes the class with no measurements @@ -97,7 +97,9 @@ class GTSAM_EXPORT PreintegratedCombinedMeasurements const imuBias::ConstantBias& biasHat = imuBias::ConstantBias(), const Eigen::Matrix& preintMeasCov = Eigen::Matrix::Zero()) - : PreintegrationType(p, biasHat), preintMeasCov_(preintMeasCov) {} + : PreintegrationType(p, biasHat), preintMeasCov_(preintMeasCov) { + PreintegrationType::resetIntegration(); + } /** * Construct preintegrated directly from members: base class and @@ -108,7 +110,9 @@ class GTSAM_EXPORT PreintegratedCombinedMeasurements PreintegratedCombinedMeasurements( const PreintegrationType& base, const Eigen::Matrix& preintMeasCov) - : PreintegrationType(base), preintMeasCov_(preintMeasCov) {} + : PreintegrationType(base), preintMeasCov_(preintMeasCov) { + PreintegrationType::resetIntegration(); + } /// Virtual destructor ~PreintegratedCombinedMeasurements() override {} diff --git a/gtsam/navigation/ImuFactor.h b/gtsam/navigation/ImuFactor.h index a3d7dce756..fd087aaee0 100644 --- a/gtsam/navigation/ImuFactor.h +++ b/gtsam/navigation/ImuFactor.h @@ -79,7 +79,7 @@ class GTSAM_EXPORT PreintegratedImuMeasurements: public PreintegrationType { /// Default constructor for serialization and wrappers PreintegratedImuMeasurements() { - preintMeasCov_.setZero(); + resetIntegration(); } /** @@ -90,7 +90,7 @@ class GTSAM_EXPORT PreintegratedImuMeasurements: public PreintegrationType { PreintegratedImuMeasurements(const std::shared_ptr& p, const imuBias::ConstantBias& biasHat = imuBias::ConstantBias()) : PreintegrationType(p, biasHat) { - preintMeasCov_.setZero(); + resetIntegration(); } /** @@ -101,6 +101,7 @@ class GTSAM_EXPORT PreintegratedImuMeasurements: public PreintegrationType { PreintegratedImuMeasurements(const PreintegrationType& base, const Matrix9& preintMeasCov) : PreintegrationType(base), preintMeasCov_(preintMeasCov) { + PreintegrationType::resetIntegration(); } /// Virtual destructor From afc6868ca39f238e930101c03cfd52e2a46795c5 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 22 Dec 2024 18:17:09 -0500 Subject: [PATCH 05/19] wrap ImuFactor2 --- gtsam/navigation/navigation.i | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gtsam/navigation/navigation.i b/gtsam/navigation/navigation.i index adb8bf2bb0..ceeab3b355 100644 --- a/gtsam/navigation/navigation.i +++ b/gtsam/navigation/navigation.i @@ -156,6 +156,22 @@ virtual class ImuFactor: gtsam::NonlinearFactor { void serialize() const; }; +virtual class ImuFactor2: gtsam::NonlinearFactor { + ImuFactor2(); + ImuFactor2(size_t state_i, size_t state_j, + size_t bias, + const gtsam::PreintegratedImuMeasurements& preintegratedMeasurements); + + // Standard Interface + gtsam::PreintegratedImuMeasurements preintegratedMeasurements() const; + gtsam::Vector evaluateError(const gtsam::NavState& state_i, + gtsam::NavState& state_j, + const gtsam::imuBias::ConstantBias& bias_i); + + // enable serialization functionality + void serialize() const; +}; + #include virtual class PreintegrationCombinedParams : gtsam::PreintegrationParams { PreintegrationCombinedParams(gtsam::Vector n_gravity); From 28065b737b62c3b0c32119ba73c6058c8e99f147 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 23 Dec 2024 10:31:39 -0500 Subject: [PATCH 06/19] Helper macro for cout printing --- gtsam/base/Testable.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gtsam/base/Testable.h b/gtsam/base/Testable.h index 8eb6326c05..eb8d851d1a 100644 --- a/gtsam/base/Testable.h +++ b/gtsam/base/Testable.h @@ -41,6 +41,7 @@ #include #define GTSAM_PRINT(x)((x).print(#x)) +#define GTSAM_COUT(x) (std::cout << #x ": " << x << std::endl) namespace gtsam { From 72da68ebf30bdadc1a340c9a6220745d3a32e611 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 8 Jan 2025 12:44:39 -0500 Subject: [PATCH 07/19] platform specific #ifs --- gtsam/hybrid/tests/testHybridBayesNet.cpp | 32 ++++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index 989694b269..bf035de679 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -552,19 +552,25 @@ TEST(HybridBayesNet, Sampling) { EXPECT_LONGS_EQUAL(2, average_continuous.size()); EXPECT_LONGS_EQUAL(num_samples, discrete_samples.size()); - // Regressions don't work across platforms :-( - // // regression for specific RNG seed - // double discrete_sum = - // std::accumulate(discrete_samples.begin(), discrete_samples.end(), - // decltype(discrete_samples)::value_type(0)); - // EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); - - // VectorValues expected; - // expected.insert({X(0), Vector1(-0.0131207162712)}); - // expected.insert({X(1), Vector1(-0.499026377568)}); - // // regression for specific RNG seed - // EXPECT(assert_equal(expected, average_continuous.scale(1.0 / - // num_samples))); + // regression for specific RNG seed + double discrete_sum = + std::accumulate(discrete_samples.begin(), discrete_samples.end(), + decltype(discrete_samples)::value_type(0)); +#if __APPLE__ + EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); +#elif __linux__ + EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); +#endif + + VectorValues expected; + expected.insert({X(0), Vector1(-0.0131207162712)}); + expected.insert({X(1), Vector1(-0.499026377568)}); + // regression for specific RNG seed +#if __APPLE__ + EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); +#elif __linux__ + EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); +#endif } /* ****************************************************************************/ From c00f6631adaa7c85876249cfc986f959fde1addc Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 8 Jan 2025 12:52:44 -0500 Subject: [PATCH 08/19] other tests --- gtsam/linear/tests/testGaussianBayesNet.cpp | 12 +++++++++--- gtsam/linear/tests/testGaussianConditional.cpp | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/gtsam/linear/tests/testGaussianBayesNet.cpp b/gtsam/linear/tests/testGaussianBayesNet.cpp index b1cfbe12ca..ccc58d3ff6 100644 --- a/gtsam/linear/tests/testGaussianBayesNet.cpp +++ b/gtsam/linear/tests/testGaussianBayesNet.cpp @@ -186,9 +186,15 @@ TEST(GaussianBayesNet, sample) { std::mt19937_64 rng(4242); auto actual3 = gbn.sample(&rng); EXPECT_LONGS_EQUAL(2, actual.size()); - // regression is not repeatable across platforms/versions :-( - // EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); - // EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); + + // regressions +#ifdef __APPLE__ + EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); + EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); +#elif __linux__ + EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); + EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); +#endif } /* ************************************************************************* */ diff --git a/gtsam/linear/tests/testGaussianConditional.cpp b/gtsam/linear/tests/testGaussianConditional.cpp index 68894c3142..b445443480 100644 --- a/gtsam/linear/tests/testGaussianConditional.cpp +++ b/gtsam/linear/tests/testGaussianConditional.cpp @@ -464,8 +464,12 @@ TEST(GaussianConditional, sample) { std::mt19937_64 rng(4242); auto actual3 = conditional.sample(given, &rng); EXPECT_LONGS_EQUAL(1, actual2.size()); - // regression is not repeatable across platforms/versions :-( - // EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); + // regressions +#ifdef __APPLE__ + EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); +#elif __linux__ + EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); +#endif } /* ************************************************************************* */ From 212c79289f0877c7ef9222351728ebca563761e8 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 8 Jan 2025 12:57:30 -0500 Subject: [PATCH 09/19] support Windows --- gtsam/hybrid/tests/testHybridBayesNet.cpp | 4 ++++ gtsam/linear/tests/testGaussianBayesNet.cpp | 3 +++ gtsam/linear/tests/testGaussianConditional.cpp | 2 ++ 3 files changed, 9 insertions(+) diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index bf035de679..127160ab62 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -560,6 +560,8 @@ TEST(HybridBayesNet, Sampling) { EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); #elif __linux__ EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); +#elif _WIN32 + EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); #endif VectorValues expected; @@ -570,6 +572,8 @@ TEST(HybridBayesNet, Sampling) { EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); #elif __linux__ EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); +#elif _WIN32 + EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); #endif } diff --git a/gtsam/linear/tests/testGaussianBayesNet.cpp b/gtsam/linear/tests/testGaussianBayesNet.cpp index ccc58d3ff6..570296e8b7 100644 --- a/gtsam/linear/tests/testGaussianBayesNet.cpp +++ b/gtsam/linear/tests/testGaussianBayesNet.cpp @@ -194,6 +194,9 @@ TEST(GaussianBayesNet, sample) { #elif __linux__ EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); +#elif _WIN32 + EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); + EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); #endif } diff --git a/gtsam/linear/tests/testGaussianConditional.cpp b/gtsam/linear/tests/testGaussianConditional.cpp index b445443480..2213ae8728 100644 --- a/gtsam/linear/tests/testGaussianConditional.cpp +++ b/gtsam/linear/tests/testGaussianConditional.cpp @@ -469,6 +469,8 @@ TEST(GaussianConditional, sample) { EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); #elif __linux__ EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); +#elif _WIN32 + EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); #endif } From d9106fd19083cdc8b900c991cc4e104be009706a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 8 Jan 2025 13:32:34 -0500 Subject: [PATCH 10/19] add numeric header for std::accumulate --- gtsam/hybrid/tests/testHybridBayesNet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index 127160ab62..5f54c57b6e 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -34,6 +34,7 @@ #include #include +#include using namespace std; using namespace gtsam; From 41280d4d1e32a2545d18e7a6500f22a42ad36736 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 8 Jan 2025 18:33:46 -0500 Subject: [PATCH 11/19] update tests that failed and add shonan averaging test --- gtsam/hybrid/tests/testHybridBayesNet.cpp | 16 ++++++-------- gtsam/linear/tests/testGaussianBayesNet.cpp | 4 ++-- .../linear/tests/testGaussianConditional.cpp | 8 +++---- gtsam/sfm/tests/testShonanAveraging.cpp | 22 ++++++++++++------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index 5f54c57b6e..a5bea4292a 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -557,25 +557,23 @@ TEST(HybridBayesNet, Sampling) { double discrete_sum = std::accumulate(discrete_samples.begin(), discrete_samples.end(), decltype(discrete_samples)::value_type(0)); -#if __APPLE__ +#if __APPLE__ || _WIN32 EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); #elif __linux__ EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); -#elif _WIN32 - EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); #endif VectorValues expected; + // regression for specific RNG seed +#if __APPLE__ || _WIN32 expected.insert({X(0), Vector1(-0.0131207162712)}); expected.insert({X(1), Vector1(-0.499026377568)}); - // regression for specific RNG seed -#if __APPLE__ - EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); #elif __linux__ - EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); -#elif _WIN32 - EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); + expected.insert({X(0), Vector1(-0.00799425)}); + expected.insert({X(1), Vector1(-0.526464)}); #endif + + EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); } /* ****************************************************************************/ diff --git a/gtsam/linear/tests/testGaussianBayesNet.cpp b/gtsam/linear/tests/testGaussianBayesNet.cpp index 570296e8b7..32534a1e7a 100644 --- a/gtsam/linear/tests/testGaussianBayesNet.cpp +++ b/gtsam/linear/tests/testGaussianBayesNet.cpp @@ -192,8 +192,8 @@ TEST(GaussianBayesNet, sample) { EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); #elif __linux__ - EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); - EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); + EXPECT(assert_equal(Vector2(20.0070499, 39.9942591), actual[X(1)], 1e-5)); + EXPECT(assert_equal(Vector2(109.976501, 229.990945), actual[X(0)], 1e-5)); #elif _WIN32 EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); diff --git a/gtsam/linear/tests/testGaussianConditional.cpp b/gtsam/linear/tests/testGaussianConditional.cpp index 2213ae8728..ad6a8ffe20 100644 --- a/gtsam/linear/tests/testGaussianConditional.cpp +++ b/gtsam/linear/tests/testGaussianConditional.cpp @@ -465,12 +465,10 @@ TEST(GaussianConditional, sample) { auto actual3 = conditional.sample(given, &rng); EXPECT_LONGS_EQUAL(1, actual2.size()); // regressions -#ifdef __APPLE__ +#if __APPLE__ || _WIN32 EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); #elif __linux__ - EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); -#elif _WIN32 - EXPECT(assert_equal(Vector2(31.0111856, 64.9850775), actual2[X(0)], 1e-5)); + EXPECT(assert_equal(Vector2(30.9809331, 64.9927588), actual2[X(0)], 1e-5)); #endif } @@ -523,7 +521,7 @@ TEST(GaussianConditional, Print) { " d = [ 20 40 ]\n" " mean: 1 elements\n" " x0: 20 40\n" - " logNormalizationConstant: -4.0351\n" + " logNormalizationConstant: -4.03510164\n" "isotropic dim=2 sigma=3\n"; EXPECT(assert_print_equal(expected, conditional, "GaussianConditional")); diff --git a/gtsam/sfm/tests/testShonanAveraging.cpp b/gtsam/sfm/tests/testShonanAveraging.cpp index dfa725ab6d..63b4eae5cd 100644 --- a/gtsam/sfm/tests/testShonanAveraging.cpp +++ b/gtsam/sfm/tests/testShonanAveraging.cpp @@ -205,14 +205,20 @@ TEST(ShonanAveraging3, CheckWithEigen) { ShonanAveraging3::LiftwithDescent(4, Qstar3, descentDirection); EXPECT_LONGS_EQUAL(5, initialQ4.size()); - // TODO(frank): uncomment this regression test: currently not repeatable - // across platforms. - // Matrix expected(4, 4); - // expected << 0.0459224, -0.688689, -0.216922, 0.690321, // - // 0.92381, 0.191931, 0.255854, 0.21042, // - // -0.376669, 0.301589, 0.687953, 0.542111, // - // -0.0508588, 0.630804, -0.643587, 0.43046; - // EXPECT(assert_equal(SOn(expected), initialQ4.at(0), 1e-5)); + Matrix expected(4, 4); +#if __APPLE__ || _WIN32 + expected << 0.0459224, -0.688689, -0.216922, 0.690321, // + 0.92381, 0.191931, 0.255854, 0.21042, // + -0.376669, 0.301589, 0.687953, 0.542111, // + -0.0508588, 0.630804, -0.643587, 0.43046; +#elif __linux__ + expected << 0.0459224, -0.688689, -0.216922, 0.690321, // + 0.92381, 0.191931, 0.255854, 0.21042, // + -0.376669, 0.301589, 0.687953, 0.542111, // + -0.0508588, 0.630804, -0.643587, 0.43046; +#endif + + EXPECT(assert_equal(SOn(expected), initialQ4.at(0), 1e-5)); } /* ************************************************************************* */ From d4726cfd1f15efaead1a32f15fbb1ed309cdaaae Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 9 Jan 2025 08:57:45 -0500 Subject: [PATCH 12/19] fix some regressions --- gtsam/hybrid/tests/testHybridBayesNet.cpp | 2 ++ gtsam/linear/tests/testGaussianConditional.cpp | 2 +- gtsam/sfm/tests/testShonanAveraging.cpp | 16 ++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index a5bea4292a..6b69e11984 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -573,6 +573,8 @@ TEST(HybridBayesNet, Sampling) { expected.insert({X(1), Vector1(-0.526464)}); #endif + std::cout << std::setprecision(12); + average_continuous.scale(1.0 / num_samples).print(); EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); } diff --git a/gtsam/linear/tests/testGaussianConditional.cpp b/gtsam/linear/tests/testGaussianConditional.cpp index ad6a8ffe20..0252368eae 100644 --- a/gtsam/linear/tests/testGaussianConditional.cpp +++ b/gtsam/linear/tests/testGaussianConditional.cpp @@ -521,7 +521,7 @@ TEST(GaussianConditional, Print) { " d = [ 20 40 ]\n" " mean: 1 elements\n" " x0: 20 40\n" - " logNormalizationConstant: -4.03510164\n" + " logNormalizationConstant: -4.0351\n" "isotropic dim=2 sigma=3\n"; EXPECT(assert_print_equal(expected, conditional, "GaussianConditional")); diff --git a/gtsam/sfm/tests/testShonanAveraging.cpp b/gtsam/sfm/tests/testShonanAveraging.cpp index 63b4eae5cd..4ea30c9e87 100644 --- a/gtsam/sfm/tests/testShonanAveraging.cpp +++ b/gtsam/sfm/tests/testShonanAveraging.cpp @@ -207,15 +207,15 @@ TEST(ShonanAveraging3, CheckWithEigen) { Matrix expected(4, 4); #if __APPLE__ || _WIN32 - expected << 0.0459224, -0.688689, -0.216922, 0.690321, // - 0.92381, 0.191931, 0.255854, 0.21042, // - -0.376669, 0.301589, 0.687953, 0.542111, // - -0.0508588, 0.630804, -0.643587, 0.43046; + expected << 0.145767, -0.938445, 0.135713, -0.282233, // + 0.780348, -0.0104323, 0.266238, 0.565743, // + -0.383624, 0.0434887, 0.917211, 0.0983088, // + -0.471849, -0.342523, -0.263482, 0.768514; #elif __linux__ - expected << 0.0459224, -0.688689, -0.216922, 0.690321, // - 0.92381, 0.191931, 0.255854, 0.21042, // - -0.376669, 0.301589, 0.687953, 0.542111, // - -0.0508588, 0.630804, -0.643587, 0.43046; + expected << 0.100724, -0.987231, 0.104092, 0.0662867, // + 0.571527, 0.0292782, 0.226546, -0.788147, // + -0.349294, 0.064102, 0.93465, 0.0177471, // + 0.735667, 0.142857, 0.253519, 0.611649; #endif EXPECT(assert_equal(SOn(expected), initialQ4.at(0), 1e-5)); From cb2be68d051473448cc6b66694cc678f4034eea3 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 9 Jan 2025 09:28:06 -0500 Subject: [PATCH 13/19] fix test with better precision --- gtsam/hybrid/tests/testHybridBayesNet.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index 6b69e11984..c313708f43 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -569,12 +569,10 @@ TEST(HybridBayesNet, Sampling) { expected.insert({X(0), Vector1(-0.0131207162712)}); expected.insert({X(1), Vector1(-0.499026377568)}); #elif __linux__ - expected.insert({X(0), Vector1(-0.00799425)}); - expected.insert({X(1), Vector1(-0.526464)}); + expected.insert({X(0), Vector1(-0.00799425182219)}); + expected.insert({X(1), Vector1(-0.526463854268)}); #endif - std::cout << std::setprecision(12); - average_continuous.scale(1.0 / num_samples).print(); EXPECT(assert_equal(expected, average_continuous.scale(1.0 / num_samples))); } From 556ed9bfcc55888a14855a68cbaf385b3282f26b Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 9 Jan 2025 09:31:12 -0500 Subject: [PATCH 14/19] separate Windows regression for Shonan Averaging --- gtsam/sfm/tests/testShonanAveraging.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gtsam/sfm/tests/testShonanAveraging.cpp b/gtsam/sfm/tests/testShonanAveraging.cpp index 4ea30c9e87..e297678b8e 100644 --- a/gtsam/sfm/tests/testShonanAveraging.cpp +++ b/gtsam/sfm/tests/testShonanAveraging.cpp @@ -206,7 +206,7 @@ TEST(ShonanAveraging3, CheckWithEigen) { EXPECT_LONGS_EQUAL(5, initialQ4.size()); Matrix expected(4, 4); -#if __APPLE__ || _WIN32 +#if __APPLE__ expected << 0.145767, -0.938445, 0.135713, -0.282233, // 0.780348, -0.0104323, 0.266238, 0.565743, // -0.383624, 0.0434887, 0.917211, 0.0983088, // @@ -216,6 +216,11 @@ TEST(ShonanAveraging3, CheckWithEigen) { 0.571527, 0.0292782, 0.226546, -0.788147, // -0.349294, 0.064102, 0.93465, 0.0177471, // 0.735667, 0.142857, 0.253519, 0.611649; +#elif _WIN32 + expected << 0.0825862, -0.645931, 0.271896, 0.708537, // + 0.927285, -0.0156335, 0.291603, -0.234236, // + -0.36419, -0.132115, 0.831933, -0.39724, // + 0.0262425, 0.751715, 0.385912, 0.534143; #endif EXPECT(assert_equal(SOn(expected), initialQ4.at(0), 1e-5)); From 438bead4fdf1a04ab598c29fa1846436510d9dca Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 9 Jan 2025 10:45:23 -0500 Subject: [PATCH 15/19] small cleanup --- gtsam/hybrid/tests/testHybridBayesNet.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index c313708f43..784d9c95f6 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -557,11 +557,7 @@ TEST(HybridBayesNet, Sampling) { double discrete_sum = std::accumulate(discrete_samples.begin(), discrete_samples.end(), decltype(discrete_samples)::value_type(0)); -#if __APPLE__ || _WIN32 - EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); -#elif __linux__ EXPECT_DOUBLES_EQUAL(0.477, discrete_sum / num_samples, 1e-9); -#endif VectorValues expected; // regression for specific RNG seed From 9142200a6e577f5a59d1f0904228cd000274abeb Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 10 Jan 2025 10:27:34 -0500 Subject: [PATCH 16/19] Revert "suppress newer GCC warnings in Eigen" This reverts commit b7e60c4043b39dd8d31510376e34bcb13f8cfa64. --- gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h | 1 - 1 file changed, 1 deletion(-) diff --git a/gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h b/gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h index aa798c0939..fe0cfec0bc 100755 --- a/gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h +++ b/gtsam/3rdparty/Eigen/Eigen/src/Core/util/DisableStupidWarnings.h @@ -66,7 +66,6 @@ #endif #if __GNUC__>=6 #pragma GCC diagnostic ignored "-Wignored-attributes" - #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif #if __GNUC__==7 // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325 From 9910bb63623b5b0423b4b032da81814fdef349c4 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 10 Jan 2025 10:28:36 -0500 Subject: [PATCH 17/19] Revert "Helper macro for cout printing" This reverts commit 28065b737b62c3b0c32119ba73c6058c8e99f147. --- gtsam/base/Testable.h | 1 - 1 file changed, 1 deletion(-) diff --git a/gtsam/base/Testable.h b/gtsam/base/Testable.h index eb8d851d1a..8eb6326c05 100644 --- a/gtsam/base/Testable.h +++ b/gtsam/base/Testable.h @@ -41,7 +41,6 @@ #include #define GTSAM_PRINT(x)((x).print(#x)) -#define GTSAM_COUT(x) (std::cout << #x ": " << x << std::endl) namespace gtsam { From fbe4ad1dc92a952c6529dfdde11be2ac3800663f Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 10 Jan 2025 10:29:58 -0500 Subject: [PATCH 18/19] common Apple and Windows assertions --- gtsam/linear/tests/testGaussianBayesNet.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gtsam/linear/tests/testGaussianBayesNet.cpp b/gtsam/linear/tests/testGaussianBayesNet.cpp index 32534a1e7a..6e45765410 100644 --- a/gtsam/linear/tests/testGaussianBayesNet.cpp +++ b/gtsam/linear/tests/testGaussianBayesNet.cpp @@ -188,15 +188,12 @@ TEST(GaussianBayesNet, sample) { EXPECT_LONGS_EQUAL(2, actual.size()); // regressions -#ifdef __APPLE__ +#ifdef __APPLE__ || _WIN32 EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); #elif __linux__ EXPECT(assert_equal(Vector2(20.0070499, 39.9942591), actual[X(1)], 1e-5)); EXPECT(assert_equal(Vector2(109.976501, 229.990945), actual[X(0)], 1e-5)); -#elif _WIN32 - EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); - EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); #endif } From 62b0ed6678ae4fdbdb583fa615ad7fdde5c143bc Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 10 Jan 2025 11:11:03 -0500 Subject: [PATCH 19/19] change from ifdef to if --- gtsam/linear/tests/testGaussianBayesNet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/linear/tests/testGaussianBayesNet.cpp b/gtsam/linear/tests/testGaussianBayesNet.cpp index 6e45765410..587597cf14 100644 --- a/gtsam/linear/tests/testGaussianBayesNet.cpp +++ b/gtsam/linear/tests/testGaussianBayesNet.cpp @@ -188,7 +188,7 @@ TEST(GaussianBayesNet, sample) { EXPECT_LONGS_EQUAL(2, actual.size()); // regressions -#ifdef __APPLE__ || _WIN32 +#if __APPLE__ || _WIN32 EXPECT(assert_equal(Vector2(20.0129382, 40.0039798), actual[X(1)], 1e-5)); EXPECT(assert_equal(Vector2(110.032083, 230.039811), actual[X(0)], 1e-5)); #elif __linux__