From 5afc00c2fdb674770c348757bee761c800b761f8 Mon Sep 17 00:00:00 2001 From: Joan <43519278+joan-yanqiong@users.noreply.github.com> Date: Fri, 17 May 2024 17:38:20 -0400 Subject: [PATCH] Update main.py try proposed fix according to https://github.com/StatBiomed/SpatialDM/issues/25#issuecomment-1913475294 --- spatialdm/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spatialdm/main.py b/spatialdm/main.py index ba18cd4..6d52839 100644 --- a/spatialdm/main.py +++ b/spatialdm/main.py @@ -38,7 +38,14 @@ def _Euclidean_to_RBF(X, l, singlecell=single_cell): # At single-cell resolution, no within-spot communications if singlecell: - np.fill_diagonal(rbf_d, 0) + # Convert csr_matrix to lil_matrix for efficient row operations + rbf_d_lil = rbf_d.tolil() + + # Set diagonal elements to zero + rbf_d_lil.setdiag(0) + + # Convert back to csr_matrix if needed + rbf_d = rbf_d_lil.tocsr() else: rbf_d.setdiag(np.exp(-X.diagonal()**2 / (2 * l ** 2)))