From 7e46542163cbc30d02a3b0453fb667e7ee33e691 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Mon, 14 Apr 2025 19:28:35 -0600 Subject: [PATCH 1/2] Modified the `gauss-sidel` method of `regridding.fill()` to accept a `guess` argument which allows the user to provide a starting point. --- regridding/_fill/_fill.py | 1 + regridding/_fill/_gauss_seidel.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/regridding/_fill/_fill.py b/regridding/_fill/_fill.py index 578f4b7..89cb226 100644 --- a/regridding/_fill/_fill.py +++ b/regridding/_fill/_fill.py @@ -34,6 +34,7 @@ def fill( kwargs Additional method-specific keyword arguments. For the Gauss-Seidel method, the valid keyword arguments are: + - ``guess=np.median(a[where], axis)``, the first guess at the fill value. - ``num_iterations=100``, the number of red-black Gauss-Seidel iterations to perform. Examples diff --git a/regridding/_fill/_gauss_seidel.py b/regridding/_fill/_gauss_seidel.py index b4278f7..fe6bffc 100644 --- a/regridding/_fill/_gauss_seidel.py +++ b/regridding/_fill/_gauss_seidel.py @@ -12,14 +12,18 @@ def fill_gauss_seidel( a: np.ndarray, where: np.ndarray, axis: None | int | Sequence[int], + guess: None | float | np.ndarray = 0, num_iterations: int = 100, ) -> np.ndarray: a = a.copy() - a, where = np.broadcast_arrays(a, where, subok=True) + if guess is None: + guess = np.median(a[where], axis=axis) - a[where] = 0 + a, where, guess = np.broadcast_arrays(a, where, guess, subok=True) + + a[where] = guess[where] axis = regridding._util._normalize_axis(axis=axis, ndim=a.ndim) axis_numba = ~np.arange(len(axis))[::-1] From dcb6592d509675c7cf2a1465616a82b33d8f9268 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Mon, 14 Apr 2025 19:37:19 -0600 Subject: [PATCH 2/2] fixes --- regridding/_fill/_gauss_seidel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regridding/_fill/_gauss_seidel.py b/regridding/_fill/_gauss_seidel.py index fe6bffc..40c3644 100644 --- a/regridding/_fill/_gauss_seidel.py +++ b/regridding/_fill/_gauss_seidel.py @@ -12,7 +12,7 @@ def fill_gauss_seidel( a: np.ndarray, where: np.ndarray, axis: None | int | Sequence[int], - guess: None | float | np.ndarray = 0, + guess: None | float | np.ndarray = None, num_iterations: int = 100, ) -> np.ndarray: