From a2f9eb37d1b47184d6ac48c85cd5bd339625fba4 Mon Sep 17 00:00:00 2001 From: endre bakken stovner Date: Mon, 18 Oct 2021 14:12:09 +0200 Subject: [PATCH] 0.0.63 --- CHANGELOG | 6 +++ ncls/src/ncls.pyx | 97 +++++++++++++++++---------------------------- ncls/src/ncls32.pyx | 69 ++++++++++++++++---------------- ncls/version.py | 2 +- 4 files changed, 79 insertions(+), 95 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ee5859b..099c6aa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +# 0.0.63 (18.10.21) +- fix critical error: fix 1024-error for subtract 64 bit + +# 0.0.62 (20.09.21) +- fix critical error: fix 1024-error for subtract + # 0.0.61 (13.09.21) - fix critical error: in case of more than 1024 overlaps for on interval only reported 1024 first diff --git a/ncls/src/ncls.pyx b/ncls/src/ncls.pyx index b7cba2d..4c0233e 100644 --- a/ncls/src/ncls.pyx +++ b/ncls/src/ncls.pyx @@ -446,7 +446,8 @@ cdef class NCLS64: @cython.boundscheck(False) @cython.wraparound(False) @cython.initializedcheck(False) - cpdef set_difference_helper(self, const int64_t [::1] starts, const int64_t [::1] ends, const int64_t [::1] indexes): + cpdef set_difference_helper(self, const int64_t [::1] starts, const int64_t [::1] ends, const int64_t [::1] indexes, const int64_t [::1] nhits, + const int64_t[::1] nhits): cdef int i cdef int nhit = 0 @@ -477,28 +478,21 @@ cdef class NCLS64: if not self.im: # if empty return [], [], [] - it_alloc = cn.interval_iterator_alloc() it = it_alloc for loop_counter in range(length): - spent = 0 - while it: + nhit = nhits[loop_counter] + nstart = starts[loop_counter] + nend = ends[loop_counter] + + while nhit > 0: i = 0 cn.find_intervals(it, starts[loop_counter], ends[loop_counter], self.im, self.ntop, self.subheader, self.nlists, im_buf, 1024, - &(nhit), &(it)) # GET NEXT BUFFER CHUNK - - #print("nhits:", nhit) - - nstart = starts[loop_counter] - nend = ends[loop_counter] - - # print("nstart", nstart) - # print("nend", nend) + &(na), &(it)) # GET NEXT BUFFER CHUNK if nfound + nhit >= length: - length = (length + nhit) * 2 output_arr = np.resize(output_arr, length) output_arr_start = np.resize(output_arr_start, length) @@ -515,62 +509,45 @@ cdef class NCLS64: output[nfound] = indexes[loop_counter] i = nhit nfound += 1 + break - while i < nhit: - # print("--- i:", i) - # print("--- im_buf[i]", im_buf[i]) - #print(" B start:", im_buf[i].start) - #print(" B end:", im_buf[i].end) + max_i = 1024 if nhit > 1024 else nhit + while i < max_i: # in case the start contributes nothing - if i < nhit - 1: - # print(" i < nhit - 1") + if nstart < im_buf[i].start: + output[nfound] = indexes[loop_counter] + output_start[nfound] = nstart + output_end[nfound] = im_buf[i].start + nfound += 1 + nstart = im_buf[i].end - if nstart < im_buf[i].start: - #print(" new_start", nstart) - #print(" new_end", im_buf[i].start) + i += 1 + + nhit = nhit - 1024 + + if nhit <= 0: + i = i - 1 + if im_buf[i].start <= nstart and im_buf[i].end >= ends[loop_counter]: + # print("im_buf[i].start <= nstart and im_buf[i].end >= ends[loop_counter]") + #print("we are here " * 10) + + output_start[nfound] = -1 + output_end[nfound] = -1 + output[nfound] = indexes[loop_counter] + nfound += 1 + else: + if im_buf[i].start > nstart: output[nfound] = indexes[loop_counter] output_start[nfound] = nstart output_end[nfound] = im_buf[i].start nfound += 1 - nstart = im_buf[i].end - elif i == nhit - 1: - - # print("i == nhit -1") - #print("im_buf[i].start", im_buf[i].start) - #print("im_buf[i].end", im_buf[i].end) - #print("nstart", nstart) - #print("ends[loop_counter]", ends[loop_counter]) - - if im_buf[i].start <= nstart and im_buf[i].end >= ends[loop_counter]: - # print("im_buf[i].start <= nstart and im_buf[i].end >= ends[loop_counter]") - #print("we are here " * 10) - - output_start[nfound] = -1 - output_end[nfound] = -1 - output[nfound] = indexes[loop_counter] + if im_buf[i].end < ends[loop_counter]: + output[nfound] = indexes[loop_counter] + output_start[nfound] = im_buf[i].end + output_end[nfound] = ends[loop_counter] nfound += 1 - else: - if im_buf[i].start > nstart: - # print("im_buf[i].start > nstart", im_buf[i].start, nstart) - output[nfound] = indexes[loop_counter] - output_start[nfound] = nstart - output_end[nfound] = im_buf[i].start - nfound += 1 - - if im_buf[i].end < ends[loop_counter]: - # print("im_buf[i].end < ends[loop_counter]", im_buf[i].end, ends[loop_counter]) - # print("i, loop_counter", i, loop_counter) - # print("indexes[loop_counter]", indexes[loop_counter]) - # print("indexes", indexes[loop_counte rloop_counter]) - - output[nfound] = indexes[loop_counter] - output_start[nfound] = im_buf[i].end - output_end[nfound] = ends[loop_counter] - nfound += 1 - - i += 1 cn.reset_interval_iterator(it_alloc) it = it_alloc diff --git a/ncls/src/ncls32.pyx b/ncls/src/ncls32.pyx index 43b5dc5..bb9bc07 100644 --- a/ncls/src/ncls32.pyx +++ b/ncls/src/ncls32.pyx @@ -478,14 +478,13 @@ cdef class NCLS32: cdef int i = 0 cdef int nhit = 0 cdef int nfound = 0 - cdef int nfound_loop = 0 cdef int32_t nstart = 0 cdef int32_t nend = 0 cdef int length = len(starts) - cdef int loop_counter = 0 cdef int overlap_type_nb = 0 cdef int na = -1 cdef int spent = 0 + cdef int max_i = 0 output_arr = np.zeros(length, dtype=np.int64) output_arr_start = np.zeros(length, dtype=np.int32) @@ -512,10 +511,8 @@ cdef class NCLS32: nhit = nhits[loop_counter] nstart = starts[loop_counter] nend = ends[loop_counter] - nfound_loop = 0 - spent = 0 - while not spent: + while nhit > 0: i = 0 cn.find_intervals(it, starts[loop_counter], ends[loop_counter], self.im, self.ntop, self.subheader, self.nlists, im_buf, 1024, @@ -538,42 +535,46 @@ cdef class NCLS32: output[nfound] = indexes[loop_counter] i = nhit nfound += 1 - nfound_loop += 1 + break - while i < 1024: + max_i = 1024 if nhit > 1024 else nhit + + while i < max_i: # in case the start contributes nothing - if i < nhit - 1: - if nstart < im_buf[i].start: + if nstart < im_buf[i].start: + output[nfound] = indexes[loop_counter] + output_start[nfound] = nstart + output_end[nfound] = im_buf[i].start + nfound += 1 + nstart = im_buf[i].end + + i += 1 + + nhit = nhit - 1024 + + if nhit <= 0: + i = i - 1 + + if im_buf[i].start <= nstart and im_buf[i].end >= ends[loop_counter]: + # print("im_buf[i].start <= nstart and im_buf[i].end >= ends[loop_counter]") + #print("we are here " * 10) + + output_start[nfound] = -1 + output_end[nfound] = -1 + output[nfound] = indexes[loop_counter] + nfound += 1 + else: + if im_buf[i].start > nstart: output[nfound] = indexes[loop_counter] output_start[nfound] = nstart output_end[nfound] = im_buf[i].start nfound += 1 - nfound_loop += 1 - - nstart = im_buf[i].end - elif nfound_loop == nhit - 1: - if im_buf[i].start <= nstart and im_buf[i].end >= ends[loop_counter]: - output_start[nfound] = -1 - output_end[nfound] = -1 - output[nfound] = indexes[loop_counter] - nfound += 1 - nfound_loop += 1 - else: - if im_buf[i].start > nstart: - output[nfound] = indexes[loop_counter] - output_start[nfound] = nstart - output_end[nfound] = im_buf[i].start - nfound += 1 - nfound_loop += 1 - - if im_buf[i].end < ends[loop_counter]: - output[nfound] = indexes[loop_counter] - output_start[nfound] = im_buf[i].end - output_end[nfound] = ends[loop_counter] - nfound += 1 - nfound_loop += 1 - i += 1 + if im_buf[i].end < ends[loop_counter]: + output[nfound] = indexes[loop_counter] + output_start[nfound] = im_buf[i].end + output_end[nfound] = ends[loop_counter] + nfound += 1 cn.reset_interval_iterator(it_alloc) it = it_alloc diff --git a/ncls/version.py b/ncls/version.py index 27d5382..2c20ada 100644 --- a/ncls/version.py +++ b/ncls/version.py @@ -1 +1 @@ -__version__ = "0.0.61" +__version__ = "0.0.63"