Probably to keep it simple, one could use exp
from the standard library, otherwise there are some hoops to jump through, to get it work with npy_expl
.
The usual Numpy-API is header-only (more precisely, only headers are needed at compile-/linktime, see here), but this is not the case with math-functions. There is define NPY_INLINE_MATH
, which would also present numpy's math library as inline functions, but this will not work on installed numpy-distributionen, because those lack the core/src
-folder, where the definitions of math-functions are given.
So you have to add the precompiled static numpy's math library to your setup. It can be found in folder core/lib
and is called (at least on linux) libnpymath.a
.
The most robust way is to use get_info
from numpy.distutils.misc_util
, which returns a dictionary providing values for 'define_macros'
,
'include_dirs'
, 'libraries'
and 'library_dirs'
- i.e. values we need to pass to Extension, e.g.
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from numpy.distutils.misc_util import get_info
npymath_info = get_info('npymath')
extensions = [
Extension('_hmmc', ['_hmmc.pyx'],
**npymath_info
),
]
setup(
ext_modules = cythonize(extensions)
)
There is also the function get_mathlibs
from numpy.distutils.misc_util
but it only works if _numpyconfig.h
is present, which is not the case at least in my installation.