如何在 Julia 中对一个大向量求和
How to sum over a big vector in Julia
我正在尝试对一个非常“大”的向量求和,我知道 big()
函数可用于计算大数,
我什至在下面使用过(和有用)。
但是,如果我尝试总计使用它,它就不起作用。
我尝试了 big(sum(test, dims=1))
和 sum(big(test), dims=1))
但我收到以下错误:
InexactError: Int64(-3331427209747016990720)
test = Tuple{Int, Int}[]
N = 80
Iterations = 60
for i in 1:10000
push!(test, (big(largeNumber1(N, Iterations)) * big(largeNumber2(N, Iterations)), 0))
end
# this just transforms test into a vector
test = hcat(first.(test), last.(test)) * [1, 0]
sum(test, dims=1) # here is where the code "breaks"
<output> 1-element Vector{Int64}:
-5233167026984513820
很可能我用的 big()
错了
您没有显示 largeNumber1() 的代码,但您似乎在求和之前将大整数放入 Int64 元组向量中。尝试
test = Tuple{BigInt, BigInt}[]
我正在尝试对一个非常“大”的向量求和,我知道 big()
函数可用于计算大数,
我什至在下面使用过(和有用)。
但是,如果我尝试总计使用它,它就不起作用。
我尝试了 big(sum(test, dims=1))
和 sum(big(test), dims=1))
但我收到以下错误:
InexactError: Int64(-3331427209747016990720)
test = Tuple{Int, Int}[]
N = 80
Iterations = 60
for i in 1:10000
push!(test, (big(largeNumber1(N, Iterations)) * big(largeNumber2(N, Iterations)), 0))
end
# this just transforms test into a vector
test = hcat(first.(test), last.(test)) * [1, 0]
sum(test, dims=1) # here is where the code "breaks"
<output> 1-element Vector{Int64}:
-5233167026984513820
很可能我用的 big()
错了
您没有显示 largeNumber1() 的代码,但您似乎在求和之前将大整数放入 Int64 元组向量中。尝试
test = Tuple{BigInt, BigInt}[]