Tuesday, 15 May 2012

java - RealMatrix multiply without reassign -



java - RealMatrix multiply without reassign -

in java source must execute next lines often:

vecx = eigenmat.multiply(vecx); vecy = eigenmat.multiply(vecy);

eigenmat n x n matrix n~40 vecx/vecy n x 1 vector (intern realmatrix to)

i used "sampler" visualfm find hotspots in code ,

org.apache.commons.math3.linear.array2drowrealmatrix.<init>() org.apache.commons.math3.linear.array2drowrealmatrix.multiply()

have high runtime. i'm not java professional think every multiplication new vector created. can reassign old one?

maybe should switch jblas speed up?

matyro

edit: single core only

i think every multiplication new vector created

yes, is. source code of multiply():

public array2drowrealmatrix multiply(final array2drowrealmatrix m) { // safety check. matrixutils.checkmultiplicationcompatible(this, m); final int nrows = this.getrowdimension(); final int ncols = m.getcolumndimension(); final int nsum = this.getcolumndimension(); final double[][] outdata = new double[nrows][ncols]; // hold column of "m". final double[] mcol = new double[nsum]; final double[][] mdata = m.data; // multiply. (int col = 0; col < ncols; col++) { // re-create elements of column "col" of "m" // in contiguous memory. (int mrow = 0; mrow < nsum; mrow++) { mcol[mrow] = mdata[mrow][col]; } (int row = 0; row < nrows; row++) { final double[] datarow = data[row]; double sum = 0; (int = 0; < nsum; i++) { sum += datarow[i] * mcol[i]; } outdata[row][col] = sum; } } homecoming new array2drowrealmatrix(outdata, false); }

input vector m copied, stated in comment copy elements of column "col" of "m" in contiguous memory.

can reassign old one?

yes, can perform multiplication yourself, writing 2 loops. utilize getdata() reference underlying double[][] data.

java optimization blas apache-commons-math

No comments:

Post a Comment