changeset 12899:0ca8f06aba7a

maint: periodic merge of stable to default
author John W. Eaton <jwe@octave.org>
date Thu, 28 Jul 2011 12:00:43 -0400
parents 503865c2e542 (current diff) c68fe26745ae (diff)
children 00f5292aefeb 5d18231eee00
files
diffstat 3 files changed, 31 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/build-aux/bootstrap.conf
+++ b/build-aux/bootstrap.conf
@@ -21,6 +21,7 @@
   c-strcase
   copysign
   crypto/md5
+  fclose
   fcntl
   filemode
   fnmatch
@@ -51,6 +52,7 @@
   sleep
   stat
   stdint
+  stdio
   strftime
   strptime
   symlink
--- a/scripts/specfun/legendre.m
+++ b/scripts/specfun/legendre.m
@@ -166,7 +166,7 @@
     error ("legendre: N must be a non-negative scalar integer");
   endif
 
-  if (!isvector (x) || !isreal (x) || any (x < -1 | x > 1))
+  if (!isreal (x) || any (x(:) < -1 | x(:) > 1))
     error ("legendre: X must be real-valued vector in the range -1 <= X <= 1");
   endif
 
@@ -187,10 +187,7 @@
       error ('legendre: expecting NORMALIZATION option to be "norm", "sch", or "unnorm"');
   endswitch
 
-  if (rows (x) != 1)
-    x = x';
-  endif
-  scale = scale * ones (1, numel (x));
+  scale = scale * ones (size (x));
 
   ## Based on the recurrence relation below
   ##            m                 m              m
@@ -199,6 +196,7 @@
   ## http://en.wikipedia.org/wiki/Associated_Legendre_function
 
   overflow = false;
+  retval = zeros([n+1, size(x)]);
   for m = 1:n
     lpm1 = scale;
     lpm2 = (2*m-1) .* x .* scale;
@@ -217,7 +215,7 @@
         endif
       endif
     endfor
-    retval(m,:) = lpm3;
+    retval(m,:) = lpm3(:);
     if (strcmp (normalization, "unnorm"))
       scale = -scale * (2*m-1);
     else
@@ -227,7 +225,12 @@
     scale = scale .* sqrt(1-x.^2);
   endfor
 
-  retval(n+1,:) = scale;
+  retval(n+1,:) = scale(:);
+
+  if (isvector (x))
+  ## vector case is special
+    retval = reshape (retval, n + 1, length (x));
+  endif
 
   if (strcmp (normalization, "sch"))
     retval(1,:) = retval(1,:) / sqrt (2);
@@ -240,6 +243,7 @@
 
 endfunction
 
+
 %!test
 %! result = legendre (3, [-1.0 -0.9 -0.8]);
 %! expected = [
@@ -278,11 +282,25 @@
 %!test
 %! result = legendre (150, 0);
 %! ## This agrees with Matlab's result.
-%! assert (result(end), 3.7532741115719e+306, 0.0000000000001e+306)
+%! assert (result(end), 3.7532741115719e+306, 0.0000000000001e+306);
 
 %!test
 %! result = legendre (0, 0:0.1:1);
-%! assert (result, full(ones(1,11)))
+%! assert (result, full(ones(1,11)));
+
+%!test
+%! result = legendre (3, [-1,0,1;1,0,-1]);
+%! ## Test matrix input
+%! expected(:,:,1) = [-1,1;0,0;0,0;0,0];
+%! expected(:,:,2) = [0,0;1.5,1.5;0,0;-15,-15];
+%! expected(:,:,3) = [1,-1;0,0;0,0;0,0];
+%! assert (result, expected);
+
+%!test
+%! result = legendre (3, [-1,0,1;1,0,-1]');
+%! expected(:,:,1) = [-1,0,1;0,1.5,0;0,0,0;0,-15,0];
+%! expected(:,:,2) = [1,0,-1;0,1.5,0;0,0,0;0,-15,0];
+%! assert (result, expected);
 
 %% Check correct invocation
 %!error legendre ();
--- a/src/file-io.cc
+++ b/src/file-io.cc
@@ -666,14 +666,14 @@
 
   if (nargin == 1)
     {
-      if (nargout < 2 && args(0).is_string ())
+      if (args(0).is_string ())
         {
           // If there is only one argument and it is a string but it
           // is not the string "all", we assume it is a file to open
           // with MODE = "r".  To open a file called "all", you have
           // to supply more than one argument.
 
-          if (args(0).string_value () == "all")
+          if (nargout < 2 && args(0).string_value () == "all")
             return octave_stream_list::open_file_numbers ();
         }
       else