[Numpy-discussion] avoiding the matrix copy performance hit
Ryan Krauss
ryanlists at gmail.com
Mon Feb 13 18:14:02 CST 2006
You both seem to have cooler computers than I do:
In [19]: t1.timeit(100)
Out[19]: 4.9827449321746826
In [20]: t2.timeit(100)
Out[20]: 4.9990239143371582
On 2/13/06, Tim Hochberg <tim.hochberg at cox.net> wrote:
> Bill Baxter wrote:
>
> > Is there anyway to get around this timing difference?
> > *
> > >>> import timeit
> > ** >>> t1 = timeit.Timer("a = zeros((1000,1000),'d'); a += 1.;",
> > 'from numpy import zeros,mat')
> > ** >>> t2 = timeit.Timer("a = mat(zeros((1000,1000),'d')); a +=
> > 1.;", 'from numpy import zeros,mat')
> > >>> **t1.timeit(100)
> > 1.8391627591141742
> > >>> t2.timeit(100)
> > 3.2988266117713465
> >
> > *Copying all the data of the input array seems wasteful when the array
> > is just going to go out of scope. Or is this not something to be
> > concerned about?
>
> You could try using copy=False:
>
> >>> import timeit
> >>> t1 = timeit.Timer("a = zeros((1000,1000),'d'); a += 1.;", 'from
> numpy import zeros,mat')
> >>> t2 = timeit.Timer("a = mat(zeros((1000,1000),'d'), copy=False); a
> += 1.;", 'from numpy import z
> eros,mat')
> >>> t1.timeit(100)
> 3.6538127052460578
> >>> t2.timeit(100)
> 3.6567186611706237
>
> I'd also like to point out that your computer appears to be much faster
> than mine.
>
> -tim
>
>
> >
> > It seems like a copy-by-reference version of mat() would be useful.
> > Really I can't imagine any case when I'd want both a matrix and the
> > original version of the array both hanging around as separate copies.
> > I can imagine either 1) the array is just a temp and I won't ever need
> > it again or 2) temporarily wanting a "matrix view" on the array's data
> > to do some linalg, after which I'll go back to using the original (now
> > modified) array as an array again.
> >
> > --bill
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
More information about the Numpy-discussion
mailing list