Skip to content

Commit

Permalink
Improve numpy calculation speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Warren Kretzschmar committed May 8, 2020
1 parent 7c7d8ea commit 4e797cb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4e797cb

Please sign in to comment.