changeset 10885:36a7163a5484

unique.m: Handle corner case where sparse matrix is actually full.
author Rik <octave@nomad.inbox5.com>
date Wed, 11 Aug 2010 14:55:10 -0700
parents cc2bc3f46cd4
children 9993f1354713
files scripts/ChangeLog scripts/set/unique.m
diffstat 2 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed Aug 11 10:55:31 2010 +0200
+++ b/scripts/ChangeLog	Wed Aug 11 14:55:10 2010 -0700
@@ -1,3 +1,7 @@
+2010-08-11  Rik <octave@nomad.inbox5.com>
+
+	* set/unique.m: Handle corner case where sparse matrix is actually full.
+
 2010-08-10  Rik <octave@nomad.inbox5.com>
 
 	* set/unique.m: Check whether outputs are used before calculating.
--- a/scripts/set/unique.m	Wed Aug 11 10:55:31 2010 +0200
+++ b/scripts/set/unique.m	Wed Aug 11 14:55:10 2010 -0700
@@ -88,7 +88,12 @@
 
   if (exist ("issparse"))
     if (issparse (x) && ! optrows && nargout <= 1)
-      y = unique ([0; (full (nonzeros (x)))], varargin{:});
+      if (nnz (x) < numel (x)) 
+        y = unique ([0; (full (nonzeros (x)))], varargin{:});
+      else
+        ## Corner case where sparse matrix is actually full
+        y = unique (full (x), varargin{:});
+      endif
       return;
     endif
   endif
@@ -180,6 +185,9 @@
 %!assert(unique([1,2,2,3,2,4], 'rows'), [1,2,2,3,2,4])
 %!assert(unique([1,2,2,3,2,4]), [1,2,3,4])
 %!assert(unique([1,2,2,3,2,4]', 'rows'), [1,2,3,4]')
+%!assert(unique(sparse([2,0;2,0])), [0,2]')
+%!assert(unique(sparse([1,2;2,3])), [1,2,3]')
+%!assert(unique([1,2,2,3,2,4]', 'rows'), [1,2,3,4]')
 %!assert(unique(single([1,2,2,3,2,4]), 'rows'), single([1,2,2,3,2,4]))
 %!assert(unique(single([1,2,2,3,2,4])), single([1,2,3,4]))
 %!assert(unique(single([1,2,2,3,2,4]'), 'rows'), single([1,2,3,4]'))