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

Indexing 0-based JuMPArray: end keyword throws errors #730

Closed
dourouc05 opened this issue Apr 15, 2016 · 9 comments
Closed

Indexing 0-based JuMPArray: end keyword throws errors #730

dourouc05 opened this issue Apr 15, 2016 · 9 comments
Labels
Category: Containers Related to the Containers submodule Type: Bug upstream

Comments

@dourouc05
Copy link
Contributor

When I ran code on an updated JuMP (0.12), indexing arrays of variables at [end] stopped working (while this code perfectly worked in JuMP 0.11). Here is a

using JuMP

m = Model()
@defVar(m, x[0:2], Bin)
@setObjective(m, Max, x[1])
solve(m)

getValue(x[end])
getValue(x)[end]

The errors I get (for both examples) are:

ERROR: Failed attempt to index JuMPArray along dimension 1: 3 ∉ 0:2
 in error at error.jl:21

(By the way, is it normal this error does not show where it was triggered from my code?)

@joehuchette
Copy link
Contributor

Sorry for the slow reply. Unfortunately I don't think there's much we can do here: the compiler rewrites x[end] to something like x[size(x,1)]. Are you sure this worked on v0.11?

What do you mean by "this error does not show"? This might be a bug, either on our end or with julia, depending on the behavior.

@mlubin
Copy link
Member

mlubin commented Apr 27, 2016

@joehuchette, I think it uses the endof method, may we shouldn't define it?

@mlubin
Copy link
Member

mlubin commented Apr 27, 2016

The current behavior is dangerous:

julia> @variable(m, x[2:4]);

julia> x[end]
x[3]

@joehuchette
Copy link
Contributor

I'm fine with that

@mlubin
Copy link
Member

mlubin commented Apr 27, 2016

I wonder if we can return a special object from endof analogous to Colon()

@mlubin
Copy link
Member

mlubin commented Apr 27, 2016

No, that doesn't work because that would break end-1

@dourouc05
Copy link
Contributor Author

@joehuchette: to be precise, I tried a larger piece of code that used to work with JuMP 0.11, and it was broken when I retried with JuMP 0.12.

@mlubin
Copy link
Member

mlubin commented Apr 28, 2016

end on multidimensional arrays uses size(), so it's impossible for us to fix this

@mlubin
Copy link
Member

mlubin commented Apr 28, 2016

Maybe the solution is to define size as an error and implement JuMP.size if you actually want to access the dimensions?

mlubin added a commit that referenced this issue Apr 28, 2016
@mlubin mlubin added the Category: Containers Related to the Containers submodule label Jan 8, 2017
mlubin added a commit that referenced this issue Sep 19, 2017
Replace JuMPDict with Dict. Rewrite JuMPArray to be compatible with
AbstractArray. Explicit keyword argument in macro to force container
type.

Closes #1099
Closes #1047
Closes #417 (collect is now well defined for Array, JuMPArray, and Dict)
Closes #833 (`eachindex` and `indices` are defined for JuMPArray)
Closes #740 (dot broadcast syntax is now the default, no need to explicitly define vectorized functions)
Closes #922 (fixed by checking for duplicates)
Closes #933 (corollary: closes #346)
Closes #643 (colons work for Array and JuMPArray, obviously not Dict)
Closes #730 (end is not supported for JuMPArray)
Closes #646 (we now rely on built-in iteration behavior for Dict)
mlubin added a commit that referenced this issue Sep 19, 2017
Replace JuMPDict with Dict. Rewrite JuMPArray to be compatible with
AbstractArray. Explicit keyword argument in macro to force container
type.

Closes #1099
Closes #1047
Closes #417 (collect is now well defined for Array, JuMPArray, and Dict)
Closes #833 (`eachindex` and `indices` are defined for JuMPArray)
Closes #740 (dot broadcast syntax is now the default, no need to explicitly define vectorized functions)
Closes #922 (fixed by checking for duplicates)
Closes #933 (corollary: closes #346)
Closes #643 (colons work for Array and JuMPArray, obviously not Dict)
Closes #730 (end is not supported for JuMPArray)
Closes #646 (we now rely on built-in iteration behavior for Dict)
@mlubin mlubin closed this as completed in 852a3af Nov 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Containers Related to the Containers submodule Type: Bug upstream
Development

No branches or pull requests

3 participants