【发布时间】:2019-02-06 00:55:47
【问题描述】:
这是一个小乘积函数,可以将常量列表、运算符列表和另一个常量列表转换为 Julia Expr。
该函数适用于较小的常量集,但是对于包含 100 个常量和 5 个运算符的列表,该函数会引发 StackOverflow。
function applyProduct(left, operators, right)
prod = Iterators.product(left, operators, right)
prod = Iterators.vcat(prod...)
return Iterators.map(x -> Expr(:call, Symbol(x[2]), Symbol(x[1]), Symbol(x[3])), prod)
end
我的函数在 vcat 函数中爆炸:
ERROR: LoadError: StackOverflowError:
Stacktrace:
[1] promote_eltypeof(::Tuple{String,typeof(+),Expr}, ::Tuple{String,typeof(+),Expr}, ::Vararg{Any,N} where N) at .\abstractarray.jl:1211 (repeats 8406 times)
[2] _cat(::Val{1}, ::Tuple{String,typeof(*),Expr}, ::Vararg{Any,N} where N) at .\abstractarray.jl:1382
[3] #cat#104(::Val{1}, ::Function, ::Tuple{String,typeof(*),Expr}, ::Vararg{Any,N} where N) at .\abstractarray.jl:1511
[4] (::getfield(Base, Symbol("#kw##cat")))(::NamedTuple{(:dims,),Tuple{Val{1}}}, ::typeof(cat), ::Tuple{String,typeof(*),Expr}, ::Vararg{Any,N} where N) at .\none:0
[5] vcat(::Tuple{String,typeof(*),Expr}, ::Tuple{String,typeof(*),Expr}, ::Tuple{String,typeof(*),Expr}, ::Vararg{Any,N} where N) at .\abstractarray.jl:1449
这是一个堆栈溢出错误,因此数据以某种方式存储在堆栈中。我应该声明一些东西以将其保存在内存中吗?
我想将此操作应用于大量常量。也许我没有使用最有效的方法。
【问题讨论】:
标签: out-of-memory julia stack-overflow