Skip to content

Commit 27f30ef

Browse files
committed
decythonize viterbi_sort
1 parent 76b773c commit 27f30ef

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

H2MM_C/H2MM_C.pyx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,7 +3411,7 @@ def viterbi_path(h2mm_model h_mod, indexes, times, num_cores=None):
34113411
return out
34123412

34133413

3414-
def viterbi_sort(h2mm_model hmod, indexes, times, num_cores=None):
3414+
def viterbi_sort(hmod, indexes, times, num_cores=None):
34153415
"""
34163416
An all inclusive viterbi processing algorithm. Returns the ICL, the most likely
34173417
state path, posterior probabilities, and a host of information sorted by
@@ -3505,14 +3505,9 @@ def viterbi_sort(h2mm_model hmod, indexes, times, num_cores=None):
35053505
dwell, the columns correspond to the counts of each photon stream.
35063506
"""
35073507
# use viterbi to find most likely path based on posterior probability through all bursts
3508-
cdef Py_ssize_t i, b, e, st
3509-
cdef list paths, scale
3510-
cdef cnp.ndarray[double,ndim=1] ll
3511-
cdef double icl
35123508
paths, scale, ll, icl = viterbi_path(hmod,indexes,times,num_cores=num_cores)
3513-
35143509
# sorting bursts based on which dwells occur in them
3515-
cdef cnp.ndarray[int, ndim=1] burst_type = np.zeros(len(indexes),dtype=int)
3510+
burst_type = np.zeros(len(indexes),dtype=int)
35163511
for i in range(len(indexes)):
35173512
# determine the "type" of burst it is, the index represents if a state is present, using binary, minus 1 because there are no bursts with no dwells
35183513
burst_type_temp = 0
@@ -3521,17 +3516,16 @@ def viterbi_sort(h2mm_model hmod, indexes, times, num_cores=None):
35213516
burst_type_temp += 2**st
35223517
burst_type[i] = burst_type_temp
35233518
# sorting dwells based on transition rates, and calculating their E and S values
3524-
cdef list dwell_mid = [[[]for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3525-
cdef list dwell_beg = [[[]for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3526-
cdef list dwell_end = [[[]for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3527-
cdef list dwell_burst = [[] for i in range(hmod.nstate)]
3528-
cdef list ph_mid = [[np.zeros((0,hmod.ndet),dtype=int)for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3529-
cdef list ph_beg = [[np.zeros((0,hmod.ndet),dtype=int)for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3530-
cdef list ph_end = [[np.zeros((0,hmod.ndet),dtype=int)for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3531-
cdef list ph_burst = [np.zeros((0,hmod.ndet),dtype=int) for i in range(hmod.nstate)]
3532-
cdef list ph_counts = [np.zeros((0,hmod.ndet),dtype=int) for i in range(hmod.nstate)]
3533-
cdef cnp.ndarray time, index, state
3534-
cdef cnp.ndarray[long,ndim=2] ph_counts_temp = np.zeros((1,hmod.ndet),dtype=int)
3519+
dwell_mid = [[[] for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3520+
dwell_beg = [[[] for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3521+
dwell_end = [[[] for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3522+
dwell_burst = [[] for i in range(hmod.nstate)]
3523+
ph_mid = [[np.zeros((0,hmod.ndet),dtype=int)for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3524+
ph_beg = [[np.zeros((0,hmod.ndet),dtype=int)for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3525+
ph_end = [[np.zeros((0,hmod.ndet),dtype=int)for i in range(hmod.nstate)] for j in range(hmod.nstate)]
3526+
ph_burst = [np.zeros((0,hmod.ndet),dtype=int) for i in range(hmod.nstate)]
3527+
ph_counts = [np.zeros((0,hmod.ndet),dtype=int) for i in range(hmod.nstate)]
3528+
ph_counts_temp = np.zeros((1,hmod.ndet),dtype=int)
35353529
#sorts the dwells into dwell times and photon counts
35363530
for time, index, state in zip(times, indexes, paths):
35373531
demar = np.append(1,np.diff(state))

docs/source/ChangeNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Change Notes
44
.. currentmodule:: H2MM_C
55

66

7+
Changed in Version 2.1.X
8+
------------------------
9+
10+
- Fixed: issue `Issue 4 <https://github.com/harripd/H2MMpythonlib/issues/4>`_ where :func:`viterbi_sort` failed when run from ipython ``__main__``.
11+
12+
713
Changed in Version 2.1.1
814
------------------------
915

0 commit comments

Comments
 (0)