changeset 17278:79d4b6089968

Fix isequal for sparse matrix (bug #37321) * Sparse-op-defs.h (SPARSE_BASE_REDUCTION_OP): Fix typo in indexing * __isequal__.m: Always return logical * isequal.m, Sparse.cc: Add tests
author Stefan Mahr <dac922@gmx.de>
date Mon, 19 Aug 2013 11:19:41 +0200
parents eb8bf49780fb
children 9a2422e40f76
files liboctave/array/Sparse.cc liboctave/operators/Sparse-op-defs.h scripts/general/isequal.m scripts/general/private/__isequal__.m
diffstat 4 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/Sparse.cc	Mon Aug 19 08:09:04 2013 -0400
+++ b/liboctave/array/Sparse.cc	Mon Aug 19 11:19:41 2013 +0200
@@ -2793,6 +2793,19 @@
 %! s(1,:) = [];
 %! assert (s, sparse ([], [], [], 0, 1));
 
+## Test (bug #37321)
+
+%!test a=sparse (0,0); assert (all (a)==sparse ([1]))
+%!test a=sparse (0,1); assert (all (a)==sparse ([1]))
+%!test a=sparse (1,0); assert (all (a)==sparse ([1]))
+%!test a=sparse (1,0); assert (all (a,2)==sparse ([1]))
+%!test a=sparse (1,0); assert (isequal (size (all (a,1)),[1 0]))
+%!test a=sparse (1,1); assert (all (a)==sparse ([0])), assert (isequal (size (all (a)),[1 1]))
+%!test a=sparse (2,1); assert (all (a)==sparse ([0])), assert (isequal (size (all (a)),[1 1]))
+%!test a=sparse (1,2); assert (all (a)==sparse ([0])), assert (isequal (size (all (a)),[1 1]))
+%!test a=sparse (2,2); assert (isequal(all (a),sparse ([0 0])))
+
+
 */
 
 template <class T>
--- a/liboctave/operators/Sparse-op-defs.h	Mon Aug 19 08:09:04 2013 -0400
+++ b/liboctave/operators/Sparse-op-defs.h	Mon Aug 19 11:19:41 2013 +0200
@@ -1766,7 +1766,7 @@
           for (octave_idx_type i = 0; i < nc ; i++) \
             { \
               retval.ridx (i) = 0; \
-              retval.cidx (i+1) = i; \
+              retval.cidx (i+1) = i+1; \
               retval.data (i) = MT_RESULT; \
             } \
         } \
--- a/scripts/general/isequal.m	Mon Aug 19 08:09:04 2013 -0400
+++ b/scripts/general/isequal.m	Mon Aug 19 11:19:41 2013 +0200
@@ -74,6 +74,11 @@
 ## test for inequality (struct)
 %!assert (isequal (struct ('a',NaN,'b',2),struct ('a',NaN,'b',2),struct ('a',NaN,'b',2)), false)
 
+## test for sparse matrices
+%!assert (isequal (sparse (0,1), sparse (0,1)), true)
+%!assert (isequal (sparse (0,1), sparse (1,0)), false)
+%!assert (isequal (sparse (2, 2), sparse (2, 2)), true)
+
 ## Input validation
 %!error isequal ()
 %!error isequal (1)
--- a/scripts/general/private/__isequal__.m	Mon Aug 19 08:09:04 2013 -0400
+++ b/scripts/general/private/__isequal__.m	Mon Aug 19 11:19:41 2013 +0200
@@ -156,7 +156,7 @@
 
         t = (l_f_x == length (f_y)) && all (f_x == f_y);
         if (!t)
-          return;
+          break;
         endif
 
         y = y(f_y);
@@ -168,11 +168,17 @@
         endif
 
         if (!t)
-          return;
+          break;
         endif
       endfor
 
     endif
   endif
 
+  if (!t)
+    t=logical(0);
+  else
+    t=logical(1);
+  endif
+
 endfunction