From 81e22f44f0bb2c1aeb156fd6ee9005d840d4cc6c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 20 Dec 2025 00:30:14 +0100 Subject: [PATCH] fix(qav3): do not weight the first pivot if cannot be computed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- quickadapter/user_data/strategies/Utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 521e041..638e2e4 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -535,7 +535,12 @@ def _impute_weights( finite_mask: NDArray[np.bool_] | None = None, default_weight: float = DEFAULT_EXTREMA_WEIGHT, ) -> NDArray[np.floating]: - weights = weights.astype(float, copy=False) + weights = weights.astype(float, copy=True) + + # weights computed by zigzag have NaN on first element if it cannot be computed correctly + if len(weights) > 0 and not np.isfinite(weights[0]): + weights[0] = 0.0 + if finite_mask is None: finite_mask = np.isfinite(weights) @@ -546,9 +551,9 @@ def _impute_weights( if not np.isfinite(median_weight): median_weight = default_weight - weights_out = weights.astype(float, copy=True) - weights_out[~finite_mask] = median_weight - return weights_out + weights[~finite_mask] = median_weight + + return weights def normalize_weights( -- 2.53.0