1

I would like to change a sparse matrix dimensions dynamically. However, I'm concerned with efficiency. Does this operation copy all the content of the first matrix into a bigger one ? In that case, would it be a better idea to increase matrix dimension by 100 for example ? The java doc doesn't seem to be talking about efficiency in that case.

1 Answers1

0

It doesn't copy the values and should be very fast. It does fill column indexes with zeros because that's required as part of the sparse format.

@Override
public void reshape( int numRows , int numCols , int arrayLength ) {
    // OK so technically it is sorted, but forgetting to correctly set this flag is a common mistake so
    // decided to be conservative and mark it as unsorted so that stuff doesn't blow up
    this.indicesSorted = false;
    this.numRows = numRows;
    this.numCols = numCols;
    growMaxLength( arrayLength , false);
    this.nz_length = 0;

    if( numCols+1 > col_idx.length ) {
        col_idx = new int[ numCols+1 ];
    } else {
        Arrays.fill(col_idx,0,numCols+1,0);
    }
}
lessthanoptimal
  • 2,722
  • 2
  • 23
  • 25