I'm working with a large (16793600x400) logical sparse
array named hits, and when I try to access multiple rows of
the array at once, I get less elements than when I access
the rows individually. For example:
K>> whos hits
Name Size Bytes Class
Attributes
hits 16793600x400 2049604 logical
sparse
K>> hits(9018812,300:400)
ans =
(1,15) 1
(1,17) 1
(1,44) 1
(1,62) 1
(1,66) 1
(1,98) 1
K>> hits(9018843,300:400)
ans =
(1,1) 1
(1,87) 1
K>> hits([9018812 9018843],300:400)
ans =
(2,1) 1
(1,15) 1
(1,17) 1
(1,44) 1
(1,62) 1
(1,66) 1
(1,98) 1
K>> hits(9018843,386)
ans =
1
The element at hits(9018843,386) is there when I access it
individually or with a single row index, but when I try and
use a subset of the array it dissapears.
Anyone know what's going on?
Bruno Luong - 30 Jul 2008 22:57 GMT
It looks like a BUG to me on old MATLAB versions:
I run this on both 2006B and 2008A, Windows Vista 32 bits.
i=[9018812+zeros(1,6) 9018843+zeros(1,2)];
j=[15 17 44 62 66 98 1 87]-1+300;
s=logical(ones(1,8));
S=sparse(i,j,s,16793600,400);
S([9018812 9018843],300:400)
%%%%%%%%%%%%%%%%%%%%%
% 2006B, Bug
>> S([9018812 9018843],300:400)
ans =
(1,15) 1
(1,17) 1
(1,44) 1
(1,62) 1
(1,66) 1
(1,98) 1
%%%%%%%%%%%%%%%%%%%%
% 2008B, OK
>> S([9018812 9018843],300:400)
ans =
(2,1) 1
(1,15) 1
(1,17) 1
(1,44) 1
(1,62) 1
(1,66) 1
(2,87) 1
(1,98) 1
% Bruno
Bruno Luong - 31 Jul 2008 06:57 GMT
Is it a known bug? This bug is linked to a so fundamental
Matlab operation that makes me scare, I start to suspect all
my code using sparse matrix.
Bruno
K Foster - 31 Jul 2008 13:17 GMT
Thanks for the help Bruno, it's nice to know that it wasn't
my fault. I am running the R2006b version. I haven't
found a bug report for the problem listed, so I'm going to
write up one for the Mathworks people and see what they
have to say.
K Foster - 01 Aug 2008 00:22 GMT
Mathworks Reply:
"This was a bug in the implementation of SPARSE that was
introduced in MATLAB 7.3 (R2006b) that caused elements in a
large logical sparse array to be incorrectly assigned. This
bug did not exist in MATLAB 7.2 (R2006a) and was fixed in
MATLAB 7.4 (R2007a) and onward. [...]
The bug appears when creating logical sparse matrices.
However, the bug does not appear for sparse matrices
populated with 8-byte doubles. MATLAB does not support
sparse matrices populated with other data types (1-byte
uint8s or 4-byte singles). "
So I guess I'm stuck switching from logicals (which ideally
would only be 1 bit) to doubles (which are 8 bytes). I've
tried it and it works, it's just slightly annoying at how
much more RAM it is taking up...