gpt4 book ai didi

java - 在稀疏矩阵的情况下,EJML reshape 函数是否有效?

转载 作者:太空宇宙 更新时间:2023-11-04 09:29:00 25 4
gpt4 key购买 nike

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

最佳答案

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

@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);
}
}

关于java - 在稀疏矩阵的情况下,EJML reshape 函数是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57341245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com