Skip to content

reshape of BigInt ranges leads to errors due to implicit conversion of dims to Int #40076

Open
@jishnub

Description

@jishnub
julia> reshape(big(1):big(2)^62, 2, :) # works as expected
2×2305843009213693952 reshape(::UnitRange{BigInt}, 2, 2305843009213693952) with eltype BigInt:
 1  3  5  7   9  11  13  15  17  19  21  23  25  27  29  31  33  35  37  39  41  43  45    4611686018427387899  4611686018427387901  4611686018427387903
 2  4  6  8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40  42  44  46     4611686018427387900  4611686018427387902  4611686018427387904

julia> reshape(big(1):big(2)^63, 2, :) # strange error message because of Int overflow
ERROR: DimensionMismatch("parent has 9223372036854775808 elements, which is incompatible with size (2, 4611686018427387904)")
Stacktrace:
 [1] _throw_dmrs(n::BigInt, str::String, dims::Tuple{Int64, Int64})
   @ Base ./reshapedarray.jl:181
 [2] _reshape(parent::UnitRange{BigInt}, dims::Tuple{Int64, Int64})
   @ Base ./reshapedarray.jl:176
 [3] reshape
   @ ./reshapedarray.jl:112 [inlined]
 [4] reshape(parent::UnitRange{BigInt}, dims::Tuple{Int64, Colon})
   @ Base ./reshapedarray.jl:118
 [5] reshape(::UnitRange{BigInt}, ::Int64, ::Colon)
   @ Base ./reshapedarray.jl:117
 [6] top-level scope
   @ REPL[10]:1

julia> reshape(big(1):big(2)^64, 2, :) # clearer error message, but perhaps this should work? 
ERROR: InexactError: Int64(9223372036854775808)
Stacktrace:
 [1] Type
   @ ./gmp.jl:364 [inlined]
 [2] _reshape_uncolon
   @ ./reshapedarray.jl:129 [inlined]
 [3] reshape(parent::UnitRange{BigInt}, dims::Tuple{Int64, Colon})
   @ Base ./reshapedarray.jl:118
 [4] reshape(::UnitRange{BigInt}, ::Int64, ::Colon)
   @ Base ./reshapedarray.jl:117
 [5] top-level scope
   @ REPL[11]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bignumsBigInt and BigFloatbugIndicates an unexpected problem or unintended behaviorrangesEverything AbstractRange

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions