From 41280d4d1e32a2545d18e7a6500f22a42ad36736 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 8 Jan 2025 18:33:46 -0500 Subject: [PATCH] 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 5f54c57b6..a5bea4292 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 570296e8b..32534a1e7 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 2213ae872..ad6a8ffe2 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 dfa725ab6..63b4eae5c 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)); } /* ************************************************************************* */