Как я могу создать разреженную матрицу 1000000 x 1000000 с помощью Java Colt?

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

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

Вот ошибка, которую я получаю:

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"

1 ответ

Решение

Ты не можешь. Из документации:

Броски:
IllegalArgumentException - если rows<0 || columns<0 || > (double)columns*rows > Integer.MAX_VALUE,

Вместо создания матрицы с координатами x и y, возвращая Value, создать HashMap<Coordinates, Value>, где Coordinates простой класс, содержащий х и у.

Другие вопросы по тегам