[Numpy-discussion] In-place operations
Pierre Thibault
thibault at physics.cornell.edu
Thu Sep 14 08:01:16 CDT 2006
On 9/13/06, Francesc Altet <faltet at carabos.com> wrote:
> Well, it seems that malloc actually takes more time when asking for more
> space. However, this can't be the reason why Pierre is seeing that:
>
> a = numpy.exp(a) [1]
>
> is slower than
>
> numpy.exp(a,out=a) [2]
>
> as I'd say that this increment in time is negligible compared with
> processing times of those big arrays. In fact, here are my times:
>
> >>> Timer("a = numpy.exp(a)", "import numpy;a =
> numpy.random.rand(2048,2048) + 1j *
> numpy.random.rand(2048,2048)").repeat(3,1)
> [2.5527338981628418, 2.5427830219268799, 2.5074479579925537]
> >>> Timer("numpy.exp(a,out=a)", "import numpy;a =
> numpy.random.rand(2048,2048) + 1j *
> numpy.random.rand(2048,2048)").repeat(3,1)
> [2.5298278331756592, 2.5082788467407227, 2.5222280025482178]
>
> So, both times are comparable.
Yeah, sorry about that: I had not checked carefully the timing. It
seemed slower to me, but you're right, this is not a problem as long
as there is enough free RAM. Ok, I'll go back to my coding and do like
I should always do: care about optimization later.
Thanks for all the comments and explanations!
Pierre
--
Pierre Thibault
616 Clark Hall, Cornell University
(607) 255-5522
More information about the Numpy-discussion
mailing list