help-octave
[Top][All Lists]
Advanced

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

Re: speeding up function


From: Jaroslav Hajek
Subject: Re: speeding up function
Date: Sun, 11 Jul 2010 20:50:26 +0200

On Sun, Jul 11, 2010 at 5:41 PM, Carlo de Falco <address@hidden> wrote:
> Hi all,
>
> I often store sets of matrices and vectors as part of NDArrays, e.g.
>
> for ii=1:Ni
>   for jj=1:Nj
>     v(ii, :, jj) = randn (2, 1);
>     m(ii, :, :, jj) = randn (2, 2);
>   endfor
> endfor
>
> so, to be able to perform matrix-vector operations like
>
> for ii=1:Ni
>   for jj=1:Nj
>     detm(ii, jj) = det (m(ii,:,:,jj));
>   endfor
> endfor
>
> or
>
> for ii=1:Ni
>   for jj=1:Nj
>     mv2(ii, :, jj) = squeeze (m(ii,:,:,jj)) * (v(ii,:,jj).^2)(:);
>   endfor
> endfor
>
> without for cycles, I produced the funcion below.
> Although it works it seems to be a bit slow.
> Does anyone on the list see any obvious bottleneck I coud remove to
> speed it up?
>

I'm afraid it will never be much efficient to apply Octave's matrix
functions like det() on a huge number of 2x2 matrices.
The actual computation is, in this case, completely drowned in the
call overhead.
I think the function you supplied is not entirely correct (it probably
doesn't work with more than 2 arrays, the varargin indexing seems
messed up). Maybe you could measure which part of your function eats
the most time? Though I'm afraid I'll know the answer; if it's the
main cellfun call (with the enclosed expression evaluated a priori),
then there's really little you can do.

-- 
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]