[Numpy-discussion] use of %extend

Michel Dupront michel.dupront at hotmail.fr
Thu Apr 15 07:26:51 EDT 2010


 

Yes. I am really sorry about that.
 
> From: seb.haase at gmail.com
> Date: Thu, 15 Apr 2010 13:24:10 +0200
> To: numpy-discussion at scipy.org
> Subject: Re: [Numpy-discussion] use of %extend
> 
> 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
> >
> >
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
 		 	   		  
_________________________________________________________________
Hotmail et MSN dans la poche? HOTMAIL et MSN sont dispo gratuitement sur votre téléphone!
http://www.messengersurvotremobile.com/?d=Hotmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100415/76d1c635/attachment.html>


More information about the NumPy-Discussion mailing list