Mercurial > octave
diff test/mk-sparse-tst.sh @ 32058:e242124f1240
Overhaul input validation of sparse() function.
* sparse.cc (Fsparse): Decode input type and identify floating point inputs.
If input is of single type, emit new warning "Octave:sparse:double-conversion".
If input is neither floating point or logical, then call err_wrong_type_arg()
for pretty error message. Rename temporary variable 'k' to "argidx" for clarity.
New temporary variable "arg" to increase readability of code. Add FIXME note
about unreachable code due to behavior of get_dimensions().
* sparse.cc (Fissparse): Turn off warning about double-conversion temporarily
for test which has single input.
* warning_ids.m: Add description for new warning ID
"Octave:sparse:double-conversion".
* mk-sparse-tst.sh: Redo BIST tests for sparse() construction.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 26 Apr 2023 10:09:09 -0700 |
parents | 939e5d952675 |
children | bade9602c5a1 |
line wrap: on
line diff
--- a/test/mk-sparse-tst.sh Wed Apr 26 09:55:12 2023 -0700 +++ b/test/mk-sparse-tst.sh Wed Apr 26 10:09:09 2023 -0700 @@ -174,6 +174,33 @@ gen_specific() { cat <<EOF +%% error handling in constructor +%!error <Invalid call> sparse () +%!error <Invalid call> sparse (1,2,3,4,5,6,7) +%!warning <input array cast to double> +%! warning ("on", "Octave:sparse:double-conversion", "local"); +%! s = sparse (single ([1 2])); +%!error <wrong type argument 'uint8 matrix'> +%! s = sparse (uint8 ([1 2])); +%% FIXME: negative dimensions are allowed and replaced with 0. +%% If this is fixed, re-instate these tests. +%!#error <dimensions must be non-negative> sparse (-1, 2) +%!#error <dimensions must be non-negative> sparse (1, -2) +%!error <dimension mismatch> sparse (1,[2,3],[1,2,3]) +%!error <invalid option: foobar> sparse ([1,1],[1,1],[1,2],"foobar") +%% negative subscripts are disallowed +%!error <subscripts must be> sparse ([1,3],[1,-4],[3,5],2,2) +%!error <subscripts must be> sparse ([1,3],[1,-4],[3,5i],2,2) +%% FIXME: negative dimensions are allowed and replaced with 0. +%% If this is fixed, re-instate these tests. +%!#error <dimensions must be non-negative> sparse ([1,1],[1,1],[1,2], -1, 2) +%!#error <dimensions must be non-negative> sparse ([1,1],[1,1],[1,2], 1, -2) +%!warning <input array cast to double> +%! warning ("on", "Octave:sparse:double-conversion", "local"); +%! s = sparse ([1,1],[1,1], single ([1,2]), 2, 2); +%!error <wrong type argument 'uint8 matrix'> +%! s = sparse ([1,1],[1,1], uint8 ([1,2]), 2, 2); + %!test # segfault test from edd@debian.org %! n = 510; %! sparse (kron ((1:n)', ones (n,1)), kron (ones (n,1), (1:n)'), ones (n)); @@ -189,12 +216,6 @@ %#!error inv ( sparse ([0,0;0,1+i]) ); %#!error inv ( sparse ([0,0;0,0] ) ); -%% error handling in constructor -%!error sparse (1,[2,3],[1,2,3]) -%!error sparse ([1,1],[1,1],[1,2],3,3,"invalid") -%!error sparse ([1,3],[1,-4],[3,5],2,2) -%!error sparse ([1,3],[1,-4],[3,5i],2,2) -%!error sparse (-1,-1,1) EOF }