[Fwd: Re: improved Matrix.times()]
- Subject: [Fwd: Re: improved Matrix.times()]
- From: Ron Boisvert <boisvert@nist.gov>
- Date: Fri, 23 May 2008 10:51:28 -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: Anders Peterson <anders_peterson@optimatika.se>
Subject: Re: improved Matrix.times()
I don't think all your suggested changes are good. The only really
unfortunate things I see in the jama code is the 'Arowi' and 's'
declarations inside the loops. It would be much better to declare those
temporary variables once before the looping begins and then simply
assign 'Arowi = A[i];' and 's = 0;' inside the loops.
Not sure having a local copy (or not) of the left matrix' row makes much
difference, but I'm sure the local copy of the right matrix' column and
the 's' makes a speed difference.
/Anders
-----------------------------
http://ojalgo.org/
Marcell Missura wrote:
> 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