[Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

Christopher Barker Chris.Barker@noaa....
Wed Sep 5 12:19:43 CDT 2007

Bill Spotz wrote:
> I have been considering adding some C++ STL support to numpy/doc/swig/ 
> numpy.i.  Probably std::vector<TYPE> <=> PyArrayObject (and some  
> std::complex<TYPE> support as well).  Is this what you had in mind?

well, std::valarray is not the same as std::vector, though there are 
similarities, so the example would be helpful.

Of greatest concern to me is the memory management issue -- it would be 
nice to be able to share the data black between the valarray and the 
numpy array (rather than copying back and forth), but as the both 
valarrays and vectors are re-sizeable, that might get tricky. I'm 
assuming that you can get the pointer to the data block from both, but 
it might change on you.

If you solve that for std::vector, the solution is likely to be similar 
for std:valarray. (I hope).

David Goldsmith wrote:
> Point of clarification: below "well-tested" = "well-use-tested," not 
> (necessarily) "well-unit-tested".

Of course, the better tested the better, but anything is probably better 
than starting from scratch!

Travis Vaught wrote:
> Have you seen this?
> http://www.scipy.org/Cookbook/SWIG_and_NumPy
> Also, the numpy/doc/swig directory has the simple typemaps.

Looked at both, and they are a great starting point, but only deal with 
plain old C arrays, as far as I've seen.

Unless someone speaks up, it sounds like it's not been done, but there 
are at least a few of us that are interested, so maybe we can start a 


By the way, David G. and I are working on the same project, so we're 
kind of like one person....

Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the Numpy-discussion mailing list