[Numpy-discussion] Fwd: numpy.i and std::complex

Glen Mabey gmabey at swri.org
Mon Oct 27 11:06:27 EDT 2014


I was very excited to learn about numpy.i for easy numpy+swigification of C code -- it's really handy.

Knowing that swig wraps C code, I wasn't too surprised that there was the issue with complex data types (as described at http://docs.scipy.org/doc/numpy/reference/swig.interface-file.html#other-common-types-complex), but still it was pretty disappointing because most of my data is complex, and I'm invoking methods written to use C++'s std::complex class.

After quite a bit of puzzling and not much help from previous mailing list posts, I created this very brief but very useful file, which I call numpy_std_complex.i --

/* -*- C -*-  (not really, but good for syntax highlighting) */

%include "numpy.i"

%include <std_complex.i>

%numpy_typemaps(std::complex<float>,  NPY_CFLOAT , int)
%numpy_typemaps(std::complex<double>, NPY_CDOUBLE, int)

#endif /* SWIGPYTHON */

I'd really like for this to be included alongside numpy.i -- but maybe I overestimate the number of numpy users who use complex data (let your voice be heard!) and who also end up using std::complex in C++ land.

Or if anyone wants to improve upon this usage I would be very happy to hear about what I'm missing.

I'm sure there's a documented way to submit this file to the git repo, but let me simultaneously ask whether list subscribers think this is worthwhile and ask someone to add+push it for me …

Glen Mabey

More information about the NumPy-Discussion mailing list