changeset 18421:7c0db9c4e454

issymmetric.m: Fix OOM when run on large sparse matrices (bug #41426) * issymmetric.m: Avoid using '(:)' which creates an index vector which may exceed idx_vector_type when used on sparse matrices.
author David Spies <davidnspies@gmail.com>
date Sun, 02 Feb 2014 20:26:28 -0800
parents c2d1869a95ee
children be3702a2eb8a
files scripts/linear-algebra/issymmetric.m
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/linear-algebra/issymmetric.m	Sun Feb 02 16:01:10 2014 -0800
+++ b/scripts/linear-algebra/issymmetric.m	Sun Feb 02 20:26:28 2014 -0800
@@ -40,7 +40,8 @@
   retval = isnumeric (x) && issquare (x);
   if (retval)
     if (tol == 0)
-      retval = all ((x == x.')(:));
+      ## Handle large sparse matrices as well as full ones
+      retval = nnz (x != x.') == 0;
     else
       norm_x = norm (x, inf);
       retval = norm_x == 0 || norm (x - x.', inf) / norm_x <= tol;
@@ -59,6 +60,7 @@
 %!assert (issymmetric ([1, 2i; 2i, 1]))
 %!assert (! (issymmetric ("t")))
 %!assert (! (issymmetric (["te"; "et"])))
+%!assert (issymmetric (speye (100000)))
 
 %!test
 %! s.a = 1;