Mercurial > hg > octave-lyh
changeset 16935:a7b2fc7fe1a9
binocdf.m: Reverse calling convention to betaincinv to preserve accuracy when p =~ 1.
* scripts/statistics/distributions/binocdf.m: Reverse calling convention to
betaincinv to preserve accuracy when p =~ 1.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 09 Jul 2013 14:39:39 -0700 |
parents | 48f5b993b819 |
children | 8f0a82add3da |
files | doc/interpreter/expr.txi scripts/deprecated/isequalwithequalnans.m scripts/deprecated/module.mk scripts/general/isequal.m scripts/general/isequaln.m scripts/general/isequalwithequalnans.m scripts/general/module.mk scripts/statistics/distributions/binocdf.m |
diffstat | 7 files changed, 71 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/expr.txi +++ b/doc/interpreter/expr.txi @@ -796,7 +796,7 @@ @DOCSTRING(isequal) -@DOCSTRING(isequalwithequalnans) +@DOCSTRING(isequaln) @opindex <= @DOCSTRING(le)
rename from scripts/general/isequalwithequalnans.m rename to scripts/deprecated/isequalwithequalnans.m --- a/scripts/general/isequalwithequalnans.m +++ b/scripts/deprecated/isequalwithequalnans.m @@ -18,18 +18,22 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} isequalwithequalnans (@var{x1}, @var{x2}, @dots{}) -## Assuming NaN == NaN, return true if all of @var{x1}, @var{x2}, @dots{} -## are equal. -## @seealso{isequal} +## This function has been deprecated. Use @code{@file{isequaln}} instead. +## @seealso{isequaln} ## @end deftypefn -function retval = isequalwithequalnans (x1, varargin) +## Deprecated in 3.8 + +function retval = isequalwithequalnans (varargin) - if (nargin < 2) - print_usage (); + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "isequalwithequalnans is obsolete and will be removed from a future version of Octave, please use isequaln instead"); endif - retval = __isequal__ (true, x1, varargin{:}); + retval = isequaln (varargin{:}); endfunction
--- a/scripts/deprecated/module.mk +++ b/scripts/deprecated/module.mk @@ -9,6 +9,7 @@ deprecated/java_debug.m \ deprecated/error_text.m \ deprecated/gen_doc_cache.m \ + deprecated/isequalwithequalnans.m \ deprecated/isstr.m \ deprecated/java_convert_matrix.m \ deprecated/java_get.m \
--- a/scripts/general/isequal.m +++ b/scripts/general/isequal.m @@ -19,7 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} isequal (@var{x1}, @var{x2}, @dots{}) ## Return true if all of @var{x1}, @var{x2}, @dots{} are equal. -## @seealso{isequalwithequalnans} +## @seealso{isequaln} ## @end deftypefn function retval = isequal (x1, varargin) @@ -74,3 +74,7 @@ ## test for inequality (struct) %!assert (isequal (struct ('a',NaN,'b',2),struct ('a',NaN,'b',2),struct ('a',NaN,'b',2)), false) +## Input validation +%!error isequal () +%!error isequal (1) +
new file mode 100644 --- /dev/null +++ b/scripts/general/isequaln.m @@ -0,0 +1,50 @@ +## Copyright (C) 2005-2012 William Poetra Yoga Hadisoeseno +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} isequaln (@var{x1}, @var{x2}, @dots{}) +## Return true if all of @var{x1}, @var{x2}, @dots{} are equal under the +## additional assumption that NaN == NaN (no comparison of NaN placeholders +## in dataset). +## @seealso{isequal} +## @end deftypefn + +function retval = isequaln (x1, varargin) + + if (nargin < 2) + print_usage (); + endif + + retval = __isequal__ (true, x1, varargin{:}); + +endfunction + + +## test for equality +%!assert (isequaln ({1,2,NaN,4},{1,2,NaN,4}), true) +%!assert (isequaln ([1,2,NaN,4],[1,2,NaN,4]), true) +## test for inequality +%!assert (isequaln ([1,2,NaN,4],[1,NaN,3,4]), false) +%!assert (isequaln ([1,2,NaN,4],[1,2,3,4]), false) +## test for equality (struct) +%!assert (isequaln (struct ('a',NaN,'b',2),struct ('a',NaN,'b',2),struct ('a',NaN,'b',2)), true) +%!assert (isequaln (1,2,1), false) + +## Input validation +%!error isequaln () +%!error isequaln (1)
--- a/scripts/general/module.mk +++ b/scripts/general/module.mk @@ -46,7 +46,7 @@ general/iscolumn.m \ general/isdir.m \ general/isequal.m \ - general/isequalwithequalnans.m \ + general/isequaln.m \ general/isrow.m \ general/isscalar.m \ general/issquare.m \
--- a/scripts/statistics/distributions/binocdf.m +++ b/scripts/statistics/distributions/binocdf.m @@ -60,9 +60,9 @@ k = (x >= 0) & (x < n) & (n == fix (n)) & (p >= 0) & (p <= 1); tmp = floor (x(k)); if (isscalar (n) && isscalar (p)) - cdf(k) = 1 - betainc (p, tmp + 1, n - tmp); + cdf(k) = betainc (1 - p, n - tmp, tmp + 1); else - cdf(k) = 1 - betainc (p(k), tmp + 1, n(k) - tmp); + cdf(k) = betainc (1 .- p(k), n(k) - tmp, tmp + 1); endif endfunction