1

I am using Colt for its Sparse Matrix implementation, but as soon as I apply algebra on these, they become Dense Matrix. Namely, if I multiply two sparse matrices A and B and want to assign the result to a third matrix C, I cannot declare C as a sparse matrix. I have a lot of memory issues because I manipulate large matrices (1GB in RAM if I make it dense). I tried the following:

Algebra al = new Algebra();
SparseDoubleMatrix2D a = generateSparseMatrix(); // whatever is here
SparseDoubleMatrix2D aCarre = (SparseDoubleMatrix2D) al.mult(a, al.transpose(a));

But I obtain a java.lang.ClassCastException (can't cast from Dense to Sparse).

Thanks by advance,

Maveric78f

Maveric78f
  • 55
  • 6
  • Let's say I want to compute M = M1.M2. If the matrices are n*n, each slot of the product matrix is the sum of n double products, which is non null if and only if both of the terms are non null. As a consequence, if p, p1 and p2 are respectively the probability of encountering a non null slot at random in M, M1 and M2, p = 1-(1-p1p2)^n. If p1=p2=0.3% and n=10000, p=8.7%. I guess that's not very sparse indeed. But still, I still have the same issues with scalar product, addition, transposition, ... – Maveric78f Dec 11 '13 at 10:36
  • Sparse matrices use a key-value pair as the underlying data structure, while dense matrices use arrays as underlying data structure. That is why you can't cast from one to the other. The only proper way to this is `SparseDoubleMatrix2D matrix = new SparseDoublematrix2D(denseMatrix.toArray())`. If you are already having memory issues, this will probably not be helpful for you. – Chthonic Project Jan 22 '14 at 10:50

0 Answers0