help-octave
[Top][All Lists]
Advanced

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

Re: speeding up function


From: c.
Subject: Re: speeding up function
Date: Mon, 12 Jul 2010 00:54:58 +0200

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



reply via email to

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