[SciPy-user] returning an array from weave inline

Flavio Coelho fccoelho@gmail....
Fri Mar 30 11:18:07 CDT 2007


Yes Emanuele, that makes complete sense.

thanks,

Flávio

On 3/29/07, Emanuele Olivetti <olivetti@itc.it> wrote:
>
> Flavio Coelho wrote:
> > Thanks Fernando,
> >
> > I thought variables converted to C were copies, so that there could not
> be
> > an in place operation on a Python variable.
>
> They are copies like it is in the C way of thinking: if you pass a
> basic type (e.g. an int) to the inlined C code and modify it then
> when you are back to python there is no change in the initial variable
> you passed since just the copy was modified. If you pass something more
> complex
> (e.g. a numpy array) then you are just giving a copy of the it's reference
> (or pointer) to that function. With that reference (or copy of) you
> can access the the _original_ array and modify it. So when you are back to
> python your array _is_ changed. This mechanism allows better efficiency:
> what happens if you have a huge 2Gb array and pass it to the inline code?
> It's not desirable to make a whole copy and allocate other 2Gb or RAM...
>
> Anyway python itself works like that. E.g.:
> ----
> def f(a,b):
>      a=a+1
>      b.append(1)
>      return
>
> a=1
> b=[3,2]
> print a,b
> f(a,b)
> print a,b
> ----
>
> Hope this helps,
>
> Emanuele
>
> ------------------
> ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
> ITC -> since 1 March 2007 Fondazione Bruno Kessler
> ------------------
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>



-- 
Flávio Codeço Coelho
registered Linux user # 386432
get counted at http://counter.li.org
---------------------------
"software gets slower faster than hardware gets faster"
Niklaus Wirth's law
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070330/b9dbab08/attachment.html 


More information about the SciPy-user mailing list