From help-request at octave dot org Mon Feb 7 08:01:01 2005 Subject: Re: de-for-ing.. From: David Bateman To: Miroslaw Kwasniak CC: help at octave dot org Date: Mon, 07 Feb 2005 15:02:51 +0100 Miroslaw Kwasniak wrote: >On Sun, Feb 06, 2005 at 10:42:36PM +0100, Gorazd Brumen wrote: > > >>The results are the same, but the for loop is much >>faster and less memory consuming. the kron solution >>is preety much stupid. >> >> > >I'm suprized too, because octave has slow loops. > > > >>Is there a better way than the for loop? >> >> > >I've tested also two additional methods with repmat: and sort: > >place3=sum(repmat(x_init(:),1,lx) <= repmat(x(:)',n,1)); >t3=cputime; > >and sort: > >[y i0]=sort([x_init, x]); >i=find(i0>n); >place4(i0(i)-n)=cumsum([i(1) diff(i)]-1); >t4=cputime; > >Results for >ftest(n=1000, lx=10000); >ftest(n=10000, lx=1000); > >cpu-tme in seconds (2.1.63 on A1600XP) > for-loop kronecker repmat sort > 1.600000 2.350000 4.200000 0.040000 > 0.8700000 2.3800000 2.5200000 0.0100000 > >Winner is the method with sort, but it may fail, because it assumes that >sort doesn't change order for equal values: > > x(i) == x(j) & i < j ==> find(i0==i) < find(i0==j) > >and it may depend on sort implementation. > > sort maintains ordering and so won't swap equal values... D. -- David Bateman David dot Bateman at motorola dot com Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary ------------------------------------------------------------- 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 -------------------------------------------------------------