I am new to numpy extension writing, and am trying to call some of the
functions defined in Numeric-21.3/Src/multiarraymodule.c, eg
extern PyObject *PyArray_Correlate(PyObject *op1, PyObject *op2, int mode)
in a Numeric extension module that I am writing.
Are these functions available via the C API, and if so, how should I
go about accessing them? Or are the only array functions defined in
Include/arrayobject.h available in the C API?
Below is my prototype module. I am defining a function 'xcorr' that
just does what cross_correlate does, as a test case to see if I can
access the multiarray C API:
/* jdhscipy.c -- Wed Oct 2 2002
*/
#include "Python.h"
#include "Numeric/arrayobject.h"
#include "stdio.h"
static PyObject *ErrorObject;
extern PyObject *PyArray_Correlate(PyObject*, PyObject*, int);
static char xcorr__doc__[] = "";
static PyObject * xcorr(PyObject *self, PyObject *args) {
PyObject *shape, *a0;
int mode=0;
if (!PyArg_ParseTuple(args, "OO|i", &a0, &shape, &mode)) return NULL;
return PyArray_Correlate(a0, shape, mode);
}
static struct PyMethodDef jdhscipy_methods[] = {
{"xcorr", xcorr, 1, xcorr__doc__},
{NULL, NULL} /* sentinel */
};
/* Initialization function for the module (*must* be called initjdhscipy) */
static char jdhscipy_module_documentation[] =
"My first scipy extension"
;
DL_EXPORT(void) initjdhscipy(void)
{
PyObject *m, *d;
/* Create the module and add the functions */
m = Py_InitModule4("jdhscipy", jdhscipy_methods,
jdhscipy_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
/* Import the array object */
import_array();
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
ErrorObject = PyString_FromString("jdhscipy.error");
PyDict_SetItemString(d, "error", ErrorObject);
/* XXXX Add constants here */
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module jdhscipy");
}