User guide
NumPy User Guide, Release 1.9.0
}
#else
PyMODINIT_FUNC initnpufunc(void)
{
PyObject
*
m,
*
logit,
*
d;
m = Py_InitModule("npufunc", LogitMethods);
if (m == NULL) {
return;
}
import_array();
import_umath();
logit = PyUFunc_FromFuncAndData(funcs, data, types, 4, 1, 1,
PyUFunc_None, "logit",
"logit_docstring", 0);
d = PyModule_GetDict(m);
PyDict_SetItemString(d, "logit", logit);
Py_DECREF(logit);
}
#endif
This is a setup.py file for the above code. As before, the module can be build via calling python setup.py build at the
command prompt, or installed to site-packages via python setup.py install.
’’’
setup.py file for logit.c
Note that since this is a numpy extension
we use numpy.distutils instead of
distutils from the python standard library.
Calling
$python setup.py build_ext --inplace
will build the extension library in the current file.
Calling
$python setup.py build
will build a file that looks like ./build/lib
*
, where
lib
*
is a file that begins with lib. The library will
be in this file and end with a C library extension,
such as .so
Calling
$python setup.py install
will install the module in your site-packages file.
See the distutils section of
’Extending and Embedding the Python Interpreter’
at docs.python.org and the documentation
on numpy.distutils for more information.
’’’
def configuration(parent_package=’’, top_path=None):
import numpy
90 Chapter 5. Using Numpy C-API