From 0a16244a46430a133d09a6cd54d9cee6a8cecb1a Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Mon, 13 Jul 2026 14:48:35 +0200 Subject: [PATCH 1/2] Reject non-finite sliding-window weights --- .../smoothers/sliding_window_manifold_mean_smoother.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pyrecest/smoothers/sliding_window_manifold_mean_smoother.py b/src/pyrecest/smoothers/sliding_window_manifold_mean_smoother.py index 1ad9c2a946..cefaf149d0 100644 --- a/src/pyrecest/smoothers/sliding_window_manifold_mean_smoother.py +++ b/src/pyrecest/smoothers/sliding_window_manifold_mean_smoother.py @@ -6,8 +6,9 @@ from functools import partial from operator import index as operator_index +from pyrecest.backend import all as backend_all from pyrecest.backend import any as backend_any -from pyrecest.backend import asarray, concatenate, ndim, stack, sum +from pyrecest.backend import asarray, concatenate, isfinite, ndim, stack, sum from pyrecest.distributions import ( AbstractHypercylindricalDistribution, AbstractHyperhemisphericalDistribution, @@ -92,6 +93,8 @@ def __init__( self.window_weights = asarray(window_weights).reshape(-1) if self.window_weights.shape[0] != self.window_size: raise ValueError("window_weights must have length window_size.") + if not bool(backend_all(isfinite(self.window_weights))): + raise ValueError("window_weights must be finite.") if backend_any(self.window_weights < 0): raise ValueError("window_weights must be non-negative.") if sum(self.window_weights) <= 0: From e7cf6bc82c3b8744b7bcf28818c399fd2a1f7a64 Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Mon, 13 Jul 2026 14:48:43 +0200 Subject: [PATCH 2/2] Add non-finite sliding-window weight regression --- ...anifold_mean_smoother_nonfinite_weights.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/smoothers/test_sliding_window_manifold_mean_smoother_nonfinite_weights.py diff --git a/tests/smoothers/test_sliding_window_manifold_mean_smoother_nonfinite_weights.py b/tests/smoothers/test_sliding_window_manifold_mean_smoother_nonfinite_weights.py new file mode 100644 index 0000000000..3be7fc452e --- /dev/null +++ b/tests/smoothers/test_sliding_window_manifold_mean_smoother_nonfinite_weights.py @@ -0,0 +1,26 @@ +import unittest + +import numpy as np +from pyrecest.backend import array +from pyrecest.smoothers import SlidingWindowManifoldMeanSmoother + + +class SlidingWindowManifoldMeanSmootherNonfiniteWeightsTest(unittest.TestCase): + def test_rejects_nonfinite_window_weights(self): + invalid_weight_vectors = ( + array([1.0, np.nan, 1.0]), + array([1.0, np.inf, 1.0]), + array([1.0, -np.inf, 1.0]), + ) + + for window_weights in invalid_weight_vectors: + with self.subTest(window_weights=window_weights): + with self.assertRaisesRegex(ValueError, "finite"): + SlidingWindowManifoldMeanSmoother( + window_size=3, + window_weights=window_weights, + ) + + +if __name__ == "__main__": + unittest.main()