changeset 18429:90568d7fe382 stable

ppval.m: Return correctly sized output for scalar polynomial input (bug #41448). * ppval.m: Return correctly sized output for scalar polynomial input (bug #41448).
author Rik <rik@octave.org>
date Mon, 03 Feb 2014 14:25:11 -0800
parents 4d2e15abe5e7
children 155d8e90ee1f
files scripts/polynomial/ppval.m
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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 <argument must be a pp-form structure> ppval (1,2)
+%!error <argument must be a pp-form structure> ppval (struct ("a", 1), 2)
+%!error <argument must be a pp-form structure> ppval (struct ("form", "ab"), 2)
+