Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



sparse matrix bug
Posted:
Jun 18, 1996 11:50 AM


An interesting little bug I tripped over in Matlab on the Sun today. It is also in the mac version.
Matlab is supposed to work with sparse matrices and full matrices together, leaving the result as a sparse matrix.
For example, when A is sparse and B is full,
C=A+B;
C is supposed to be sparse. This is good.
C=A*B;
C is still supposed to be sparse. Still good.
Consider the following expression though.
C = A(:,ind)  B*(R1\R2);
A and B are sparse. ind is an index vector (full). R1 and R2 are full. C should be sparse, since it is a sum of terms, all of which should be sparse.
NOT so. At least not on a Mac running 4.2c1 or on a sparc5.
I can fix it, by forcing R1 and R2 to be sparse, but this cost me some headaches. When I later tried to use C, which is huge when full, it crashed the sparc20 I was running it on remotely with memory problems. It did not return cleanly. I tried it again on my own sparc5, and it quickly crashed that system too. No out of memory message. Just reboot.
If you do not believe me, try out the following code. Check out b after it is computed. Full. Not sparse.
John D'Errico, derrico@kodak.com
 a = sprandn(100,50,0.1); c = sprandn(10,50,0.05); c=full(c);
crank=rank(c);
[q,r,e]=qr(c,0);
j_subs=e(1:crank); j_est=e((crank+1):50);
a1=a(:,j_subs);
r1=r(1:crank,1:crank); r2=r(1:crank,(crank+1):50);
b=a(:,j_est)a1*(r1\r2);
whos 



