[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: vectorization quiz
From: |
Francesco Potortì |
Subject: |
Re: vectorization quiz |
Date: |
Fri, 10 Sep 2010 10:42:16 +0200 |
>> 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.
I think the slow thing is the index computation, so maybe I could try to
compute them all at once and then index, reshape and sum. Maybe I'll try.
With the new diag implementation now we have a fast way of multiplying
each row of a matrix by a different number. But I think we have no
euivalently fast way of summing a different number to each row. Am I
wrong?
> 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.
For the moment, the problem does not grant such effort on my part. But
I'll keep that in mind for the future. Thanks for the suggestions.
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/