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

keys/LinearIndices for non-Int indices #32566

Open
sostock opened this issue Jul 12, 2019 · 1 comment
Open

keys/LinearIndices for non-Int indices #32566

sostock opened this issue Jul 12, 2019 · 1 comment
Labels
arrays [a, r, r, a, y, s]

Comments

@sostock
Copy link
Contributor

sostock commented Jul 12, 2019

Due to LinearIndices only supporting Ints, keys and LinearIndices do not work when the indices are not representable as Ints:

julia> keys(1:typemax(Int128))
ERROR: InexactError: trunc(Int64, 170141183460469231731687303715884105727)
[...]

julia> LinearIndices(1:typemax(Int128))
ERROR: InexactError: trunc(Int64, 170141183460469231731687303715884105727)
[...]

Related: #27090

@mbauman
Copy link
Sponsor Member

mbauman commented Jul 16, 2019

Yeah, this is a bit of a wart. I have an old branch where I started parameterizing all these indices structures, but I recall hitting a number of roadblocks making this trickier than it first appears.

In some senses, I'm ok with LinearIndices being restricted to only being integer values — you're explicitly requesting a "memory offset"-like representation of the array, so an inability to represent values larger than Int is reasonable. The trouble is that keys should definitely always work, and right now there's a nice symmetry that it always returns either a Linear- or CartesianIndices.

The easy fix is to just patch up keys(::AbstractRange) to deal with these cases, but it'd be nice to find a generic behavior that's a bit more friendly to non-Int indices.

@mbauman mbauman added the arrays [a, r, r, a, y, s] label Jul 16, 2019
@sostock sostock changed the title keys/LinearIndices for for non-Int indices keys/LinearIndices for non-Int indices Dec 4, 2020
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]
Projects
None yet
Development

No branches or pull requests

2 participants