octave-maintainers
[Top][All Lists]
Advanced

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

Improved triu.m and tril.m


From: Marco Caliari
Subject: Improved triu.m and tril.m
Date: Thu, 22 Oct 2009 18:00:49 +0200 (CEST)
User-agent: Alpine 1.00 (DEB 882 2007-12-20)

Dear maintainers,

although triu and tril are built-in functions in Matlab and then much faster, I discovered that it is possible to improve the m files in Octave, by eliminating the min/max evaluations inside the loops and selecting whether to replace numbers with zeros or zeros wih numbers.
The results, for my Octave 3.2.3, are:

A=rand(100);
i=randperm(200)(1)-100,tic,U=triu(A,i);,toc,tic,myU=mytriu(A,i);,toc,norm(U-myU)
i = -31
Elapsed time is 0.0221 seconds.
Elapsed time is 0.00397 seconds.
ans = 0
i=randperm(200)(1)-100,tic,U=triu(A,i);,toc,tic,myU=mytriu(A,i);,toc,norm(U-myU)
i = -52
Elapsed time is 0.0224 seconds.
Elapsed time is 0.00114 seconds.
ans = 0
i=randperm(200)(1)-100,tic,U=triu(A,i);,toc,tic,myU=mytriu(A,i);,toc,norm(U-myU)
i =  22
Elapsed time is 0.0174 seconds.
Elapsed time is 0.00495 seconds.
ans = 0
i=randperm(200)(1)-100,tic,U=triu(A,i);,toc,tic,myU=mytriu(A,i);,toc,norm(U-myU)
i =  63
Elapsed time is 0.00873 seconds.
Elapsed time is 0.00261 seconds.
ans = 0
i=randperm(200)(1)-100,tic,U=triu(A,i);,toc,tic,myU=mytriu(A,i);,toc,norm(U-myU)
i =  36
Elapsed time is 0.0146 seconds.
Elapsed time is 0.00413 seconds.
ans = 0

For me the speed-up is > 3. Enclosed, the patches wrt 3.2.3.

Best regards,

Marco

Attachment: triu.m.diff
Description: Text Data

Attachment: tril.m.diff
Description: Text Data


reply via email to

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