help-octave
[Top][All Lists]
Advanced

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

Re: help with vectorization of update rule


From: Jaroslav Hajek
Subject: Re: help with vectorization of update rule
Date: Mon, 25 Oct 2010 13:36:40 +0200

On Fri, Oct 22, 2010 at 10:56 AM, grg <address@hidden> wrote:
>
>
> Søren Hauberg wrote:
>>
>> Try the following (more simple solution):
>>
>>     z = x0 * (A.^(0:T));
>>
>>
>
>
> Hi Søren and John,
>
> You are both indeed right: if T is increased to a number larger than 20, the
> 1st vectorized version of the code is faster than the loop, and the latest
> is even faster.
>
> However, I've just realized that yesterday I missed an important thing.
> In my problem A is a *matrix*, not a scalar as in the examples.
>

The general rule of thumb is that you only need to vectorize a loop if
the loop count is high *and* the body is cheap. The exact meanings of
"high" and "cheap" may of course vary between cases.
A matrix-vector multiplication is usually not cheap, unless the size
is small. So, if s is big enough, forget the vectorization. If T >> s
and s is small, there is still room for improvement.


> That was indeed my initial question.  How to compute efficiently (i.e.,
> without a loop) A.^t, when size(A)=[s s], and size(t)=[1 T].

A.^t doesn't make sense in the case you describe.



reply via email to

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