[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #53251] Very slow execution of linear interpol
From: |
Michael Leitner |
Subject: |
[Octave-bug-tracker] [bug #53251] Very slow execution of linear interpolation |
Date: |
Thu, 1 Mar 2018 15:09:47 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0 |
Follow-up Comment #1, bug #53251 (project octave):
The reason is most probably that Matlab has a JIT-compiler, and Octave has not
(or it is not usable in most cases). So first, it seems that your line
Di(:,k) = gg_linintp(Y, Z(:,k), D);
is exactly equivalent to
Di(:,k) = interp1(Y, Z(:,k), D,"extrap");
Why do you use your custom interpolation routine? Matlab for sure also has
interp1. interp1 uses vectorized code, but only gives you a factor of about 2
in runtime, which is disappointing, the reason being probably all the input
checking in interp1. But you can take interp1 and remove all the input
checking (which you also do not have in your custom routine), take only the
correct code branch with the vectorized code, and it should be much faster.
But: if this is really representative for your use case, why don't you replace
the inner loop
for k=1:nx
Di(:,k) = gg_linintp(Y, Z(:,k), D);
end
by
Di = interp1(Y, Z, D,"extrap");
This executes on my computer in 6 seconds overall, which should be
competitive. Still, I am impressed by Matlab, that even 13 years ago they had
such a good JIT, that seemingly also pulled the input checking out of the
function and out of the for loop, otherwise these timings could not result.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?53251>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/