From 4e797cbe70fd8d058271a9ca36e8b5fc996408e8 Mon Sep 17 00:00:00 2001 From: Warren Kretzschmar Date: Fri, 8 May 2020 09:11:38 +0200 Subject: [PATCH] Improve numpy calculation speed --- src/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils.py b/src/utils.py index 567cf4b..296e922 100644 --- a/src/utils.py +++ b/src/utils.py @@ -110,10 +110,15 @@ def Create_Factorial_List(self, max_allele_cnt): def Create_nCr_mat(self, max_allele_cnt, factorial_list): ncr_mat = np.zeros((max_allele_cnt, max_allele_cnt), dtype=np.longdouble) + ncr_mat2 = np.zeros((max_allele_cnt, max_allele_cnt), dtype=np.longdouble) + factorial_list = np.array(factorial_list) for i in range(max_allele_cnt): + ncr_mat2[:, i] = factorial_list / \ + (factorial_list[i] * np.roll(factorial_list, i)) for j in range(max_allele_cnt): ncr_mat[j, i] = factorial_list[j] / \ (factorial_list[i] * factorial_list[j - i]) + assert np.allclose(ncr_mat, ncr_mat2) return ncr_mat def CheckAltAllele(self, single_cell_dict):