From a2957cb3f6e674df6cf5e148870f74c9d53251b4 Mon Sep 17 00:00:00 2001 From: Thibault Hallouin <thibault.hallouin@inrae.fr> Date: Wed, 10 Aug 2022 17:28:39 +0200 Subject: [PATCH] add unittest to check NaN assignment works since `xt::allclose` does not have a *equal_nan* like `xt::isclose` (see https://github.com/xtensor-stack/xtensor/issues/1995), the check is a bit more convoluted than before... --- tests/test_probabilist.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/test_probabilist.cpp b/tests/test_probabilist.cpp index af4699d..2a6dba7 100644 --- a/tests/test_probabilist.cpp +++ b/tests/test_probabilist.cpp @@ -22,7 +22,7 @@ TEST(ProbabilistTests, TestBrier) ifs.close(); // compute scores - xt::xtensor<double, 2> thresholds = {{690, 534, 445}}; + xt::xtensor<double, 2> thresholds = {{690, 534, 445, NAN}}; std::vector<xt::xarray<double>> metrics = evalhyd::evalp( @@ -37,27 +37,41 @@ TEST(ProbabilistTests, TestBrier) // check results // Brier scores xt::xtensor<double, 4> bs = - {{{{0.10615136, 0.07395622, 0.08669186}}}}; - EXPECT_TRUE(xt::allclose(metrics[0], bs)); + {{{{0.10615136, 0.07395622, 0.08669186, NAN}}}}; + EXPECT_TRUE( + xt::sum(xt::isclose(metrics[0], bs, 1e-05, 1e-08, true)) + == xt::xscalar<double>(4) + ); // Brier skill scores xt::xtensor<double, 4> bss = - {{{{0.5705594, 0.6661165, 0.5635126}}}}; - EXPECT_TRUE(xt::allclose(metrics[1], bss)); + {{{{0.5705594, 0.6661165, 0.5635126, NAN}}}}; + EXPECT_TRUE( + xt::sum(xt::isclose(metrics[1], bss, 1e-05, 1e-08, true)) + == xt::xscalar<double>(4) + ); // Brier calibration-refinement decompositions xt::xtensor<double, 5> bs_crd = {{{{{0.011411758, 0.1524456, 0.2471852}, {0.005532413, 0.1530793, 0.2215031}, - {0.010139431, 0.1220601, 0.1986125}}}}}; - EXPECT_TRUE(xt::allclose(metrics[2], bs_crd)); + {0.010139431, 0.1220601, 0.1986125}, + {NAN, NAN, NAN}}}}}; + EXPECT_TRUE( + xt::sum(xt::isclose(metrics[2], bs_crd, 1e-05, 1e-08, true)) + == xt::xscalar<double>(12) + ); // Brier likelihood-base rate decompositions xt::xtensor<double, 5> bs_lbd = {{{{{0.012159881, 0.1506234, 0.2446149}, {0.008031746, 0.1473869, 0.2133114}, - {0.017191279, 0.1048221, 0.1743227}}}}}; - EXPECT_TRUE(xt::allclose(metrics[3], bs_lbd)); + {0.017191279, 0.1048221, 0.1743227}, + {NAN, NAN, NAN}}}}}; + EXPECT_TRUE( + xt::sum(xt::isclose(metrics[3], bs_lbd, 1e-05, 1e-08, true)) + == xt::xscalar<double>(12) + ); } TEST(ProbabilistTests, TestQuantiles) -- GitLab