adamaulia / efficient-java-matrix-library

Automatically exported from code.google.com/p/efficient-java-matrix-library
0 stars 0 forks source link

Matrix reshape question #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi all,

I have a question on the reshape method of org.ejml.data.DenseMatrix64F.java. 
If we want to keep the matrix data and just reshape it to, for example, make it 
bigger, the data doesn't stay in the same "logical" positions that it had 
before, as a consequence the logical matrix is altered, and I cannot see how 
the original data could be still used in a meaningful way. This option would be 
typically needed e.g. in dimensionality reduction algorithms, etc.

Would it make sense to consider an implementation that leaves each value in the 
same logical (i,j) position it had initially? E.g. something like:

@Override
public void reshape(int numRows, int numCols, boolean saveValues) {
    double[] d = new double[numRows * numCols];

    if (saveValues) {
        for (int i = 0, j = 0; i < numRows * numCols && j < getNumElements();) {
            if (j % this.numCols < numCols) {
                d[i++] = data[j++];
            } else {
                j += this.numCols - numCols;
            }
        }
    }

    this.data = d;

    this.numRows = numRows;
    this.numCols = numCols;
}

Any help is appreciated!

Cheers!

Original issue reported on code.google.com by sofiamar...@gmail.com on 3 Dec 2013 at 12:41

GoogleCodeExporter commented 9 years ago
Sorry for the slow reply.  There are situations where the reshape will not 
change the logical position of the data.  Like if you increase the number of 
rows.  It will get garbled if you increase the number of columns.

I'll consider modifying the functionality so that the logical position of each 
element stays the same.

Original comment by peter.ab...@gmail.com on 17 Nov 2014 at 10:48