comparison libinterp/corefcn/inv.cc @ 30609:09012191bb0c

pinv: Improve input validation (Bug #61767). * pinv.cc (Fpinv): Early exit with error() for non-numeric input. Additional tests for input validation * inv.cc (Finv): Additional BIST tests for integer inputs.
author Antonius Burgers <arburgers@gmail.com>
date Thu, 06 Jan 2022 10:38:22 +0100
parents 50bf281760e0
children 24e45a79bf3c
comparison
equal deleted inserted replaced
30608:22ecbc9551a5 30609:09012191bb0c
236 %!test 236 %!test
237 %! [xinv, rcond] = inv (single ([1,2;3,4])); 237 %! [xinv, rcond] = inv (single ([1,2;3,4]));
238 %! assert (xinv, single ([-2, 1; 1.5, -0.5]), 5*eps ("single")); 238 %! assert (xinv, single ([-2, 1; 1.5, -0.5]), 5*eps ("single"));
239 %! assert (isa (rcond, "single")); 239 %! assert (isa (rcond, "single"));
240 240
241 ## Basic test for integer inputs
242 %!assert (inv (int32 (2)), 0.5)
243 %!assert (inv (uint32 (2)), 0.5)
244 %!assert (inv (int64 (2)), 0.5)
245 %!assert (inv (uint64 (2)), 0.5)
246
241 ## Normal scalar cases 247 ## Normal scalar cases
242 %!assert (inv (2), 0.5) 248 %!assert (inv (2), 0.5)
243 %!test 249 %!test
244 %! [xinv, rcond] = inv (2); 250 %! [xinv, rcond] = inv (2);
245 %! assert (xinv, 0.5); 251 %! assert (xinv, 0.5);
378 384
379 %!error <Invalid call> inv () 385 %!error <Invalid call> inv ()
380 %!error <Invalid call> inv ([1, 2; 3, 4], 2) 386 %!error <Invalid call> inv ([1, 2; 3, 4], 2)
381 %!error <wrong type argument> inv ("Hello World") 387 %!error <wrong type argument> inv ("Hello World")
382 %!error <wrong type argument> inv ({1}) 388 %!error <wrong type argument> inv ({1})
389 %!error <wrong type argument> inv (true)
383 %!error <must be a square matrix> inv ([1, 2; 3, 4; 5, 6]) 390 %!error <must be a square matrix> inv ([1, 2; 3, 4; 5, 6])
384 %!error <inverse of the null matrix not defined> inv (sparse (2, 2, 0)) 391 %!error <inverse of the null matrix not defined> inv (sparse (2, 2, 0))
385 %!error <inverse of the null matrix not defined> inv (diag ([0, 0])) 392 %!error <inverse of the null matrix not defined> inv (diag ([0, 0]))
386 %!error <inverse of the null matrix not defined> inv (diag (complex ([0, 0]))) 393 %!error <inverse of the null matrix not defined> inv (diag (complex ([0, 0])))
387 */ 394 */