[Numpy-discussion] use of %extend

Sebastian Haase seb.haase at gmail.com
Thu Apr 15 07:24:10 EDT 2010


did you mean to send this to the SWIG list !?
-S.


On Thu, Apr 15, 2010 at 11:53 AM, Michel Dupront
<michel.dupront at hotmail.fr> wrote:
> Hello,
>
> With the following example, given in the documentation:
>
> struct Vector {
>    double x,y,z;
> };
> %extend Vector {
>     Vector __add__(Vector *other) {
>          Vector v;
>          v.x = $self->x + other->x;
>          v.y = $self->y + other->y;
>          v.z = $self->z + other->z;
>          return v;
>     }
> };
>
> one can do in python:
>>>> import example
>>>> v = example.Vector(2,3,4)
>>>> w = example.Vector(10,11,12)
>>>> print v+w
> Vector(12,14,16)
>>>>
>
> There is something more that I would like to do but I don't
> know how. I would like to be able to do:
>>>>> v1 = v + 2
>>>>> v2 = 2 + v
> where v is a vector and 2 a number that would be added to each component
> of the vector.
> I would really appreciate any help on that.
> Many thanks in advance.
>
>
> ________________________________
> Acheter en ligne en toute sécurité ? Internet Explorer 8 vous protège
> gratuitement !
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>



More information about the NumPy-Discussion mailing list