Savage Reader
Savage Reader

Reputation: 427

Exporting very large matrices using JMatio in Java

I need to export very large 3d matrices to Matlab from Java. I have written a class for creating a 3d matrix which works very well for small matrices but breaks down for large ones. The codes is as follows:

public class MLDouble3d extends MLDouble {
    private final int i;
    private final int j;
    public MLDouble3d(String name, int[] dims) {
        super(name, dims);
        i=dims[0];
        j=dims[1];
    }

    public void set(double value, int ii, int jj, int kk){
        set(value, ii + jj * i + kk * i * j);
    }
}

I get the following error when I run with a large matrix:

Exception in thread "main" java.lang.IllegalArgumentException
    at java.nio.Buffer.position(Buffer.java:236)
    at com.jmatio.types.MLNumericArray._set(MLNumericArray.java:269)
    at com.jmatio.types.MLNumericArray.setReal(MLNumericArray.java:111)
    at com.jmatio.types.MLNumericArray.set(MLNumericArray.java:215)

I've tried using MLSparse, however it cannot be used to create 3d matrices in this way.

I run the virtual machine with the following options:

-Xms24000M -Xmx24000M -Xmn16000M -XX:TLABSize=1m -XX:-ResizeTLAB 

I am able to fit the data in a double[][][] array.

Upvotes: 1

Views: 569

Answers (1)

Daniel
Daniel

Reputation: 36710

It seems that dims[0]*dims[1]*dims[2] is to large for integers, it can't be larger than 2,147,483,647. Otherwise an integer can't store the index.

Upvotes: 1

Related Questions