# HG changeset patch # User Rik # Date 1391466311 28800 # Node ID 90568d7fe38269bc9777fa7a4589aed8e506817e # Parent 4d2e15abe5e7e2e3def440fe95d3da71fc44c80c ppval.m: Return correctly sized output for scalar polynomial input (bug #41448). * ppval.m: Return correctly sized output for scalar polynomial input (bug #41448). diff -r 4d2e15abe5e7 -r 90568d7fe382 scripts/polynomial/ppval.m --- a/scripts/polynomial/ppval.m Sat Feb 01 00:16:17 2014 +0100 +++ b/scripts/polynomial/ppval.m Mon Feb 03 14:25:11 2014 -0800 @@ -32,7 +32,7 @@ if (nargin != 2) print_usage (); endif - if (! (isstruct (pp) && strcmp (pp.form, "pp"))) + if (! (isstruct (pp) && isfield (pp, "form") && strcmp (pp.form, "pp"))) error ("ppval: first argument must be a pp-form structure"); endif @@ -54,7 +54,7 @@ P = reshape (P, [d, n * k]); P = shiftdim (P, nd); P = reshape (P, [n, k, d]); - Pidx = P(idx(:), :);#2d matrix size x: coefs*prod(d) y: prod(sxi) + Pidx = P(idx(:), :); # 2D matrix size: x = coefs*prod(d), y = prod(sxi) if (isvector (xi)) Pidx = reshape (Pidx, [xn, k, d]); @@ -96,10 +96,9 @@ yi = shiftdim (yi, nd); endif - ## FIXME: Why is this commented out, rather than just removed? - #if (d == 1) - # yi = reshape (yi, sxi); - #endif + if (d == 1) + yi = reshape (yi, sxi); + endif endfunction @@ -111,6 +110,7 @@ %! abserr = 1e-14; %! pp2 = mkpp (b, [c;c], 2); %! xi = [1.1 1.3 1.9 2.1]; +%! %!assert (ppval (pp, 1.1), 1.1, abserr) %!assert (ppval (pp, 2.1), 1.1, abserr) %!assert (ppval (pp, xi), [1.1 1.3 1.9 1.1], abserr) @@ -120,6 +120,8 @@ %!assert (ppval (pp2, xi), [1.1 1.3 1.9 1.1;1.1 1.3 1.9 1.1], abserr) %!assert (ppval (pp2, xi'), [1.1 1.3 1.9 1.1;1.1 1.3 1.9 1.1], abserr) %!assert (size (ppval (pp2, [xi;xi])), [2 2 4]) +%!assert (ppval (mkpp([0 1],1), magic (3)), ones(3,3)) +%! %!test %! breaks = [0, 1, 2, 3]; %! coefs = rand (6, 4); @@ -129,3 +131,11 @@ %! ret(:,:,2) = ppval (pp, breaks'); %! assert (ppval (pp, [breaks',breaks']), ret) +%% Test input validation +%!error ppval () +%!error ppval (1) +%!error ppval (1,2,3) +%!error ppval (1,2) +%!error ppval (struct ("a", 1), 2) +%!error ppval (struct ("form", "ab"), 2) +