From 4465cb781f5e7f789c9bcd12900471b245e37822 Mon Sep 17 00:00:00 2001
From: Thibault Hallouin <thibault.hallouin@inrae.fr>
Date: Fri, 9 Jun 2023 14:07:16 +0200
Subject: [PATCH] check rank of data structures only if tensors

for arrays, rank is not applicable, so it should not be checked
---
 include/evalhyd/evald.hpp | 26 ++++++++++++++++----------
 include/evalhyd/evalp.hpp | 37 ++++++++++++++++++++++++-------------
 2 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/include/evalhyd/evald.hpp b/include/evalhyd/evald.hpp
index 19cbdbc..a2e9ef3 100644
--- a/include/evalhyd/evald.hpp
+++ b/include/evalhyd/evald.hpp
@@ -210,19 +210,25 @@ namespace evalhyd
                     xtl::missing<const std::vector<std::string>>()
     )
     {
-        // check ranks of tensors
-        if (xt::get_rank<XD2>::value != 2)
+        // check ranks of expressions if they are tensors
+        if (xt::get_rank<XD2>::value != SIZE_MAX)
         {
-            throw std::runtime_error(
-                    "observations and/or predictions and/or thresholds "
-                    "are not two-dimensional"
-            );
+            if (xt::get_rank<XD2>::value != 2)
+            {
+                throw std::runtime_error(
+                        "observations and/or predictions and/or thresholds "
+                        "are not two-dimensional"
+                );
+            }
         }
-        if (xt::get_rank<XB3>::value != 3)
+        if (xt::get_rank<XB3>::value != SIZE_MAX)
         {
-            throw std::runtime_error(
-                    "temporal masks are not three-dimensional"
-            );
+            if (xt::get_rank<XB3>::value != 3)
+            {
+                throw std::runtime_error(
+                        "temporal masks are not three-dimensional"
+                );
+            }
         }
 
         // retrieve real types of the expressions
diff --git a/include/evalhyd/evalp.hpp b/include/evalhyd/evalp.hpp
index 4fa7a2b..fb64692 100644
--- a/include/evalhyd/evalp.hpp
+++ b/include/evalhyd/evalp.hpp
@@ -190,24 +190,35 @@ namespace evalhyd
                     xtl::missing<const std::vector<std::string>>()
     )
     {
-        // check ranks of tensors
-        if (xt::get_rank<XD2>::value != 2)
+        // check ranks of expressions if they are tensors
+        if (xt::get_rank<XD2>::value != SIZE_MAX)
         {
-            throw std::runtime_error(
-                    "observations and/or thresholds are not two-dimensional"
-            );
+            if (xt::get_rank<XD2>::value != 2)
+            {
+                throw std::runtime_error(
+                        "observations and/or thresholds are not two-dimensional"
+                );
+            }
         }
-        if (xt::get_rank<XD4>::value != 4)
+
+        if (xt::get_rank<XD4>::value != SIZE_MAX)
         {
-            throw std::runtime_error(
-                    "predictions are not four-dimensional"
-            );
+            if (xt::get_rank<XD4>::value != 4)
+            {
+                throw std::runtime_error(
+                        "predictions are not four-dimensional"
+                );
+            }
         }
-        if (xt::get_rank<XB4>::value != 4)
+
+        if (xt::get_rank<XB4>::value != SIZE_MAX)
         {
-            throw std::runtime_error(
-                    "temporal masks are not four-dimensional"
-            );
+            if (xt::get_rank<XB4>::value != 4)
+            {
+                throw std::runtime_error(
+                        "temporal masks are not four-dimensional"
+                );
+            }
         }
 
         // retrieve real types of the expressions
-- 
GitLab