gpt4 book ai didi

octave - "dimension too large"广播到 Octave 稀疏矩阵时出错

转载 作者:行者123 更新时间:2023-12-02 01:28:39 27 4
gpt4 key购买 nike

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

然而,当我尝试使用广播函数执行逐元素乘法时,我得到了错误:内存不足或维度对于 Octave 的索引类型而言太大

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

重现问题的最少代码:

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

最佳答案

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

关于octave - "dimension too large"广播到 Octave 稀疏矩阵时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35421967/

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