From e1ba31ea7238a439fab81e2274ae9eeaab377c2f Mon Sep 17 00:00:00 2001 From: devvaibhav455 Date: Sat, 7 Mar 2026 17:43:40 -0500 Subject: [PATCH] Avoided np.diag 2.4.0 memory leak bug #30862 --- filterpy/kalman/unscented_transform.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/filterpy/kalman/unscented_transform.py b/filterpy/kalman/unscented_transform.py index 871add0b..f835de3a 100644 --- a/filterpy/kalman/unscented_transform.py +++ b/filterpy/kalman/unscented_transform.py @@ -115,7 +115,8 @@ def residual(a, b): # this is the fast way to do this - see 'else' for the slow way if residual_fn is np.subtract or residual_fn is None: y = sigmas - x[np.newaxis, :] - P = np.dot(y.T, np.dot(np.diag(Wc), y)) + #P = np.dot(y.T, np.dot(np.diag(Wc), y)) #Numpy 2.4.0 memory leak in np.diag https://github.com/numpy/numpy/issues/30862 + P = y.T @ (y * Wc[:, None]) # Achieves the same using broadcasting, avoids memory leak bug, saves memory and is faster else: P = np.zeros((n, n)) for k in range(kmax):