speed of interp2 and bug with method cubic

Peter Cloetens cloetens at ESRF.FR
Sun Oct 26 14:54:00 CDT 2008



John W. Eaton wrote:
> 
> On  4-Feb-2007, Peter Cloetens wrote:
> 
> | Hello,
> | 
> | It seems that the function interp2 got much slower at a certain point
> | (~factor 6 for linear interpolation and ~factor 40 for nearest
> | neighbour).
> |...
> | Reading the history and comparing the dates of the two versions of
> | interp2 I suspect that it is linked to the modification:
> | (XI,YI no longer need to be "meshgridded")
> |... 
> | Maybe a separate code should be foreseen in the case XI and YI are
> | vectors.
> 
> If you have a fix, how about submitting a patch?
> 
> Thanks,
> 
> jwe
> _______________________________________________
> Bug-octave mailing list
> Bug-octave at octave.org
> https://www.cae.wisc.edu/mailman/listinfo/bug-octave
> 
> 

Hello,
I would like to come back to the issue of the slow interp2. As it is used by
other functions (imrotate, imremap, ...) this is quite important.
I made a faster version:
http://www.nabble.com/file/p20177305/interp2.m interp2.m 

It uses faster code when XI and YI are vectors and when X and Y are not
given. Also in the general case it is faster.
It also removes a bug in the cubic interpolation that would give an error if
the matrix is not square.

I made a simple test program:
http://www.nabble.com/file/p20177305/interp2_benchmark.m interp2_benchmark.m 

The result with the old code:
cloetens at coral39:cloetens> interp2_benchmark(2048)
Interpolating 2047 x 2048 matrix ; nearest ; XI and YI are matrix : 11.6679
seconds
Interpolating 2047 x 2048 matrix ; nearest ; XI and YI are vector : 11.3098
seconds
Interpolating 2047 x 2048 matrix ; nearest ; X, Y, XI and YI are matrix :
11.1117 seconds
Interpolating 2047 x 2048 matrix ; linear ; XI and YI are matrix : 14.8497
seconds
Interpolating 2047 x 2048 matrix ; linear ; XI and YI are vector : 14.8174
seconds
Interpolating 2047 x 2048 matrix ; linear ; X, Y, XI and YI are matrix :
14.6365 seconds
error: X and Y size must match Z dimensions
error: evaluating if command near line 246, column 7
error: evaluating if command near line 243, column 5
error: evaluating if command near line 164, column 3
error: called from `interp2' in file
`/sware/pub/octave-3.0.1/redhate4.x86_64/share/octave/3.0.1/m/general/interp2.m'
error: evaluating for command near line 33, column 5
error: called from `interp2_benchmark' in file
`/users/cloetens/octave/interp2_benchmark.m'

The result with the new code:
cloetens at coral39:cloetens> interp2_benchmark(2048)
Interpolating 2047 x 2048 matrix ; nearest ; XI and YI are matrix : 2.31001
seconds
Interpolating 2047 x 2048 matrix ; nearest ; XI and YI are vector : 0.333178
seconds
Interpolating 2047 x 2048 matrix ; nearest ; X, Y, XI and YI are matrix :
7.03896 seconds
Interpolating 2047 x 2048 matrix ; linear ; XI and YI are matrix : 5.70732
seconds
Interpolating 2047 x 2048 matrix ; linear ; XI and YI are vector : 2.33167
seconds
Interpolating 2047 x 2048 matrix ; linear ; X, Y, XI and YI are matrix :
10.4666 seconds
Interpolating 2047 x 2048 matrix ; cubic ; XI and YI are matrix : 5.01822
seconds
Interpolating 2047 x 2048 matrix ; cubic ; XI and YI are vector : 4.8136
seconds
Interpolating 2047 x 2048 matrix ; cubic ; X, Y, XI and YI are matrix :
4.38982 seconds

Peter




-- 
View this message in context: http://www.nabble.com/speed-of-interp2-tp8791478p20177305.html
Sent from the Octave - Bugs mailing list archive at Nabble.com.



More information about the Bug-octave mailing list