SWIG + NumPy - any examples ?

Travis Oliphant olipt at mayo.edu
Thu Jun 15 14:37:13 EDT 2000


> If anyone has done this, I would appreciate an example so I can
> get started.

This is what I did in fftw-numpy 

Taken from dfftw.i in fftw-numpy-0.6:

%init %{
        import_array();
%}

%typemap(python,in) fftw_complex * {
  /* Make sure input is a NumPy array and a Complex Double */
  PyArrayObject *arr;
  if ((arr = (PyArrayObject *) PyArray_ContiguousFromObject($source,
PyArray_CDOUBLE, 0, 0)) == NULL) return NULL;
  $target = (fftw_complex *)arr->data;
  $source = (PyObject *)arr;
}

%typemap(python,freearg) fftw_complex * {
  Py_XDECREF($arg); 
}  





More information about the Python-list mailing list