Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't cast indices to Int in isassigned call while displaying arrays #56863

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Dec 18, 2024

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> isassigned(ones(2), big(2))
true

We may therefore pass the indices to the call directly without converting them to Ints. 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> 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

@jishnub jishnub added arrays [a, r, r, a, y, s] display and printing Aesthetics and correctness of printed representations of objects. labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant