Providing array interface from SWIG-wrapped C struct

vallis.35530053 at bloglines.com vallis.35530053 at bloglines.com
Thu Oct 12 20:00:51 CDT 2006


Wonderful, it works, thanks!



Michele



--- Discussion of Numerical Python
<numpy-discussion at lists.sourceforge.net wrote:

On 10/12/06, Michele Vallisneri
<vallis at vallis.org> wrote:

> > Does anybody here have experience about offering
the array interface

> > from a SWIG-wrapped C struct?

> 

> I have.

> 

> > I have tried the following, borrowing code from numpy's arrayobject.c:

> >

> > %extend real_vec_t {

> >    PyObject *__array_struct__() {

> >
     /* From numpy/arrayobject.c/array_struct_get */

> 

> You are extending
real_vec_t with a new METHOD, but what numpy

> requests is an ATTRIBUTE.
So, numpy simply queries your vec like:

> 

> arrstr = vec.__array_struct__

> 

> and not with a method call like this

> 

> arrstr = vec.__array_struct__()

> 

> 

> So here is what I would do (can fail with some SWIG optimizations)

> 

> %extend Vec {

> 

> PyObject* __array_struct__ () { /* ...  */ }

> 

>   %pythoncode {

>   __array_struct__ = property(__array_struct__,

>                                                  doc='Array protocol')

>   }

> 

> }

> 

> Hope you got the idea.

> 

> -- 

> 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

> 

> -------------------------------------------------------------------------

> Using Tomcat but need to do more? Need to support web services, security?

> Get stuff done quickly with pre-integrated technology to make your job
easier

> Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo

> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

> _______________________________________________

> Numpy-discussion mailing
list

> Numpy-discussion at lists.sourceforge.net

> https://lists.sourceforge.net/lists/listinfo/numpy-discussion

> 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list