From 2a1cf9e639545effe6a2a01f1c23064d8827e211 Mon Sep 17 00:00:00 2001 From: Wilczman Date: Thu, 18 Sep 2025 10:49:48 +0200 Subject: [PATCH] perf: fix double AAt computation and optimize eigenvalue calculation in pseudo_inverse_stacked - Remove duplicate AAt matrix multiplication (lines 37-38) - Replace full eigendecomposition with matrix 2-norm for largest eigenvalue - Expected improved performance (for me it was 20%-40% less time for computation). --- src/cedalion/imagereco/solver.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cedalion/imagereco/solver.py b/src/cedalion/imagereco/solver.py index 7cfb1f1c..ddcfe5d2 100644 --- a/src/cedalion/imagereco/solver.py +++ b/src/cedalion/imagereco/solver.py @@ -50,11 +50,10 @@ def pseudo_inverse_stacked( AAt = A_hat @ A_hat.T At = (Linv[:, np.newaxis]**2) * Adot.values.T else: # no spatial regularization - AAt = Adot.values @ Adot.values.T AAt = Adot.values @ Adot.values.T At = Adot.values.T - highest_eigenvalue = np.linalg.eig(AAt)[0][0].real + highest_eigenvalue = np.linalg.norm(AAt, ord=2) lambda_meas = alpha * highest_eigenvalue if Cmeas is None: B = At @ np.linalg.pinv(AAt + lambda_meas * np.eye(AAt.shape[0]))