There is no literal for it, but a float can parse it from a string:
>>> float('inf') inf >>> np.inf == float('inf') True
Alternatively, math.h can (almost certainly will) declare a macro that computes the value of inf, in which case you can simply use this:
cdef extern from "math.h": float INFINITY
(There is no clean way to check if INFINITY is defined in pure Cython, so if you want to span all of your databases, you will need to hack. One way to do this is to create a small C header, say fallbackinf.h :
#ifndef INFINITY #define INFINITY 0 #endif
And then in your .pyx file:
cdef extern from "math.h": float INFINITY cdef extern from "fallbackinf.h": pass inf = INFINITY if INFINITY != 0 else float('inf')
(You cannot assign INFINITY because it is an rvalue. You can end the ternary operator if #defined INFINITY is like 1.0 / 0.0 in your header, but it can raise SIGFPE, depending on your compiler.)
This is certainly in the field of optimizing the cult of the load.)
source share