From f353fdaecb7bc9e0c82629e4703e33e5a52a660f Mon Sep 17 00:00:00 2001 From: epnev Date: Wed, 21 Aug 2019 13:58:53 -0400 Subject: [PATCH] prevent division by zero warnings --- caiman/source_extraction/cnmf/estimates.py | 2 +- caiman/source_extraction/cnmf/map_reduce.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/caiman/source_extraction/cnmf/estimates.py b/caiman/source_extraction/cnmf/estimates.py index 9c4bf4a0e..432c670db 100644 --- a/caiman/source_extraction/cnmf/estimates.py +++ b/caiman/source_extraction/cnmf/estimates.py @@ -721,7 +721,7 @@ def normalize_components(self): nA = np.sqrt(np.ravel(self.A.power(2).sum(axis=0))) nA_mat = scipy.sparse.spdiags(nA, 0, nA.shape[0], nA.shape[0]) - nA_inv_mat = scipy.sparse.spdiags(1. / nA, 0, nA.shape[0], nA.shape[0]) + nA_inv_mat = scipy.sparse.spdiags(1. / (nA + np.finfo(np.float32).eps), 0, nA.shape[0], nA.shape[0]) self.A = self.A * nA_inv_mat self.C = nA_mat * self.C if self.YrA is not None: diff --git a/caiman/source_extraction/cnmf/map_reduce.py b/caiman/source_extraction/cnmf/map_reduce.py index 83209e77e..63844a62a 100644 --- a/caiman/source_extraction/cnmf/map_reduce.py +++ b/caiman/source_extraction/cnmf/map_reduce.py @@ -408,7 +408,7 @@ def run_CNMF_patches(file_name, shape, params, gnb=1, dview=None, logging.info("Constructing background") Im = scipy.sparse.csr_matrix( - (1. / mask, (np.arange(d), np.arange(d))), dtype=np.float32) + (1. / (mask + np.finfo(np.float32).eps), (np.arange(d), np.arange(d))), dtype=np.float32) if not del_duplicates: A_tot = Im.dot(A_tot)