# HG changeset patch # User dbateman # Date 1201294946 0 # Node ID 1c7b3e1fda19c8360da4468bd3a60ef349b15e30 # Parent 4b17a7297e5db92d4201ee05f9ba20436b03600f [project @ 2008-01-25 21:00:42 by dbateman] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,13 @@ +2008-01-25 Alexander Barth + + * general/interpn.m: Compatibility fix. Don't ndgrid vector + abscissa. + +2008-01-25 David Bateman + + * plot/__scatter__.m: Remove NaN values from data. + * plot/__patch__.m: Vectorize treatment of trailing NaN values. + 2008-01-25 Thomas Weber * linear-algebra/trace.m: Test cases for non 2-d args. diff --git a/scripts/general/interpn.m b/scripts/general/interpn.m --- a/scripts/general/interpn.m +++ b/scripts/general/interpn.m @@ -134,19 +134,8 @@ x{1} = x{1}(idx{:})(:); endif - if (strcmp (method, "linear") || strcmp (method, "nearest")) - if (all (cellfun (@isvector, y))) - [y{:}] = ndgrid (y{:}); - endif - elseif (any (! cellfun (@isvector, y))) - for i = 1 : nd - idx (1 : nd) = {1}; - idx (i) = ":"; - y{i} = y{i}(idx{:})(:).'; - endfor - endif + method = tolower (method); - method = tolower (method); if (strcmp (method, "linear")) vi = __lin_interpn__ (x{:}, v, y{:}); vi (isna (vi)) = extrapval; @@ -159,7 +148,7 @@ endfor idx = cell (1,nd); for i = 1 : nd - idx{i} = yidx{i} + (y{i} - x{i}(yidx{i}).' > x{i}(yidx{i} + 1).' - y{i}); + idx{i} = yidx{i} + (y{i} - x{i}(yidx{i}) > x{i}(yidx{i} + 1) - y{i}); endfor vi = v (sub2ind (sz, idx{:})); idx = zeros (prod(yshape),1); @@ -169,7 +158,17 @@ vi(idx) = extrapval; vi = reshape (vi, yshape); elseif (strcmp (method, "spline")) + szi = size (y{1}); + for i = 1 : nd + y{i} = y{i}(:); + endfor + vi = __splinen__ (x, v, y, extrapval, "interpn"); + + ## get all diagonal elements of vi + sc = sum ([1 cumprod(size (vi)(1:end-1))]); + vi = vi(sc * [0:size(vi,1)-1] + 1); + vi = reshape (vi,szi); elseif (strcmp (method, "cubic")) error ("cubic interpolation not yet implemented"); else @@ -182,7 +181,7 @@ %! A=[13,-1,12;5,4,3;1,6,2]; %! x=[0,1,4]; y=[10,11,12]; %! xi=linspace(min(x),max(x),17); -%! yi=linspace(min(y),max(y),26)'; +%! AI=linspace(min(y),max(y),26)'; %! mesh(xi,yi,interpn(x,y,A.',xi,yi,"linear").'); %! [x,y] = meshgrid(x,y); %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off; @@ -225,3 +224,13 @@ %! vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline'); %! mesh (yi, zi, squeeze (vi(1,:,:))); + +%!test +%! [x,y,z] = ndgrid(0:2); +%! f = x+y+z; +%! assert (interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5]), [1.5, 4.5]) +%! assert (interpn(x,y,z,f,[.51 1.51],[.51 1.51],[.51 1.51],'nearest'), [3, 6]) +%! assert (interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],'spline'), [1.5, 4.5]) +%! assert (interpn(x,y,z,f,x,y,z), f) +%! assert (interpn(x,y,z,f,x,y,z,'nearest'), f) +%! assert (interpn(x,y,z,f,x,y,z,'spline'), f) diff --git a/scripts/plot/__patch__.m b/scripts/plot/__patch__.m --- a/scripts/plot/__patch__.m +++ b/scripts/plot/__patch__.m @@ -124,13 +124,13 @@ nr = size (faces, 2); nc = size (faces, 1); idx = faces .'; - for i = 1: nc - t1 = isnan (idx (:,i)); - if (any (t1)) - t2 = find (t1(1:end-1) != t1(2:end))(1); - idx(t1,i) = idx(t2,i); - endif - endfor + t1 = isnan (idx); + if (any (t1)) + t2 = find (t1 != t1([2:end,end],:)); + idx (t1) = idx (t2 (cell2mat (cellfun (@(x) x(1)*ones(1,x(2)), + mat2cell ([1 : length(t2); sum(t1)], 2, ones(1,length(t2))), + "UniformOutput", false)))); + endif x = reshape (vert(:,1)(idx), size (idx)); y = reshape (vert(:,2)(idx), size (idx)); if (size(vert,2) > 2) diff --git a/scripts/plot/__scatter__.m b/scripts/plot/__scatter__.m --- a/scripts/plot/__scatter__.m +++ b/scripts/plot/__scatter__.m @@ -29,8 +29,15 @@ if (nd == 3) z = varargin{6}(:); + idx = isnan(x) | isnan (y) | isnan (z); + x (idx) = []; + y (idx) = []; + z (idx) = []; istart = 7; else + idx = isnan(x) | isnan (y); + x (idx) = []; + y (idx) = []; z = zeros (length (x), 0); endif diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-01-25 David Bateman + + * DLD-FUNCTIONS/rand.cc (Frandp): Relax relative error on randp + tests. + 2008-01-25 Michael Goffioul * graphics.h.in (base_properties::get_backend, diff --git a/src/DLD-FUNCTIONS/rand.cc b/src/DLD-FUNCTIONS/rand.cc --- a/src/DLD-FUNCTIONS/rand.cc +++ b/src/DLD-FUNCTIONS/rand.cc @@ -937,7 +937,7 @@ %!test %! % Test fixed state %! randp("state",1); -%! assert(randp(1e9,1,6),[999915677 999976657 1000047684 1000019035 999985749 999977692],1e-6) +%! assert(randp(1e9,1,6),[999915677 999976657 1000047684 1000019035 999985749 999977692],-1e-6) %!test %! % Test fixed state %! randp("seed",1); @@ -950,7 +950,7 @@ %!test %! % Test fixed state %! randp("seed",1); -%! assert(randp(1e9,1,6),[1000006208 1000012224 999981120 999963520 999963072 999981440]) +%! assert(randp(1e9,1,6),[1000006208 1000012224 999981120 999963520 999963072 999981440],-1e-6) %!test %! if (__random_statistical_tests__) %! % statistical tests may fail occasionally.