Raising an exception while using numba Raising an exception while using numba numpy numpy

Raising an exception while using numba


http://numba.pydata.org/numba-doc/dev/reference/pysupported.html

2.6.1.1. Constructs

Numba strives to support as much of the Python language as possible, but some language features are not available inside Numba-compiled functions. The following Python language features are not currently supported:

Class definitionException handling (try .. except, try .. finally)Context management (the with statement)

The raise statement is supported in several forms:

raise (to re-raise the current exception)raise SomeExceptionraise SomeException(<arguments>)

so that leaves us here:

z[i,j] = math.exp(-beta[j,i])

anything negative under about exp(-1000); really-really small will evaluate to zero without overflow

math.exp(-1000000000) "works" and is probably not your issue (although it will return 0.0, its not "really" zero)

so what would cause this to fail? well we know:

print(math.exp(100))>>>2.6881171418161356e+43

is silly big, much more than that... probably overflow

sure enough

print(math.exp(1000))>>>OverflowError: math range error

I don't have citation but I think the effective range is like -700 to 700 which evaluate to 0 and infinity(overflow) effectively from the perspective of double floats

to handle that we window the function:

n = betaif n > 100:    n = 100z = math.exp(n)

but that won't work either because math.exp(n) only accepts floats and your beta appears to be a list; you'll have to use numpy.exp(n) and numpy.clip() to window

b = numpy.array(-beta[j,i])n = numpy.clip(b, a_max=100)z = numpy.exp(n)

or to raise the overflow exception:

b = numpy.array(-beta[j,i])n = numpy.clip(b, a_max=100)if b != n:    print (j,i,-beta[j,i])    raise OverflowErrorelse:    z = numpy.exp(n)