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: Mon, 12 Jul 2010 12:42:27 +0200

On Mon, Jul 12, 2010 at 12:54 AM, c. <address@hidden> wrote:
> Hi,
> Thanks for your reply!
>
> On 11 Jul 2010, at 20:50, Jaroslav Hajek wrote:
>
>>
>> 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.
>
> it's not necessarily  matrices as small as 2x2.
> Anyways even with 2x2 or with 2x1 vectors this function appears to be faster
> than a for loop,
> though slower than something more ad hoc like
>
>  det = squeeze (v(1,1,:,:) .* (v(2,2,:,:) .* v(3,3,:,:) - v(2,3,:,:) .*
> v(3,2,:,:))
>               + v(1,2,:,:) .* (v(2,3,:,:) .* v(3,1,:,:) - v(2,1,:,:) .*
> v(3,3,:,:))
>               + v(1,3,:,:) .* (v(2,1,:,:) .* v(3,2,:,:) - v(2,2,:,:) .*
> v(3,1,:,:)));
>
>> 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).
>
> oops! thanks, I fixed that.
>
>> 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.
>
> I don't know whether that can be indicative of octave's behaviour

hardly, obviously.

> but
> according to matlab's profiler, in the call
>
> aa = randn (4, 4, 100, 100, 25); res = matarrayfun (@inv , aa, [1, 2]);
>
> most of the time is consumed by 'num2cell'...
>
> c.
>

If you don't work with the development version, my first advice is to
upgrade. Then, I'd suggest you take a representative case and try to
measure the actual time consumed by various parts using tic/toc or
cputime.

Your case for cell2mat seems rather special to me; perhaps it would be
better handled by using cat() directly.

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