diff scripts/linear-algebra/cond.m @ 31357:303bbdc3c536

Avoid out-of-memory errors for sparse matrices and ! isfinite usage. * cond.m: Replace "! isifinite (A)" input validation with a try/catch block because svd() already performs this check. * mustBeInteger.m: Use "! isfinite" for full matrices and "isinf (x) || isnan (x)" test for sparse matrices.
author Rik <rik@octave.org>
date Thu, 27 Oct 2022 14:54:27 -0700
parents 5d3faba0342e
children 597f3ee61a48
line wrap: on
line diff
--- a/scripts/linear-algebra/cond.m	Thu Oct 27 10:38:47 2022 -0400
+++ b/scripts/linear-algebra/cond.m	Thu Oct 27 14:54:27 2022 -0700
@@ -64,10 +64,12 @@
   if (p == 2)
     if (isempty (A))
       c = 0.0;
-    elseif (any (! isfinite (A(:))))
-      error ("cond: A must not contain Inf or NaN values");
     else
-      sigma   = svd (A);
+      try
+        sigma = svd (A);
+      catch
+        error ("cond: A must not contain Inf or NaN values");
+      end_try_catch
       sigma_1 = sigma(1);
       sigma_n = sigma(end);
       if (sigma_1 == 0 || sigma_n == 0)