【问题标题】:Is EJML reshape function efficient in case of sparse matrices?在稀疏矩阵的情况下,EJML 重塑函数是否有效?
【发布时间】:2019-12-11 22:52:37
【问题描述】:

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

【问题讨论】:

    标签: java matrix reshape ejml


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-25
      • 2018-06-18
      • 2016-08-31
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多