From: Francesc A. <fa...@ca...> - 2006-09-12 17:49:36
|
El dt 12 de 09 del 2006 a les 13:17 -0400, en/na Pierre Thibault va escriure: > Hello again, >=20 > On 9/12/06, Francesc Altet <fa...@ca...> wrote: > > Hello Pierre, > > [...] > > > > Well, in some way, there is a temporary array creation that is > > immediately bound to B, so in the end, the temporary is not so > > temporary, but a new (bounded) object. Obviously, the object that was > > referencing B is freed (unless there is another reference to it). >=20 > ok, I guess I was aware of all that. My worries are related to two cases: > 1) When the mere creation of a new array is prohibitive. As Archibald said in other message, creation of a big array is not an issue (malloc is very fast) and indepent of the size: >>> Timer("a=3Dnumpy.array(100,dtype=3Dnumpy.complex128)", "import numpy").repeat(3,10000) [0.19819307327270508, 0.14915895462036133, 0.14999985694885254] >>> Timer("a=3Dnumpy.array(10000,dtype=3Dnumpy.complex128)", "import numpy").repeat(3,10000) [0.15171599388122559, 0.14998698234558105, 0.14901280403137207] that is 15 us (in my old machine) irregardingly of the size. [BTW, numpy.empty seems twice as slower in my machine. Why? >>> Timer("a=3Dnumpy.empty(10000,dtype=3Dnumpy.complex128)", "import numpy").repeat(3,10000) [0.37033700942993164, 0.31780219078063965, 0.31607294082641602] ] > 2) When what I really want to change is the _content_ of an array. > Using assignment (=3D) disconnects B from the array it refers to, so > that what used to be true (C=3DB) is not anymore. >=20 > I understant that B[:] =3D ... solves the problem 2), though I don't > know if this notation is recommended; but I would like to know if > there is anyway to solve 1), in the way ufuncs can do. >=20 > I had fun using kde's "performance monitor" (ksysguard) to see the > difference between >=20 > a =3D numpy.random.rand(2048,2048) + 1j * numpy.random.rand(2048,2048) > a =3D numpy.exp(a) >=20 > and >=20 > a =3D numpy.random.rand(2048,2048) + 1j * numpy.random.rand(2048,2048) > numpy.exp(a,out=3Da) >=20 > Not only is the latter faster, but I could see a large glitch in the > memory usage for the former. Yes, it seems that some ufuncs have an additional "out" parameter that I was not aware of. Well, it that case, this parameter in the fft function would solve your needs, although I don't know how complicated would be this. Cheers, --=20 >0,0< Francesc Altet http://www.carabos.com/ V V C=C3=A1rabos Coop. V. Enjoy Data "-" |