Skip to content

whether Core.checked_dims decides to throw depends on dimension order (for empty arrays) #54244

Closed
@nsajko

Description

@nsajko
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:

  1. 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.

  2. Remove the zero sizes before checking for overflow. This would make both examples above throw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]bugIndicates an unexpected problem or unintended behaviorregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions