# HG changeset patch # User John W. Eaton # Date 1311868843 14400 # Node ID 0ca8f06aba7a59b5e7bad4a92ff73e1222760b26 # Parent 503865c2e542ae1b37b2be715d4d36346436b7a8# Parent c68fe26745aeb046d3c5adb7b2fac4342a63ce70 maint: periodic merge of stable to default diff --git a/build-aux/bootstrap.conf b/build-aux/bootstrap.conf --- 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 diff --git a/scripts/specfun/legendre.m b/scripts/specfun/legendre.m --- 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 (); diff --git a/src/file-io.cc b/src/file-io.cc --- 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 diff --git a/src/mappers.cc b/src/mappers.cc