[Numpy-discussion] Simple NumPy-compatible vector w/C++ & SWIG?

Magnus Lie Hetland magnus at hetland.org
Fri Feb 24 04:27:05 CST 2006


Hi!

I'm working on a data structure library where one of the element  
types most likely will be a vector type (i.e., points in a  
multidimensional space, with the dimensionality set by the user). In  
the data structure (which is disk-based) I have work with raw bytes  
that I'd like to copy around as little as possible.

The library itself is (being) written in C++, but I'm wrapping it  
with SWIG so I can drive and test it with Python. It seems to me that  
something NumPy-compatible might be the best choice for the vector  
type, but I'm not sure how I should do that.

I've been thinking about simply implementing a minimal compatibility  
layer for the NumPy Array Interface; is it then possible to construct  
a NumPy array using this custom array, and get full support for the  
various array operations without actually copying the data?

And: Any ideas on what to do on the C++ side? Is there any code/ 
library out there for a vector-thing that works well in C++ *and*  
that has wrapping code for NumPy? (I know the STL vector is wrapped  
to a Python list by default -- I'm just thinking that including those  
things in the equation would lead to lots of copied data...)

--
Magnus Lie Hetland
http://hetland.org






More information about the Numpy-discussion mailing list