【问题标题】:"dimension too large" error when broadcasting to sparse matrix in octave以八度音阶广播到稀疏矩阵时出现“维度太大”错误
【发布时间】:2016-02-18 04:04:57
【问题描述】:

32 位 Octave 对数组中的最大元素数有限制。我已经从源代码重新编译(按照 https://github.com/calaba/octave-3.8.2-enable-64-ubuntu-14.04 处的脚本),现在有了 64 位索引。

尽管如此,当我尝试使用广播函数执行元素乘法时,我得到error: out of memory or dimension too large for Octave's index type

这是一个错误,还是一个未记录的功能?如果是错误,是否有人有合理有效的解决方法?

重现问题的最少代码:

function indexerror();
% both of these are formed without error
%    a = zeros (2^32, 1, 'int8');
%    b = zeros (1024*1024*1024*3, 1, 'int8');

%   sizemax    % returns 9223372036854775806

    nnz = 1000            % number of non-zero elements
    rowmax = 250000
    colmax = 100000

    irow = zeros(1,nnz);
    icol = zeros(1,nnz);
    for ind =1:nnz
        irow(ind) = round(rowmax/nnz*ind);
        icol(ind) = round(colmax/nnz*ind);
    end

    sparseMat = sparse(irow,icol,1,rowmax,colmax);

    % column vector to be broadcast
    broad = 1:rowmax;
    broad = broad(:);

    % this gives "dimension too large" error
    toobig = bsxfun(@times,sparseMat,broad);

    % so does this
    toobig2 = sparse(repmat(broad,1,size(sparseMat,2)));
    mult = sparse( sparseMat .* toobig2 );        % never made it this far
end

编辑: 好吧,我有一个低效的解决方法。它比使用 bsxfun 慢 3 倍左右(取决于细节),但它比必须对库中的错误进行排序要好。希望有一天有人会发现这很有用。

% loop over rows, instead of using bsxfun
mult_loop = sparse([],[],[],rowmax,colmax);
for ind =1:length(broad);
    mult_loop(ind,:) = broad(ind) * sparseMat(ind,:);
end

【问题讨论】:

  • 您是否尝试过使用新的octave broadcasting mechanismtoobig = sparseMat .* rep;
  • 刚试了一下,还是报错:product: nonconformant arguments (op1 is 250000x100000, op2 is 250000x1)
  • 它应该可以工作。这似乎与bug 35787 有关

标签: octave


【解决方案1】:

不幸的是,是的,这是一个错误。显然 @bsxfunrepmat 正在返回完整矩阵而不是稀疏矩阵。错误已在此处提交: http://savannah.gnu.org/bugs/index.php?47175

【讨论】:

    猜你喜欢
    • 2021-09-21
    • 2014-05-14
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多