{"action":"created","comment":{"url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/comments/40508539","id":40508539,"diff_hunk":"@@ -5,67 +5,59 @@\n \n # This code is unused for now. See issue #192\n \n-immutable JuMPArray{T,N,R<:OrdinalRange} <: JuMPContainer\n+immutable JuMPArray{T,N} <: JuMPContainer\n     innerArray::Array{T,N}\n-    name::Symbol\n-    indexsets::NTuple{N,R}\n+    indexsets::NTuple{N}\n+    lookup::NTuple{N,Dict}\n+    meta::Dict{Symbol,Any}\n end\n \n-function Base.getindex{T}(d::JuMPArray{T,1,UnitRange{Int}},index::Real)\n-    @inbounds return d.innerArray[index - start(d.indexsets[1])+1]\n+function JuMPArray{T,N}(innerArray::Array{T,N}, indexsets::NTuple{N})\n+    JuMPArray(innerArray, indexsets, ntuple(N) do i\n+        idxset = indexsets[i]\n+        ret = Dict{eltype(idxset), Int}()\n+        if !(eltype(idxset) == Int && (typeof(idxset) == UnitRange || typeof(idxset) == StepRange))\n+            cnt = 1\n+            for x in idxset\n+                ret[x] = cnt\n+                cnt += 1\n+            end\n+        end\n+        ret\n+    end, Dict{Symbol,Any}())\n end\n \n-function Base.getindex{T}(d::JuMPArray{T,2,UnitRange{Int}},ix1::Real,ix2::Real)\n-    @inbounds return d.innerArray[ix1 - start(d.indexsets[1])+1, ix2 - start(d.indexsets[2])+1]\n+function _rev_lookup(lookup, rng::UnitRange{Int}, I)\n+    first(rng) <= I <= last(rng) || throw(BoundsError())\n+    I - (start(rng) - 1)\n+end\n+function _rev_lookup(lookup, rng::StepRange{Int}, I)\n+    first(rng) <= I <= last(rng) || throw(BoundsError())\n+    d, r = divrem(I - start(rng), step(rng))\n+    r == 0 || throw(BoundsError())\n+    d + 1\n end\n \n+_rev_lookup(lookup, v, I) = lookup[I]::Int\n \n-function Base.getindex{T,N}(d::JuMPArray{T,N,UnitRange{Int}},indices::Real...)\n-    length(indices) == N || error(\"Wrong number of indices for \",d.name,\", expected \",length(d.indexsets))\n-    idx = Array(Int, N)\n-    for i in 1:N\n-        idx[i] = Base.to_index(indices[i]) - start(d.indexsets[i]) + 1\n-    end\n-    return d.innerArray[idx...]\n-end\n+Base.getindex{T}(d::JuMPArray{T,1}, I) =\n+    d.innerArray[_rev_lookup(d.lookup[1], d.indexsets[1], I[1])]","path":"src/JuMPArray.jl","position":55,"original_position":55,"commit_id":"730a321d9b8e3b085bbd44ab1b9afdfd6c845109","original_commit_id":"730a321d9b8e3b085bbd44ab1b9afdfd6c845109","user":{"login":"mlubin","id":1733683,"avatar_url":"https://avatars.githubusercontent.com/u/1733683?v=3","gravatar_id":"","url":"https://api.github.com/users/mlubin","html_url":"https://github.com/mlubin","followers_url":"https://api.github.com/users/mlubin/followers","following_url":"https://api.github.com/users/mlubin/following{/other_user}","gists_url":"https://api.github.com/users/mlubin/gists{/gist_id}","starred_url":"https://api.github.com/users/mlubin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlubin/subscriptions","organizations_url":"https://api.github.com/users/mlubin/orgs","repos_url":"https://api.github.com/users/mlubin/repos","events_url":"https://api.github.com/users/mlubin/events{/privacy}","received_events_url":"https://api.github.com/users/mlubin/received_events","type":"User","site_admin":false},"body":"Right now we're generating a type inside of a macro. We might lose some generality by moving away from that. The old JuMPArray code above has ``NTuple`` with a uniform element type.","created_at":"2015-09-27T19:37:29Z","updated_at":"2015-09-27T19:37:29Z","html_url":"https://github.com/JuliaOpt/JuMP.jl/pull/590#discussion_r40508539","pull_request_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/590","_links":{"self":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/comments/40508539"},"html":{"href":"https://github.com/JuliaOpt/JuMP.jl/pull/590#discussion_r40508539"},"pull_request":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/590"}}},"pull_request":{"url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/590","id":46106276,"html_url":"https://github.com/JuliaOpt/JuMP.jl/pull/590","diff_url":"https://github.com/JuliaOpt/JuMP.jl/pull/590.diff","patch_url":"https://github.com/JuliaOpt/JuMP.jl/pull/590.patch","issue_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/590","number":590,"state":"open","locked":false,"title":"Reimplement dormant JuMPArray to work with any cartesian product index sets","user":{"login":"joehuchette","id":1373010,"avatar_url":"https://avatars.githubusercontent.com/u/1373010?v=3","gravatar_id":"","url":"https://api.github.com/users/joehuchette","html_url":"https://github.com/joehuchette","followers_url":"https://api.github.com/users/joehuchette/followers","following_url":"https://api.github.com/users/joehuchette/following{/other_user}","gists_url":"https://api.github.com/users/joehuchette/gists{/gist_id}","starred_url":"https://api.github.com/users/joehuchette/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joehuchette/subscriptions","organizations_url":"https://api.github.com/users/joehuchette/orgs","repos_url":"https://api.github.com/users/joehuchette/repos","events_url":"https://api.github.com/users/joehuchette/events{/privacy}","received_events_url":"https://api.github.com/users/joehuchette/received_events","type":"User","site_admin":false},"body":"WIP, just opening to solicit comments on the approach.","created_at":"2015-09-27T18:50:28Z","updated_at":"2015-09-27T19:37:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d62d095567633f295fcbc5c2af06a5f1939c019b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/590/commits","review_comments_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/590/comments","review_comment_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/590/comments","statuses_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/statuses/730a321d9b8e3b085bbd44ab1b9afdfd6c845109","head":{"label":"JuliaOpt:JuMPArray-part-deux","ref":"JuMPArray-part-deux","sha":"730a321d9b8e3b085bbd44ab1b9afdfd6c845109","user":{"login":"JuliaOpt","id":5667382,"avatar_url":"https://avatars.githubusercontent.com/u/5667382?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaOpt","html_url":"https://github.com/JuliaOpt","followers_url":"https://api.github.com/users/JuliaOpt/followers","following_url":"https://api.github.com/users/JuliaOpt/following{/other_user}","gists_url":"https://api.github.com/users/JuliaOpt/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaOpt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaOpt/subscriptions","organizations_url":"https://api.github.com/users/JuliaOpt/orgs","repos_url":"https://api.github.com/users/JuliaOpt/repos","events_url":"https://api.github.com/users/JuliaOpt/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaOpt/received_events","type":"Organization","site_admin":false},"repo":{"id":6150069,"name":"JuMP.jl","full_name":"JuliaOpt/JuMP.jl","owner":{"login":"JuliaOpt","id":5667382,"avatar_url":"https://avatars.githubusercontent.com/u/5667382?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaOpt","html_url":"https://github.com/JuliaOpt","followers_url":"https://api.github.com/users/JuliaOpt/followers","following_url":"https://api.github.com/users/JuliaOpt/following{/other_user}","gists_url":"https://api.github.com/users/JuliaOpt/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaOpt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaOpt/subscriptions","organizations_url":"https://api.github.com/users/JuliaOpt/orgs","repos_url":"https://api.github.com/users/JuliaOpt/repos","events_url":"https://api.github.com/users/JuliaOpt/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaOpt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JuliaOpt/JuMP.jl","description":"Modeling language for Mathematical Programming (linear, mixed-integer, conic, nonlinear)","fork":false,"url":"https://api.github.com/repos/JuliaOpt/JuMP.jl","forks_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/forks","keys_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/teams","hooks_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/hooks","issue_events_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/events{/number}","events_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/events","assignees_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/assignees{/user}","branches_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/branches{/branch}","tags_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/tags","blobs_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/languages","stargazers_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/stargazers","contributors_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/contributors","subscribers_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/subscribers","subscription_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/subscription","commits_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/contents/{+path}","compare_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/merges","archive_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/downloads","issues_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues{/number}","pulls_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/labels{/name}","releases_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/releases{/id}","created_at":"2012-10-10T00:34:45Z","updated_at":"2015-09-23T21:47:33Z","pushed_at":"2015-09-27T18:50:29Z","git_url":"git://github.com/JuliaOpt/JuMP.jl.git","ssh_url":"git@github.com:JuliaOpt/JuMP.jl.git","clone_url":"https://github.com/JuliaOpt/JuMP.jl.git","svn_url":"https://github.com/JuliaOpt/JuMP.jl","homepage":"","size":9544,"stargazers_count":177,"watchers_count":177,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":65,"forks":44,"open_issues":65,"watchers":177,"default_branch":"master"}},"base":{"label":"JuliaOpt:master","ref":"master","sha":"a028d17dcc7be6909264727652055865f9a0b7e2","user":{"login":"JuliaOpt","id":5667382,"avatar_url":"https://avatars.githubusercontent.com/u/5667382?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaOpt","html_url":"https://github.com/JuliaOpt","followers_url":"https://api.github.com/users/JuliaOpt/followers","following_url":"https://api.github.com/users/JuliaOpt/following{/other_user}","gists_url":"https://api.github.com/users/JuliaOpt/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaOpt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaOpt/subscriptions","organizations_url":"https://api.github.com/users/JuliaOpt/orgs","repos_url":"https://api.github.com/users/JuliaOpt/repos","events_url":"https://api.github.com/users/JuliaOpt/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaOpt/received_events","type":"Organization","site_admin":false},"repo":{"id":6150069,"name":"JuMP.jl","full_name":"JuliaOpt/JuMP.jl","owner":{"login":"JuliaOpt","id":5667382,"avatar_url":"https://avatars.githubusercontent.com/u/5667382?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaOpt","html_url":"https://github.com/JuliaOpt","followers_url":"https://api.github.com/users/JuliaOpt/followers","following_url":"https://api.github.com/users/JuliaOpt/following{/other_user}","gists_url":"https://api.github.com/users/JuliaOpt/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaOpt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaOpt/subscriptions","organizations_url":"https://api.github.com/users/JuliaOpt/orgs","repos_url":"https://api.github.com/users/JuliaOpt/repos","events_url":"https://api.github.com/users/JuliaOpt/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaOpt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JuliaOpt/JuMP.jl","description":"Modeling language for Mathematical Programming (linear, mixed-integer, conic, nonlinear)","fork":false,"url":"https://api.github.com/repos/JuliaOpt/JuMP.jl","forks_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/forks","keys_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/teams","hooks_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/hooks","issue_events_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/events{/number}","events_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/events","assignees_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/assignees{/user}","branches_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/branches{/branch}","tags_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/tags","blobs_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/languages","stargazers_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/stargazers","contributors_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/contributors","subscribers_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/subscribers","subscription_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/subscription","commits_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/contents/{+path}","compare_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/merges","archive_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/downloads","issues_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues{/number}","pulls_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/labels{/name}","releases_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/releases{/id}","created_at":"2012-10-10T00:34:45Z","updated_at":"2015-09-23T21:47:33Z","pushed_at":"2015-09-27T18:50:29Z","git_url":"git://github.com/JuliaOpt/JuMP.jl.git","ssh_url":"git@github.com:JuliaOpt/JuMP.jl.git","clone_url":"https://github.com/JuliaOpt/JuMP.jl.git","svn_url":"https://github.com/JuliaOpt/JuMP.jl","homepage":"","size":9544,"stargazers_count":177,"watchers_count":177,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":65,"forks":44,"open_issues":65,"watchers":177,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/590"},"html":{"href":"https://github.com/JuliaOpt/JuMP.jl/pull/590"},"issue":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/590"},"comments":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/590/comments"},"review_comments":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/590/comments"},"review_comment":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/590/commits"},"statuses":{"href":"https://api.github.com/repos/JuliaOpt/JuMP.jl/statuses/730a321d9b8e3b085bbd44ab1b9afdfd6c845109"}}}}