{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/10337","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/10337/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/10337/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/10337/events","html_url":"https://github.com/JuliaLang/julia/pull/10337","id":59056519,"number":10337,"title":"improved ind2sub/sub2ind","user":{"login":"Jutho","id":4162102,"avatar_url":"https://avatars.githubusercontent.com/u/4162102?v=3","gravatar_id":"","url":"https://api.github.com/users/Jutho","html_url":"https://github.com/Jutho","followers_url":"https://api.github.com/users/Jutho/followers","following_url":"https://api.github.com/users/Jutho/following{/other_user}","gists_url":"https://api.github.com/users/Jutho/gists{/gist_id}","starred_url":"https://api.github.com/users/Jutho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jutho/subscriptions","organizations_url":"https://api.github.com/users/Jutho/orgs","repos_url":"https://api.github.com/users/Jutho/repos","events_url":"https://api.github.com/users/Jutho/events{/privacy}","received_events_url":"https://api.github.com/users/Jutho/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":44,"created_at":"2015-02-26T11:08:31Z","updated_at":"2015-03-14T15:39:12Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/10337","html_url":"https://github.com/JuliaLang/julia/pull/10337","diff_url":"https://github.com/JuliaLang/julia/pull/10337.diff","patch_url":"https://github.com/JuliaLang/julia/pull/10337.patch"},"body":"Use `stagedfunction` definition of `sub2ind` and `ind2sub` to generate specialized code for every `N` in `dims::NTuple{N,Integer}`. See #10331 for related discussion and performance check. I can do more performance benchmarking if somebody can point me to a good test suite that depends heavily on the use of those 2 functions."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/80537706","html_url":"https://github.com/JuliaLang/julia/pull/10337#issuecomment-80537706","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/10337","id":80537706,"user":{"login":"mbauman","id":154641,"avatar_url":"https://avatars.githubusercontent.com/u/154641?v=3","gravatar_id":"","url":"https://api.github.com/users/mbauman","html_url":"https://github.com/mbauman","followers_url":"https://api.github.com/users/mbauman/followers","following_url":"https://api.github.com/users/mbauman/following{/other_user}","gists_url":"https://api.github.com/users/mbauman/gists{/gist_id}","starred_url":"https://api.github.com/users/mbauman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbauman/subscriptions","organizations_url":"https://api.github.com/users/mbauman/orgs","repos_url":"https://api.github.com/users/mbauman/repos","events_url":"https://api.github.com/users/mbauman/events{/privacy}","received_events_url":"https://api.github.com/users/mbauman/received_events","type":"User","site_admin":false},"created_at":"2015-03-14T15:39:12Z","updated_at":"2015-03-14T15:39:12Z","body":"I really like the direction this is heading.  This version of `sub2ind` doesn't handle linear indexing in the last index, which is currently supported in base but untested.  The way you've set this up makes it really easy to fix:\r\n\r\n```diff\r\ndiff --git a/base/abstractarray.jl b/base/abstractarray.jl\r\nindex fecf83e..f832f3b 100644\r\n--- a/base/abstractarray.jl\r\n+++ b/base/abstractarray.jl\r\n@@ -1031,7 +1031,9 @@ function repmat(a::AbstractVector, m::Int)\r\n end\r\n\r\n sub2ind(dims::()) = 1\r\n+sub2ind(dims::(Integer,)) = 1\r\n sub2ind(dims::(Integer,), i1::Integer) = i1\r\n+sub2ind(dims::(Integer,Integer), i1::Integer) = i1\r\n sub2ind(dims::(Integer,Integer), i1::Integer, i2::Integer) = i1+dims[1]*(i2-1)\r\n sub2ind(dims::(Integer,Integer,Integer...), i1::Integer, i2::Integer, I::Integer...) =\r\n     i1 + dims[1]*(sub2ind(tail(dims),i2,I...)-1)\r\n```\r\n\r\n+1 to a rebase and merge."}}