Closed
Description
julia> b = typemax(Int) - 1
9223372036854775806
julia> Array{Int}(undef, b, b, 0)
ERROR: ArgumentError: invalid Array dimensions
Stacktrace:
[1] checked_dims
@ ./boot.jl:585 [inlined]
[2] Array
@ ./boot.jl:598 [inlined]
[3] (Array{Int64})(::UndefInitializer, m::Int64, n::Int64, o::Int64)
@ Core ./boot.jl:611
[4] top-level scope
@ REPL[2]:1
julia> Array{Int}(undef, 0, b, b)
0×9223372036854775806×9223372036854775806 Array{Int64, 3}
julia> versioninfo()
Julia Version 1.12.0-DEV.387
Commit b5bfd83a3d0 (2024-04-22 13:12 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Two alternative solutions:
-
When there's a zero among the dimension sizes, only check that the nonzero sizes are nonnegative and less than
typemax(Int)
. Don't check for overflow during multiplication. This would make both examples above return. -
Remove the zero sizes before checking for overflow. This would make both examples above throw.