[Numpy-discussion] Fwd: numpy.i and std::complex
Tom Krauss
thomas.p.krauss at gmail.com
Sun Dec 14 13:52:57 EST 2014
I know this is a month old at this point, but I wanted to state that I use
std::complex<double> with swig all the time and it works great. I have very
similar code in each of my project's ".i" files, so I am happy to see you
are adding support to numpy.i.
E.g.
%numpy_typemaps(std::complex<double>, NPY_CDOUBLE, int)
On Fri, Nov 14, 2014 at 1:06 PM, Glen Mabey <gmabey at swri.org> wrote:
>
>
> Hello,
>
> Ok, here's my attempt --
>
> https://github.com/gmabey/numpy/compare/swig-std-complex
>
> Glen
>
> On Oct 27, 2014, at 11:13 AM, Bill Spotz <wfspotz at sandia.gov> wrote:
>
> > 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 <gmabey at 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 at 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: wfspotz at sandia.gov **
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141214/ce6df21f/attachment.html>
More information about the NumPy-Discussion
mailing list