From edf95a05bf31e95691c71aa98f897daff2a2e3be Mon Sep 17 00:00:00 2001 From: zyyk78 <109540139+zyyk78@users.noreply.github.com> Date: Mon, 10 Nov 2025 21:38:16 +0800 Subject: [PATCH] Improve linear solve with fallback to least squares Added error handling for linear solve failure, using least squares as fallback. --- caiman/utils/stats.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/caiman/utils/stats.py b/caiman/utils/stats.py index cf1e3d596..b6f2db4b7 100644 --- a/caiman/utils/stats.py +++ b/caiman/utils/stats.py @@ -329,4 +329,10 @@ def pd_solve(a, b): if info == 0: return dpotrs(L, b)[0] else: - return np.linalg.solve(a, b) + try: + pdsv = np.linalg.solve(a, b) + except LinAlgError : + logger = logging.getLogger("caiman") + logger.warning("Unable to solve directly, using least squares instead.") + pdsv = np.linalg.lstsq(a, b, rcond=None)[0] + return pdsv