我想动态改变稀疏矩阵的维数。然而,我关心的是效率。此操作是否将第一个矩阵的所有内容复制到一个更大的矩阵中?在这种情况下,例如将矩阵维数增加100是不是更好?在这种情况下,java文档似乎并没有提到效率。
发布于 2020-01-16 09:56:09
它不会复制值,速度应该非常快。它确实用零填充列索引,因为这是稀疏格式所必需的。
@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);
}
}https://stackoverflow.com/questions/57341245
复制相似问题