[ojAlgo-user] Populating matrices
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Nigel S. <nig...@gm...> - 2008-11-13 10:32:27
|
Hi, I wonder if someone could please comment on the proper way to populate blank matricies, with memory efficiency in mind. The example I have is loading a CSV file into the matrix. Previously I used JAMA: 1) Created the matrix (new Matrix(rowCount, colCount)) 2) Iterate over the rows: 2.1) Iterate over the columns 2.1.1) Write to the array (currentMatrix.set(row, j, Double.parseDouble(cols[remainingCols.get(j)]));) I adapted this to ojalgo, so now I use 1) PrimitiveMatrix.FACTORY.buildZero(rowCount, colCount) ... 2.1.1) currentMatrix = currentMatrix.set(row, j, Double.parseDouble(cols[colsOfInterest[j]])); This is very slow, in that the JAMA version takes 0.3 s to run, and the ojalgo version takes 30+ seconds to run. Essentially because the matrix set method seems to make a copy of the matrix, which it returns. This does seem at odds with the java doc which indicates that the physical stores are mutable, so I would assume the matrix should also be mutable. The other option appears to be to create a double array and copy it into the matrix with the factory, but this will mean, for a short time, there will be two copies of a potentially large array in memory. Any advice would be most helpful. Cheers Nigel |