bug in interpn for method linear and nearest

Alexander Barth barth.alexander at gmail.com
Mon Jan 21 15:23:47 CST 2008


On Jan 21, 2008 2:07 PM, David Bateman <David.Bateman at motorola.com> wrote:

> Alexander Barth wrote:
> > Hi all,
> > I think there are some bugs in interpn (octave 3.0.0 and current cvs).
> > * method = linear: in matlab I get for:
> >
> > >> [x,y,z] = ndgrid(0:2);
> > >> f = x+y+z;
> > >> fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5])
> >
> > fi =
> >
> >     1.5000    4.5000
> >
> > In octave:
> > octave:4> [x,y,z] = ndgrid(0:2);
> > octave:5> f = x+y+z;
> > octave:6> fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5])
> > fi =
> >
> > ans(:,:,1) =
> >
> >    1.5000   2.5000
> >    2.5000   3.5000
> >
> > ans(:,:,2) =
> >
> >    2.5000   3.5000
> >    3.5000   4.5000
> >
> > Matlab and octave do different things here. The coordinates of the
> > interpolated locations are 'ndgrid'ed in octave. (note that interp2 in
> > octave does not pass the interpolated locations by meshgrid).
> >
> > * method = 'nearest'
> >
> > The following fails in octave:
> > octave:7> fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],'nearest')
> > error: operator -: nonconformant arguments (op1 is 8x1, op2 is 1x8)
> > error: evaluating binary operator `-' near line 162, column 36
> > error: evaluating binary operator `>' near line 162, column 54
> > error: evaluating binary operator `+' near line 162, column 27
> > error: evaluating assignment expression near line 162, column 16
> > error: evaluating for command near line 161, column 5
> > error: evaluating if command near line 150, column 3
> > error: called from `interpn' in file
> > `/u/abarth/local/share/octave/2.9.17/m/general/interpn.m'
> > error: evaluating assignment expression near line 7, column 4
> >
> > while in matlab:
> > >>  fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],'nearest')
> >
> > fi =
> >
> >      3     6
> >
> > * A minor issue is that the string method is transformed to lowercase
> > a couple of lines too late in the code.
> >
> > I attached is a tentative patch. I don't fully understand interpn.m,
> > so it would be great if someone could confirm the modifications.
> >
> > Thanks
> > Alex
> >
>
> I pretty much hacked interpn.m together when porting code from
> octave-forge, as it seemed relatively easy to do at the time. It looks
> like you found a real bug and a real incompatibility. Yes i think your
> patch is right, though the commented section should be removed
> completely and the example code you supplied should be added as a test.
> Consider the attached patch instead based on your patch.
>
> D.
>

Thank you for reply. I tried to apply your revised patch, but I got this
error:
laptop:~/Octave/CVS/octave$ patch < interpn.patch
patch: **** Overdue `---' at line 16; check line numbers at line 4

Do I apply it correctly?
In the attached patch, I added the test-case and removed the commended code
as you pointed-out.
I also included a test-case for the spline interpolation and we have the
same incompatibility:
octave:5> [x,y,z] = ndgrid(0:2);
octave:6> f = x+y+z;
octave:7> fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],'spline')
fi =

ans(:,:,1) =

   1.5000   2.5000
   2.5000   3.5000

ans(:,:,2) =

   2.5000   3.5000
   3.5000   4.5000

(should be just [1.5000    4.5000])

Sorry, I don't understand the spline-code well enough to propose a patch for
this.

Cheers,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080121/ced52e1f/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interpn_with_tests.patch
Type: text/x-patch
Size: 1854 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080121/ced52e1f/attachment.bin 


More information about the Bug-octave mailing list