help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple matrix problem


From: Dmitri A. Sergatskov
Subject: Re: simple matrix problem
Date: Wed, 05 Nov 2003 12:13:52 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 Netscape/7.1

address@hidden wrote:
On Nov 5, 2003 at 2:47pm, Geraint Paul Bevan wrote:

g.beva >data = [ data ( : , 1 ) , detrend ( data ( : , 2 ) ) ]

Not to knit-pick, but an in-place assignment is faster than
re-allocating memory via the [...] operator:

---
octave> version
ans = 2.1.50
octave> A = rand(50,50);
octave> tic;A(:,1) = rand(50,1);toc
ans = 0.0013770
octave> tic;A = [ rand(50,1), A(:,2:50)];toc
ans = 0.0026010
---


Though I do not disagree with the conclusion I do not think those number
make much sense (tic;toc timing is not that accurate):

address@hidden dima]$ octave
GNU Octave, version 2.1.50 (i686-pc-linux-gnu).
...
octave:1> A = rand(50,50);
octave:2> tic;A(:,1) = rand(50,1);toc
ans = 0.0082260
octave:3> tic;A = [ rand(50,1), A(:,2:50)];toc
ans = 0.00092900
octave:4>


It's almost exactly twice as fast. Sorry Geraint, this is just my
curiosity running amok! :-)


So [...] almost 10 times as fast! Sure...

You need to make a test case that takes few seconds, eg.:
octave:5> A = ones(5000,5000);
octave:6> tic;A(:,1) = rand(5000,1);toc
ans = 0.0099300
octave:7> tic;A = [ rand(5000,1), A(:,2:5000)];toc
ans = 28.603

~Tomer


Regards,

Dmitri.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]