From 0b1a9cd6cf79e3a144d5d5172a2112cb444a6942 Mon Sep 17 00:00:00 2001
From: Thibault Hallouin <thibault.hallouin@inrae.fr>
Date: Wed, 25 Jan 2023 17:45:52 +0100
Subject: [PATCH] skip ranks-based metrics in conditional masking tests

because of the random process in the rank computations, and the
different input tensor sizes
---
 tests/test_probabilist.cpp | 48 +++++++++++++++++++++++++++++++++++---
 1 file changed, 45 insertions(+), 3 deletions(-)

diff --git a/tests/test_probabilist.cpp b/tests/test_probabilist.cpp
index 816f1bd..e25233e 100644
--- a/tests/test_probabilist.cpp
+++ b/tests/test_probabilist.cpp
@@ -606,10 +606,24 @@ TEST(ProbabilistTests, TestMaskingConditions)
     // check results are identical
     for (std::size_t m = 0; m < all_metrics_p.size(); m++)
     {
+        // ---------------------------------------------------------------------
+        // /!\ skip ranks-based metrics because it contains a random process
+        //     for which setting the seed will not work because the time series
+        //     lengths are different between "conditioned" and "preconditioned",
+        //     which results in different tensor shapes, and hence in different
+        //     random ranks for ties
+        if ((all_metrics_p[m] == "RANK_DIAG")
+            || (all_metrics_p[m] == "DS")
+            || (all_metrics_p[m] == "AS"))
+        {
+            continue;
+        }
+        // ---------------------------------------------------------------------
+
         EXPECT_TRUE(
                 xt::all(xt::isclose(metrics_q_conditioned[m],
                                     metrics_q_preconditioned[m],
-                                    1e-05, 1e-06, true))
+                                    1e-05, 1e-08, true))
         ) << "Failure for (" << all_metrics_p[m] << ")";
     }
 
@@ -647,10 +661,24 @@ TEST(ProbabilistTests, TestMaskingConditions)
     // check results are identical
     for (std::size_t m = 0; m < all_metrics_p.size(); m++)
     {
+        // ---------------------------------------------------------------------
+        // /!\ skip ranks-based metrics because it contains a random process
+        //     for which setting the seed will not work because the time series
+        //     lengths are different between "conditioned" and "preconditioned",
+        //     which results in different tensor shapes, and hence in different
+        //     random ranks for ties
+        if ((all_metrics_p[m] == "RANK_DIAG")
+            || (all_metrics_p[m] == "DS")
+            || (all_metrics_p[m] == "AS"))
+        {
+            continue;
+        }
+        // ---------------------------------------------------------------------
+
         EXPECT_TRUE(
                 xt::all(xt::isclose(metrics_q_conditioned_[m],
                                     metrics_q_preconditioned_[m],
-                                    1e-05, 1e-06, true))
+                                    1e-05, 1e-08, true))
         ) << "Failure for (" << all_metrics_p[m] << ")";
     }
 
@@ -685,10 +713,24 @@ TEST(ProbabilistTests, TestMaskingConditions)
     // check results are identical
     for (std::size_t m = 0; m < all_metrics_p.size(); m++)
     {
+        // ---------------------------------------------------------------------
+        // /!\ skip ranks-based metrics because it contains a random process
+        //     for which setting the seed will not work because the time series
+        //     lengths are different between "conditioned" and "subset",
+        //     which results in different tensor shapes, and hence in different
+        //     random ranks for ties
+        if ((all_metrics_p[m] == "RANK_DIAG")
+            || (all_metrics_p[m] == "DS")
+            || (all_metrics_p[m] == "AS"))
+        {
+            continue;
+        }
+        // ---------------------------------------------------------------------
+
         EXPECT_TRUE(
                 xt::all(xt::isclose(metrics_t_conditioned[m],
                                     metrics_t_subset[m],
-                                    1e-05, 1e-06, true))
+                                    1e-05, 1e-08, true))
         ) << "Failure for (" << all_metrics_p[m] << ")";
     }
 }
-- 
GitLab