JuliaArrays / JuliaArrays/OffsetArrays.jl
[RFC] when should Colon `:` keep offset information
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 212
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
In a normal 1-based indexing array world, this is clear: : serves as a length placeholder.
During #220 #228 and #245, I've realized that we haven't yet had a clear and consistent definition of the role of : in the OffsetArray world. Let's take reshape as an example, it might also apply to all other operations where : is allowed, e.g., getindex, setindex!.
I propose the rule of thumb is to keep offset information if it's unambiguous. It comes with one and only one extra rule: if all inds inputs are range type, keep offset information for the corresponding dimension where : is placed at.
A = OffsetArray(rand(4, 4, 4), -1, -2, -3)
reshape(A, :) # (0:64, )
reshape(A, 1:8, :) # (1:8, -1:6)
reshape(A, :, 1:8) # (0:7, 1:8)
reshape(A, 1:8, 1:8, :) # (1:8, 1:8, -2:-2)
reshape(A, 1:8, :, 1:8) # (1:8, -1:-1, 1:8)
reshape(A, :, 1:8, 1:8) # (0:0, 1:8, 1:8)
reshape(A, 1:8, 1:2, :) # (1:8, 1:2, -2:1)
reshape(A, 1:8, :, 1:2) # (1:8, -1:2, 1:2)
reshape(A, :, 1:8, 1:2) # (0:3, 1:8, 1:2)
All other cases should be consistent with the Base case. For example:
reshape(A, 8, :) # (1:8, 1:8)
In this case, it's ambiguous whether : is used as a length placeholder or axes placeholder so we should stick to the Base case; otherwise, I can foresee a lot of type piracy involved.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposed reshape examples and review the referenced issues #220, #228, and #245, then compare the suggested behavior with Julia's Base handling of reshape, getindex, and setindex!. No implementation files or tests are named; done would require an agreed rule for offset preservation before implementation and validation can be scoped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100