-2
public class SparseMatrix
{       
     static SparseObjectMatrix2D matrix = new SparseObjectMatrix2D(1000000, 1000000);

     public static void main(String[] args)
     {
            matrix.set(1, 2, 3.0);
     }      
}

Here is the error that I'm getting:

java.lang.ExceptionInInitializerError Caused by:
java.lang.IllegalArgumentException: matrix too large at
cern.colt.matrix.impl.AbstractMatrix2D.setUp(Unknown Source) at
cern.colt.matrix.impl.AbstractMatrix2D.setUp(Unknown Source) at
cern.colt.matrix.impl.SparseObjectMatrix2D.<init>(Unknown Source) at
cern.colt.matrix.impl.SparseObjectMatrix2D.<init>(Unknown Source) at
SparseMatrix.<clinit>(SparseMatrix.java:18) Exception in thread "main"
Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
  • 2
    Please post the error message you're getting. – Sizik Dec 10 '14 at 20:49
  • 2
    Please actually [ask a question](http://stackoverflow.com/help/how-to-ask) – Mike 'Pomax' Kamermans Dec 10 '14 at 20:50
  • java.lang.ExceptionInInitializerError Caused by: java.lang.IllegalArgumentException: matrix too large at cern.colt.matrix.impl.AbstractMatrix2D.setUp(Unknown Source) at cern.colt.matrix.impl.AbstractMatrix2D.setUp(Unknown Source) at cern.colt.matrix.impl.SparseObjectMatrix2D.(Unknown Source) at cern.colt.matrix.impl.SparseObjectMatrix2D.(Unknown Source) at SparseMatrix.(SparseMatrix.java:18) Exception in thread "main" Java Result: 1 – Adeetya Ravisankar Dec 10 '14 at 20:51
  • 8E12 bytes if it were full - are you getting an OutOfMemoryError? – duffymo Dec 10 '14 at 20:51
  • 2
    also don't post code in a reply comment, update your post with the details. – Mike 'Pomax' Kamermans Dec 10 '14 at 20:51
  • 1
    `matrix too large` - It's probably too large. After all, you're creating a 1 *trillion* cell matrix. – Compass Dec 10 '14 at 20:52
  • 2
    Maybe it's too large because it says it's too large. – Stefan Falk Dec 10 '14 at 20:53
  • Can I create a matrix more than 10000 X 10000? – Adeetya Ravisankar Dec 10 '14 at 20:54
  • Computer says no. Do you really need such a matrix? Maybe create several smaller matrices and then combine them. – runDOSrun Dec 10 '14 at 20:55
  • If I am not mistaken that would be around `47 GB` of RAM if that were *just* `10000x10000` 32 bit values (with no overhead of any object or container etc) – Stefan Falk Dec 10 '14 at 20:56
  • Well yeah, that is why I am trying to use sparse matrix and I am ending up with errors. I gotta store adjacency matrix for a million nodes. – Adeetya Ravisankar Dec 10 '14 at 20:58
  • Then store 100 matrices for 10000 nodes each. Or consider using a database with so much data. – runDOSrun Dec 10 '14 at 21:02
  • I just read your recent questions to figure out what you're trying to do. Please use HashMap<> for adjacency lists as suggested below. The matrix approach will get you nowhere. – runDOSrun Dec 10 '14 at 21:09

1 Answers1

2

You cannot. From the documentation:

Throws:
IllegalArgumentException - if rows<0 || columns<0 || > (double)columns*rows > Integer.MAX_VALUE.

Instead of creating a matrix addressed with x and y coordinates, returning a Value, create a HashMap<Coordinates, Value>, where Coordinates is a simple class holding x and y.

Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110