julia
c93e28e8 - Don't cast indices to `Int` in `isassigned` call while displaying arrays (#56863)

Commit
311 days ago
Don't cast indices to `Int` in `isassigned` call while displaying arrays (#56863) The comment on the line says that `isassgined` requires `Int` indices, but this isn't correct: it accepts arbitrary `Integer` indices. The corresponding methods are defined in `multidimensional.jl`. E.g.: ```julia julia> isassigned(ones(2), big(2)) true ``` We may therefore pass the indices to the call directly without converting them to `Int`s. This helps for huge arrays, where the indices may lie outside the bounds of `Int`, but are otherwise valid. As an example, the following would work correctly after this, whereas displaying the array errors currently: ```julia julia> struct MyBigFill{T,N} <: AbstractArray{T,N} val :: T axes :: NTuple{N,Base.OneTo{BigInt}} end julia> MyBigFill(val, sz::Tuple{}) = MyBigFill{typeof(val),0}(val, sz) MyBigFill julia> MyBigFill(val, sz::NTuple{N,BigInt}) where {N} = MyBigFill(val, map(Base.OneTo, sz)) MyBigFill julia> MyBigFill(val, sz::Tuple{Vararg{Integer}}) = MyBigFill(val, map(BigInt, sz)) MyBigFill julia> Base.size(M::MyBigFill) = map(length, M.axes) julia> Base.axes(M::MyBigFill) = M.axes julia> function Base.getindex(M::MyBigFill{<:Any,N}, ind::Vararg{Integer,N}) where {N} checkbounds(M, ind...) M.val end julia> function Base.isassigned(M::MyBigFill{<:Any,N}, ind::Vararg{BigInt,N}) where {N} checkbounds(M, ind...) true end julia> M = MyBigFill(4, (big(2)^65, 3)) 36893488147419103232×3 MyBigFill{Int64, 2}: 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ⋮ 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ``` --------- Co-authored-by: Oscar Smith <oscardssmith@gmail.com>
Author
Parents
Loading