Mercurial > octave-nkf
comparison scripts/set/unique.m @ 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 | 055b95863699 |
children | ffb2f1ef2097 |
comparison
equal
deleted
inserted
replaced
10884:cc2bc3f46cd4 | 10885:36a7163a5484 |
---|---|
86 ## issparse is not yet available because it is coming from a .oct | 86 ## issparse is not yet available because it is coming from a .oct |
87 ## file?!? | 87 ## file?!? |
88 | 88 |
89 if (exist ("issparse")) | 89 if (exist ("issparse")) |
90 if (issparse (x) && ! optrows && nargout <= 1) | 90 if (issparse (x) && ! optrows && nargout <= 1) |
91 y = unique ([0; (full (nonzeros (x)))], varargin{:}); | 91 if (nnz (x) < numel (x)) |
92 y = unique ([0; (full (nonzeros (x)))], varargin{:}); | |
93 else | |
94 ## Corner case where sparse matrix is actually full | |
95 y = unique (full (x), varargin{:}); | |
96 endif | |
92 return; | 97 return; |
93 endif | 98 endif |
94 endif | 99 endif |
95 | 100 |
96 if (optrows) | 101 if (optrows) |
178 %!assert(unique(cell(1,0)), cell(0,1)) | 183 %!assert(unique(cell(1,0)), cell(0,1)) |
179 %!assert(unique({}), {}) | 184 %!assert(unique({}), {}) |
180 %!assert(unique([1,2,2,3,2,4], 'rows'), [1,2,2,3,2,4]) | 185 %!assert(unique([1,2,2,3,2,4], 'rows'), [1,2,2,3,2,4]) |
181 %!assert(unique([1,2,2,3,2,4]), [1,2,3,4]) | 186 %!assert(unique([1,2,2,3,2,4]), [1,2,3,4]) |
182 %!assert(unique([1,2,2,3,2,4]', 'rows'), [1,2,3,4]') | 187 %!assert(unique([1,2,2,3,2,4]', 'rows'), [1,2,3,4]') |
188 %!assert(unique(sparse([2,0;2,0])), [0,2]') | |
189 %!assert(unique(sparse([1,2;2,3])), [1,2,3]') | |
190 %!assert(unique([1,2,2,3,2,4]', 'rows'), [1,2,3,4]') | |
183 %!assert(unique(single([1,2,2,3,2,4]), 'rows'), single([1,2,2,3,2,4])) | 191 %!assert(unique(single([1,2,2,3,2,4]), 'rows'), single([1,2,2,3,2,4])) |
184 %!assert(unique(single([1,2,2,3,2,4])), single([1,2,3,4])) | 192 %!assert(unique(single([1,2,2,3,2,4])), single([1,2,3,4])) |
185 %!assert(unique(single([1,2,2,3,2,4]'), 'rows'), single([1,2,3,4]')) | 193 %!assert(unique(single([1,2,2,3,2,4]'), 'rows'), single([1,2,3,4]')) |
186 %!assert(unique(uint8([1,2,2,3,2,4]), 'rows'), uint8([1,2,2,3,2,4])) | 194 %!assert(unique(uint8([1,2,2,3,2,4]), 'rows'), uint8([1,2,2,3,2,4])) |
187 %!assert(unique(uint8([1,2,2,3,2,4])), uint8([1,2,3,4])) | 195 %!assert(unique(uint8([1,2,2,3,2,4])), uint8([1,2,3,4])) |