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

Lisandro Dalcin dalcinl at gmail.com
Fri Feb 24 06:14:08 EST 2006


Magnus, I send you attached a SWIG file I use to interface PETSc
libraries and NumPy. It is a series of macros (perhaps a bit nested),
but I think this can help you to quickly define IN/OUT/INOUT typemaps
for arguments like this: (int size, double* data). This approach was
always enough for me. If your use case is more elaborated, please feel
free to ask for other alternatives.


On 2/24/06, Magnus Lie Hetland <magnus at hetland.org> wrote:
> 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
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>


--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
-------------- next part --------------
A non-text attachment was scrubbed...
Name: numpy.i
Type: application/octet-stream
Size: 21182 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060224/aedeba10/attachment-0001.obj>


More information about the NumPy-Discussion mailing list