Mercurial > octave
changeset 30296:d6415c931759
uniquetol.m: Check for complex input (bug #59850).
* scripts/set/uniquetol.m: Input must be non-complex. Add BISTs.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Wed, 17 Nov 2021 18:06:04 +0100 |
parents | 1830a8f85476 |
children | 5ea881d55465 |
files | scripts/set/uniquetol.m |
diffstat | 1 files changed, 12 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/set/uniquetol.m Fri Nov 12 15:24:01 2021 +0100 +++ b/scripts/set/uniquetol.m Wed Nov 17 18:06:04 2021 +0100 @@ -112,16 +112,17 @@ return; endif - if (! isfloat (A)) + if (! isfloat (A) || iscomplex (A)) error ("Octave:uniquetol:unsupported-type", - "uniquetol: A must be a double or single precision array"); + "uniquetol: A must be a double or single precision non-complex array"); endif if (nargin == 1 || ischar (varargin{1})) tol = ifelse (isa (A, "double"), 1e-12, 1e-6); - elseif (! (isfloat (varargin{1}) && isscalar (varargin{1}))) + elseif (! (isfloat (varargin{1}) && isscalar (varargin{1})) + || iscomplex (varargin{1})) error ("Octave:uniquetol:unsupported-type", - "uniquetol: TOL must be a double or single precision scalar"); + "uniquetol: TOL must be a double or single precision non-complex scalar"); else tol = varargin{1}; varargin(1) = []; @@ -149,8 +150,8 @@ output_all_indices = logical (varargin{k+1}); elseif (strcmpi (varargin{k}, "DataScale")) data_scale = varargin{k+1}(:).'; - if (! isfloat (data_scale) || any (data_scale(:) < 0) - || any (isnan (data_scale(:)))) + if (! isfloat (data_scale) || iscomplex (data_scale) + || any (data_scale(:) < 0) || any (isnan (data_scale(:)))) error ("uniquetol: DataScale must be a non-NaN, positive floating point scalar or vector"); endif cols_data_scale = columns (data_scale); @@ -345,14 +346,17 @@ ## Test input validation %!error <Invalid call> uniquetol () -%!error <A must be a double or single precision array> uniquetol (int8 (1)) +%!error <A must be a double or single precision> uniquetol (int8 (1)) +%!error <A must be .* non-complex> uniquetol (1i) %!error <TOL must be a double .* precision> uniquetol (1, int8 (1)) %!error <TOL must be a .* scalar> uniquetol (1, [1, 2]) +%!error <TOL must be .* non-complex> uniquetol (1, 1i) %!error <arguments must be passed in pairs> uniquetol (1, 2, "byrows") %!error <PROPERTY must be a string> uniquetol (1, 2, 3, "bar") %!error <A must be a 2-D array> uniquetol (ones(2,2,2), "byrows", true) %!error <DataScale must be a .* floating point> uniquetol (1, "DataScale", '1') -%!error <DataScale must be a .* positive> uniquetol (1, "DataScale", -1) +%!error <DataScale must be .* positive> uniquetol (1, "DataScale", -1) +%!error <DataScale must be .* positive> uniquetol (1, "DataScale", 1i) %!error <DataScale must be a non-NaN> uniquetol (1, "DataScale", NaN) %!error <invalid DataScale size> uniquetol (1, "DataScale", [1 2]) %!error <unknown property 'foo'> uniquetol (1, "foo", "bar")