Glen,

Supporting std::complex<> was just low enough priority for me that I decided to 
wait until someone expressed interest ... and now, many years later, someone 
finally has.

I would be happy to include this into numpy.i, but I would like to see some 
tests in the numpy repository demonstrating that it works.  These could be 
relatively short and simple, and since float and double are the only scalar 
data types that I could foresee supporting, there would not be a need for 
testing the large numbers of data types that the other tests cover.  

I would also want to protect the references to C++ objects with '#ifdef 
__cplusplus', but that is easy enough.

-Bill

On Oct 27, 2014, at 9:06 AM, Glen Mabey <gma...@swri.org> wrote:

> Hello,
> 
> 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) */
> #ifdef SWIGPYTHON
> 
> %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 …
> 
> Thanks,
> Glen Mabey
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: wfsp...@sandia.gov **

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to