Skip to content

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

Open

Description

@borissim

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

Activity

  1. rsharris commented on Oct 16, 2017

    @rsharris
    Contributor

    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.

  2. welyt commented on Nov 27, 2023

    @welyt

    same error, any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions