[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Speedup/Refaktoring loop?
From: |
Jaroslav Hajek |
Subject: |
Re: Speedup/Refaktoring loop? |
Date: |
Tue, 19 Aug 2008 12:30:43 +0200 |
On Tue, Aug 19, 2008 at 11:53 AM, Andreas Romeyke <address@hidden> wrote:
> Hi,
>
> There are any tricks to speedup the following piece of code?
>
> for i=1:n
> a=transpose(U) * X;
> tmpU = transpose(U)*U;
> for j=1:columns
> b=tmpU*V;
> V(i,j)=V(i,j)* a(i,j)/b(i,j);
> end
> end
>
> U and V are rectangular matrices, X is a squared matrix.
>
> The variant to replace line "V(i,j)=V(i,j)* a(i,j)/b(i,j);" with
>
> "V = V .* a ./ b" is much slower.
>
> I used Octave 2.9.9 to time the code.
>
> Any hints?
>
> Bye Andreas
>
>
If you really want to do what this code does, then I don't see any
speedup except hoisting "a" and "tmpU" out of the outer loop. But
chances are that you instead want something like this:
a = U.' * X;
b = U.' * U * V;
V = V .* a ./ b;
(*no* loops involved).
Note that this is not the same, since in your code the matrix b will
get a different value in each cycle of the inner loop.
>
> --
> Software Developer / Dipl. Inform. (FH)
> Max Planck Institute for Human Cognitive and Brain Sciences
> Department of Psychology
> Stephanstr. 1a, 04103 Leipzig, Germany
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
>
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
- Speedup/Refaktoring loop?, Andreas Romeyke, 2008/08/19
- Re: Speedup/Refaktoring loop?, Thomas Weber, 2008/08/19
- Re: Speedup/Refaktoring loop?,
Jaroslav Hajek <=
- Re: Speedup/Refaktoring loop? Extended..., Andreas Romeyke, 2008/08/19
- Re: Speedup/Refaktoring loop? Extended..., Jaroslav Hajek, 2008/08/19
- Re: Speedup/Refaktoring loop? Extended..., Andreas Romeyke, 2008/08/19
- Re: Speedup/Refaktoring loop? Extended..., Jaroslav Hajek, 2008/08/19
- Re: Speedup/Refaktoring loop? Extended..., Andreas Romeyke, 2008/08/27
- Re: Speedup/Refaktoring loop? Extended..., Dmitri A. Sergatskov, 2008/08/27
- Re: Speedup/Refaktoring loop? Extended..., David Bateman, 2008/08/27
- Re: Speedup/Refaktoring loop? Extended..., Andreas Romeyke, 2008/08/27
- Re: Speedup/Refaktoring loop? Extended..., John W. Eaton, 2008/08/27