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

lastindex and firstindex return type #27090

Open
nalimilan opened this issue May 13, 2018 · 1 comment
Open

lastindex and firstindex return type #27090

nalimilan opened this issue May 13, 2018 · 1 comment
Labels
domain:arrays [a, r, r, a, y, s] system:32-bit Affects only 32-bit systems

Comments

@nalimilan
Copy link
Member

As noted at #26775, we currently allow custom lastindex and firstindex implementations to return non-Int values. For example, Date ranges use an Int64 index, and their last index (and length) cannot always be represented using an Int on 32-bit.

In PR #26775, this required defining lastindex and firstindex in terms of eachindex(IndexLinear(), x) rather than of LinearIndices(x). While it's not really an issue in practice, the fact that LinearIndices is not always able to represent the indices of ranges could be considered as a problem.

Is this really the desired behavior, or should we require that indices be Int?

@mbauman
Copy link
Sponsor Member

mbauman commented May 14, 2018

This is a little unfortunate, but non-Int indices have always been a bit of a poorly-supported case. We should be able to slowly improve things, but it's not currently possible to reshape large Date ranges on an Int32 machine. Or, equivalently:

julia> 1:(typemax(Int128)÷2+1)
1:85070591730234615865843651857942052864

julia> length(1:(typemax(Int128)÷2+1))
85070591730234615865843651857942052864

julia> reshape(1:(typemax(Int128)÷2+1), :, 2)
ERROR: MethodError: no method matching _reshape(::UnitRange{Int128}, ::Tuple{Int128,Int64})

We could allow LinearIndices (and CartesianIndices) to be parameterized by the resulting index type, but even then they'll have difficulty doing the ind2sub work they're meant to do because the abstract infrastructure does the index computations in terms of Int. I suppose we could similarly re-implement those methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s] system:32-bit Affects only 32-bit systems
Projects
None yet
Development

No branches or pull requests

3 participants