Problem
The pseudo_inverse_stacked() function in cedalion has two major performance bottlenecks that cause significant slowdowns when working with large sensitivity matrices:
- Duplicate matrix multiplication: Lines 37-38 compute
AAt = Adot.values @ Adot.values.T twice
- Inefficient eigenvalue calculation: Uses full eigendecomposition
np.linalg.eig() when only the largest eigenvalue is needed
Current Code Location
src/cedalion/imagereco/solver.py -> pseudo_inverse_stacked() around lines 37-38 and eigenvalue computation
Proposed Solution
- Remove the duplicate
AAt computation
- Replace
np.linalg.eig(AAt)[0][0].real with np.linalg.norm(AAt, ord=2) for largest eigenvalue