From bb99f8d0e89ffc790314048466a54cad51c1a1df Mon Sep 17 00:00:00 2001 From: Garrett Wright Date: Thu, 15 Jan 2026 14:17:54 -0500 Subject: [PATCH] Make np `where` args explicit with `out=`. --- src/aspire/classification/legacy_implementations.py | 2 +- src/aspire/utils/matrix.py | 2 +- tests/test_matrix.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aspire/classification/legacy_implementations.py b/src/aspire/classification/legacy_implementations.py index 2809a175ce..6d7feac211 100644 --- a/src/aspire/classification/legacy_implementations.py +++ b/src/aspire/classification/legacy_implementations.py @@ -145,7 +145,7 @@ def bispec_2drot_large(coef, freqs, eigval, alpha, sample_n, seed=None): # This became a problem with very noisy images... p = np.power(eigval, alpha) mask = np.where(p, p, -1) # taking the log in the next step will yield a 0 - m = np.exp(o1 * np.log(p, where=(mask > 0))) + m = np.exp(o1 * np.log(p, where=(mask > 0), out=None)) p_m = m / m.sum() x = random(size=len(m), seed=seed) m_id = np.where(x < sample_n * p_m)[0] diff --git a/src/aspire/utils/matrix.py b/src/aspire/utils/matrix.py index d5d495365c..dca1ed2e89 100644 --- a/src/aspire/utils/matrix.py +++ b/src/aspire/utils/matrix.py @@ -364,7 +364,7 @@ def fix_signs(u): # Create array of sign corrections signs = np.take_along_axis(u, np.expand_dims(index_array, axis=0), axis=0).squeeze() _abs = np.absolute(signs) - signs = np.divide(_abs, signs, where=_abs != 0) + np.divide(_abs, signs, out=signs, where=_abs != 0) # Now we only care about the sign +1/-1. # The following corrects for any numerical division noise, diff --git a/tests/test_matrix.py b/tests/test_matrix.py index 540c86a377..f40a77e7b4 100644 --- a/tests/test_matrix.py +++ b/tests/test_matrix.py @@ -190,7 +190,7 @@ def testFixSigns(self): """ # Create simple array - x = np.arange(25).reshape(5, 5) + x = np.arange(25, dtype=np.float32).reshape(5, 5) # Set diagonal elements = -1 x[np.diag_indices_from(x)] *= -1 # Negate largest elem (last row) of first col