[Fwd: improved Matrix.times()]


Sender: "Marcell Missura" <missura@cs.uni-bonn.de>
Subject: improved Matrix.times()


After trying to multiply two huge matrices and running out of heap memory
I suggest to juice up the times(Matrix) method of the Matrix class with
the following few lines to avoid creating a massive amount of garbage on
the heap that needs to be collected.

public Matrix times(Matrix B)
{
        if (B.m != n)
                throw new IllegalArgumentException("Matrix inner
dimensions must agree.");

        Matrix C = new Matrix(m, B.n);

        for (int i = 0; i < m; i++)
                for (int j = 0; j < B.n; j++)
                        for (int k = 0; k < n; k++)
                                C.A[i][j] += A[i][k] * B.A[k][j];

        return C;
}







Date Index | Thread Index | Problems or questions? Contact list-master@nist.gov