help-octave
[Top][All Lists]
Advanced

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

Re: vectorization quiz


From: Jaroslav Hajek
Subject: Re: vectorization quiz
Date: Wed, 8 Sep 2010 13:04:05 +0200

On Wed, Sep 8, 2010 at 11:32 AM, Francesco Potortì <address@hidden> wrote:
> I thought a little, but I do not see the way of vectorising this.  It's
> a loop that is run only few times, but is called very frequently.
> Essentially, there are few 2-D maps stacked one over the other which
> must be shifted each by a variable amount and then summed to obtain a
> new 2-D map.  Here is the code:
>
>    for mi = 1:m
>      llka += llkm(by+offm(mi,1), bx+offm(mi,2), mi);
>    endfor
>
> where:
> m          ==>     5
> size(llka) ==>     156 222
> size(llkm) ==>     186 252 5
> by         ==>     16:172
> bx         ==>     16:238
> size(offm) ==>     5 2
> offm(m,i)  ==>     a scalar in the range [-15;15]
>
> Thanks in advance to those wishing to try :)
>

I don't think there's a good way. You can, of course, extract the
submatrices via cellfun and then use plus, but it's not going to be
significantly better. Given that m = 5, I think it's not even worth
trying. If it doesn't seem to be possible to vectorize (part of) the
outer loop, your best approach is to write a compiled function.
Perhaps a sufficiently general one would be useful in Octave or
OctaveForge.

regards

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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