[Numpy-discussion] avoiding the matrix copy performance hit
ryanlists at gmail.com
Mon Feb 13 18:14:02 CST 2006
You both seem to have cooler computers than I do:
In : t1.timeit(100)
In : t2.timeit(100)
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
> >>> t1.timeit(100)
> >>> t2.timeit(100)
> I'd also like to point out that your computer appears to be much faster
> than mine.
> > 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!
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
More information about the Numpy-discussion