1

我想动态更改稀疏矩阵尺寸。但是,我关心的是效率。此操作是否将第一个矩阵的所有内容复制到更大的矩阵中?在这种情况下,例如将矩阵维度增加 100 会更好吗?在这种情况下,java doc 似乎并没有谈论效率。

4

1 回答 1

0

它不会复制值并且应该非常快。它确实用零填充列索引,因为这是稀疏格式的一部分。

@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);
    }
}
于 2020-01-16T01:56:08.900 回答