bxlab / bx-python

Tools for manipulating biological data, particularly multiple sequence alignments
MIT License
148 stars 54 forks source link

ZeroDivisionError thrown by bx.intervals.intersection.IntervalNode.__cinit__ #23

Open borissim opened 7 years ago

borissim commented 7 years ago

I create a lot of IntervalNode objects and eventually this error pops up

File "intersection.pyx", line 395, in bx.intervals.intersection.IntervalTree.insert (lib/bx/intervals/intersection.c:4902)
  File "intersection.pyx", line 127, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1657)
  File "intersection.pyx", line 118, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1567)
  File "intersection.pyx", line 118, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1567)
  File "intersection.pyx", line 118, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1567)
  File "intersection.pyx", line 118, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1567)
  File "intersection.pyx", line 118, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1567)
  File "intersection.pyx", line 118, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1567)
  File "intersection.pyx", line 127, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1657)
  File "intersection.pyx", line 118, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1567)
  File "intersection.pyx", line 127, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1657)
  File "intersection.pyx", line 127, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1657)
  File "intersection.pyx", line 120, in bx.intervals.intersection.IntervalNode.insert (lib/bx/intervals/intersection.c:1600)
  File "intersection.pyx", line 91, in bx.intervals.intersection.IntervalNode.__cinit__ (lib/bx/intervals/intersection.c:1330)
ZeroDivisionError: float division

The issue seems to be that at self.priority = ceil(nlog * log(-1.0/(1.0 * rand()/RAND_MAX - 1))) I assume rand() can produce 0 or RAND_MAX, at which point *(1.0 rand()/RAND_MAX - 1)** equals 0, hence ZeroDivisionError is thrown

rsharris commented 7 years ago

Right. The comment above the failing line claims that "python's uniform is perfect since the upper limit is not inclusive". But rand() isn't from python, it's from C. And the C standard says rand() is inclusive, 0<=rand()<=RAND_MAX.

I think the question is whether the intent was to have (RAND_MAX+1) as the denominator instead of RAND_MAX. That comment makes me think python's random.random() used to be used here.

Secondary questions would be (a) why the C PRNG is being used instead of the python PRNG, since C rand() implementations are usually poor, and (b) why a binomial distribution is being used instead of uniform.

welyt commented 11 months ago

same error, any update?