Skip to content

Matrix reshape question #40

@GoogleCodeExporter

Description

@GoogleCodeExporter
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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions