{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/16260","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/16260/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/16260/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/16260/events","html_url":"https://github.com/JuliaLang/julia/pull/16260","id":153653507,"number":16260,"title":"WIP: support for 0-indexed and arbitrary-indexed arrays","user":{"login":"timholy","id":1525481,"avatar_url":"https://avatars.githubusercontent.com/u/1525481?v=3","gravatar_id":"","url":"https://api.github.com/users/timholy","html_url":"https://github.com/timholy","followers_url":"https://api.github.com/users/timholy/followers","following_url":"https://api.github.com/users/timholy/following{/other_user}","gists_url":"https://api.github.com/users/timholy/gists{/gist_id}","starred_url":"https://api.github.com/users/timholy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timholy/subscriptions","organizations_url":"https://api.github.com/users/timholy/orgs","repos_url":"https://api.github.com/users/timholy/repos","events_url":"https://api.github.com/users/timholy/events{/privacy}","received_events_url":"https://api.github.com/users/timholy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/needs-docs","name":"needs-docs","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-05-08T12:34:56Z","updated_at":"2016-05-08T19:26:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/16260","html_url":"https://github.com/JuliaLang/julia/pull/16260","diff_url":"https://github.com/JuliaLang/julia/pull/16260.diff","patch_url":"https://github.com/JuliaLang/julia/pull/16260.patch"},"body":"This is the one part of [ArrayIteration.jl](https://github.com/timholy/ArrayIteration.jl) that I think it's reasonable to move to Base for the julia-0.5 release. The core change is the addition of the `inds` function, which should be thought of as a sister function to `size` but instead returns a tuple containing the in-bounds indexes of an array. The fallback is\r\n```jl\r\ninds(A::AbstractArray, d) = 1:size(A,d)\r\ninds{T,N}(A::AbstractArray{T,N}) = ntuple(d->inds(A, d), Val{N})\r\n```\r\nBut this allows one to override `inds` for specific types:\r\n```jl\r\nA = OffsetArray([1 3; 2 4], (-1,2))\r\n@test A[0,3] == 1\r\n@test A[1,3] == 2\r\n@test A[0,4] == 3\r\n@test A[1,4] == 4\r\njulia> A[1,1]\r\nERROR: BoundsError: attempt to access OAs.OffsetArray{Int64,2,Array{Int64,2}} with inds (0:1,3:4):\r\n #undef  #undef\r\n #undef  #undef\r\n  at index [1,1]\r\n in throw_boundserror(::OAs.OffsetArray{Int64,2,Array{Int64,2}}, ::Tuple{Int64,Int64}) at ./abstractarray.jl:134\r\n [inlined code] from ./abstractarray.jl:103\r\n in getindex(::OAs.OffsetArray{Int64,2,Array{Int64,2}}, ::Int64, ::Int64) at /home/tim/src/julia-0.5/test/abstractarray.jl:542\r\n in eval(::Module, ::Any) at ./boot.jl:230\r\n```\r\n\r\nThis adds the definition and uses it in `checkbounds`. The bigger job will be wiring it into the rest of Base. So I thought I'd post at this stage and see what folks think."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/217740992","html_url":"https://github.com/JuliaLang/julia/pull/16260#issuecomment-217740992","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/16260","id":217740992,"user":{"login":"eschnett","id":213514,"avatar_url":"https://avatars.githubusercontent.com/u/213514?v=3","gravatar_id":"","url":"https://api.github.com/users/eschnett","html_url":"https://github.com/eschnett","followers_url":"https://api.github.com/users/eschnett/followers","following_url":"https://api.github.com/users/eschnett/following{/other_user}","gists_url":"https://api.github.com/users/eschnett/gists{/gist_id}","starred_url":"https://api.github.com/users/eschnett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eschnett/subscriptions","organizations_url":"https://api.github.com/users/eschnett/orgs","repos_url":"https://api.github.com/users/eschnett/repos","events_url":"https://api.github.com/users/eschnett/events{/privacy}","received_events_url":"https://api.github.com/users/eschnett/received_events","type":"User","site_admin":false},"created_at":"2016-05-08T19:26:22Z","updated_at":"2016-05-08T19:26:22Z","body":"@timholy My main concern is about arrays with a lower bound different from 1. A secondary concern would be for arrays with a non-unit stride. (This should work find with an `inds` function; whether this support should go into Base is a different question.)\r\n\r\nIrregular sparse arrays are not relevant for me at the moment. However, block-sparse arrays are, where the upper bound on some dimension `j` depends on the value of an earlier dimension `i`. I'm just bringing this up to raise general awareness; there are many open questions regarding how these should be handled, or efficiently stored, or traversed, or how much of this needs to be exposed to the user anyway since efficient algorithms will depend on (or require) such a sparsity structure."}}