diff scripts/optimization/glpk.m @ 31347:800eb86438cc stable

glpk.m: Avoid using isfinite on potentially sparse input. * scripts/optimization/glpk.m: Sparse input to this function is likely mostly finite. Avoid using "isfinite" which might cause out of memory errors for sparsily populated input. Use "isinf" and "isnan" instead.
author Markus Mützel <markus.muetzel@gmx.de>
date Wed, 26 Oct 2022 18:56:06 +0200
parents 796f54d4ddbf
children 597f3ee61a48
line wrap: on
line diff
--- a/scripts/optimization/glpk.m	Tue Oct 25 10:15:28 2022 -0700
+++ b/scripts/optimization/glpk.m	Wed Oct 26 18:56:06 2022 +0200
@@ -489,7 +489,8 @@
     print_usage ();
   endif
 
-   if (! isvector (c) || iscomplex (c) || ischar (c) || any (! isfinite (c)))
+   if (! isvector (c) || iscomplex (c) || ischar (c) || any (isinf (c))
+       || any (isnan (c)))
      error ("glpk: C must be a real vector with finite values");
   endif
   nx = length (c);
@@ -504,7 +505,7 @@
   if (! isreal (A))
     error ("glpk: A must be real valued, not %s", typeinfo (A));
   endif
-  if (any (! isfinite (A(:))))
+  if (any (isinf (A(:))) || any (isnan (A(:))))
     error ("glpk: The values in A must be finite");
   endif