Calling Fortran routines in scipy.special in a function jitted with numba
<p>Is there a way to directly or indirectly call the Fortran routines that can be found here <a href="https://github.com/scipy/scipy/tree/master/scipy/special/cdflib" rel="nofollow">https://github.com/scipy/scipy/tree/master/scipy/special/cdflib</a> and that are used by <code>scipy.stats</code> from a function that is supposed to by compiled by <code>numba</code> in <code>nopython</code>mode?</p>

<p>Concretely, because <code>scipy.stats.norm.cdf()</code> is somehow pretty slow, I am right now directly using <code>scipy.special.ndtr</code>, which is called by the former. However, I'm doing this in a loop, and my intend is to speed it up using <code>numba</code>.</p>

<p>I would take a look at <a href="https://github.com/QuantEcon/rvlib" rel="nofollow">rvlib</a>, which uses Numba and CFFI to call RMath, which is the standalone C library that R uses to calculate statistical distributions. The functions it provides should be callable by Numba in <code>nopython</code> mode. Take a look at the README for an example of the function that is equivalent to <code>scipy.stats.norm.cdf()</code></p>

<p>If you're still interested in wrapping <code>cdflib</code> yourself, I would recommend using CFFI. You'll have to build a C-interface for the functions you want. You might find this blog post that I wrote helpful in getting started:</p>

<p><a href="https://www.continuum.io/blog/developer-blog/calling-c-libraries-numba-using-cffi" rel="nofollow">https://www.continuum.io/blog/developer-blog/calling-c-libraries-numba-using-cffi</a></p>

python numba