From 61d1e3ac57f5d19f67e0b7a7ef5e4f8fba6ab8bc Mon Sep 17 00:00:00 2001
From: fbourgin <francois.bourgin@inrae.fr>
Date: Tue, 8 Apr 2025 14:28:15 +0200
Subject: [PATCH] use broadcasting to find the q_lvl indices in q_prd

---
 include/evalhyd/detail/probabilist/intervals.hpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/evalhyd/detail/probabilist/intervals.hpp b/include/evalhyd/detail/probabilist/intervals.hpp
index 21316f2..f5ed846 100644
--- a/include/evalhyd/detail/probabilist/intervals.hpp
+++ b/include/evalhyd/detail/probabilist/intervals.hpp
@@ -66,7 +66,9 @@ namespace evalhyd
                 {   
                     for (std::size_t i = 0; i < n_itv; i++)
                     {
-                    auto res = xt::where(xt::equal(xt::view(quantiles, i), q_lvl));
+                    auto a = xt::broadcast(xt::view(quantiles, i), std::vector<std::size_t>({q_lvl.size(), 2}));
+                    auto b = xt::broadcast(q_lvl, std::vector<std::size_t>({2, q_lvl.size()}));
+                    auto res = xt::where(xt::equal(a, xt::transpose(b));
                     if (res.size() != 2) 
                     {
                         throw std::runtime_error(
@@ -76,9 +78,9 @@ namespace evalhyd
                     } else 
                     {
                         xt::view(itv_bnds, xt::all(), xt::all(), i, 0, xt::all()) =
-                                xt::view(q_prd, res[0]);
+                                xt::view(q_prd, std::min(res[0][1], res[1][1]));
                         xt::view(itv_bnds, xt::all(), xt::all(), i, 1, xt::all()) = 
-                                xt::view(q_prd, res[1]);
+                                xt::view(q_prd, std::max(res[0][1], res[1][1]));
                     }
                     }
                 }
-- 
GitLab