Hi!
I experienced Integer overflow on Windows due to the fact that Int32 is the default one there:
length(CartesianIndices((1000000, 1000000)))
Succeeds on linux64 but fails on Windows (something like A[-72232] is out of bounds).
I copied randsubseq!
implementation, where the overflow happens, and adjusted it so index vars are Int64 now:
randsubseq(r::AbstractRNG, A::AbstractArray{T}, p::Real) where {T} =
randsubseq!(r, T[], A, p)
# Fill S (resized as needed) with a random subsequence of A, where
# each element of A is included in S with independent probability p.
function randsubseq!(r::AbstractRNG, S::AbstractArray, A::AbstractArray, p::Real)
Base.require_one_based_indexing(S, A)
0 <= p <= 1 || throw(ArgumentError("probability $p not in [0,1]"))
n = prod(size(A), init=Int64(1)) # length - there the overflow happened originally
p == 1 && return copyto!(resize!(S, n), A)
empty!(S)
p == 0 && return S
nexpected = p * n
sizehint!(S, round(Int64, nexpected + 5*sqrt(nexpected)))
if p > 0.15
for i = 1:n
rand(r) <= p && push!(S, A[i])
end
else
L = -1 / log1p(-p)
i = Int64(0)
while true
s = randexp(r) * L
s >= n - i && return S
push!(S, A[i += ceil(Int64, s)])
end
end
return S
end
Surprisingly I get:
BoundsError: attempt to access 1000000×1000000 CartesianIndices{2, Tuple{Base.OneTo{Int32}, Base.OneTo{Int32}}} at index [10504]
on Windows, which doesn’t really make sense. How come I can’t access something that is in bounds?