comparison 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
comparison
equal deleted inserted replaced
32057:f010a32986e4 32058:e242124f1240
172 } 172 }
173 173
174 gen_specific() { 174 gen_specific() {
175 cat <<EOF 175 cat <<EOF
176 176
177 %% error handling in constructor
178 %!error <Invalid call> sparse ()
179 %!error <Invalid call> sparse (1,2,3,4,5,6,7)
180 %!warning <input array cast to double>
181 %! warning ("on", "Octave:sparse:double-conversion", "local");
182 %! s = sparse (single ([1 2]));
183 %!error <wrong type argument 'uint8 matrix'>
184 %! s = sparse (uint8 ([1 2]));
185 %% FIXME: negative dimensions are allowed and replaced with 0.
186 %% If this is fixed, re-instate these tests.
187 %!#error <dimensions must be non-negative> sparse (-1, 2)
188 %!#error <dimensions must be non-negative> sparse (1, -2)
189 %!error <dimension mismatch> sparse (1,[2,3],[1,2,3])
190 %!error <invalid option: foobar> sparse ([1,1],[1,1],[1,2],"foobar")
191 %% negative subscripts are disallowed
192 %!error <subscripts must be> sparse ([1,3],[1,-4],[3,5],2,2)
193 %!error <subscripts must be> sparse ([1,3],[1,-4],[3,5i],2,2)
194 %% FIXME: negative dimensions are allowed and replaced with 0.
195 %% If this is fixed, re-instate these tests.
196 %!#error <dimensions must be non-negative> sparse ([1,1],[1,1],[1,2], -1, 2)
197 %!#error <dimensions must be non-negative> sparse ([1,1],[1,1],[1,2], 1, -2)
198 %!warning <input array cast to double>
199 %! warning ("on", "Octave:sparse:double-conversion", "local");
200 %! s = sparse ([1,1],[1,1], single ([1,2]), 2, 2);
201 %!error <wrong type argument 'uint8 matrix'>
202 %! s = sparse ([1,1],[1,1], uint8 ([1,2]), 2, 2);
203
177 %!test # segfault test from edd@debian.org 204 %!test # segfault test from edd@debian.org
178 %! n = 510; 205 %! n = 510;
179 %! sparse (kron ((1:n)', ones (n,1)), kron (ones (n,1), (1:n)'), ones (n)); 206 %! sparse (kron ((1:n)', ones (n,1)), kron (ones (n,1), (1:n)'), ones (n));
180 207
181 %% segfault tests from Fabian@isas-berlin.de 208 %% segfault tests from Fabian@isas-berlin.de
187 %#!error inv ( sparse ([1,1;1,1] ) ); 214 %#!error inv ( sparse ([1,1;1,1] ) );
188 %#!error inv ( sparse ([0,0;0,1] ) ); 215 %#!error inv ( sparse ([0,0;0,1] ) );
189 %#!error inv ( sparse ([0,0;0,1+i]) ); 216 %#!error inv ( sparse ([0,0;0,1+i]) );
190 %#!error inv ( sparse ([0,0;0,0] ) ); 217 %#!error inv ( sparse ([0,0;0,0] ) );
191 218
192 %% error handling in constructor
193 %!error sparse (1,[2,3],[1,2,3])
194 %!error sparse ([1,1],[1,1],[1,2],3,3,"invalid")
195 %!error sparse ([1,3],[1,-4],[3,5],2,2)
196 %!error sparse ([1,3],[1,-4],[3,5i],2,2)
197 %!error sparse (-1,-1,1)
198 EOF 219 EOF
199 } 220 }
200 221
201 222
202 gen_specific_tests() { 223 gen_specific_tests() {