[Fwd: improved Matrix.times()]
- Subject: [Fwd: improved Matrix.times()]
- From: Ron Boisvert <boisvert@nist.gov>
- Date: Wed, 21 May 2008 16:52:50 -0400
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=iso-8859-1; format=flowed
- User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
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