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

"Key not found" error with colons #643

Closed
IainNZ opened this issue Jan 11, 2016 · 9 comments
Closed

"Key not found" error with colons #643

IainNZ opened this issue Jan 11, 2016 · 9 comments
Labels
Category: Containers Related to the Containers submodule

Comments

@IainNZ
Copy link
Collaborator

IainNZ commented Jan 11, 2016

julia> m = Model()
julia> @defVar(m, x[i=1:5,j=1:5,k=0:j])
julia> x[:,1,0]
ERROR: KeyError: (Colon(),1,0) not found
 in getindex at /Users/idunning/.julia/v0.4/JuMP/src/JuMPContainer.jl:48

We should probably be providing a better error message here

@mlubin
Copy link
Member

mlubin commented Jan 12, 2016

We can fix #287 now

@joehuchette
Copy link
Contributor

FWIW:

julia> @defVar(m, x[i=1:5,j=1:5,k=0:5]);

julia> x[:,1,0]
ERROR: MethodError: `isless` has no method matching isless(::Colon, ::Int64)
Closest candidates are:
  isless(::AbstractFloat, ::Real)
  isless(::Real, ::Real)
  isless(::Char, ::Integer)
  ...
 in getindex at /Users/huchette/.julia/v0.4/JuMP/src/JuMPArray.jl:61

@mlubin
Copy link
Member

mlubin commented Mar 3, 2016

We can give a better error message here, if we assume that nobody would use [Colon()] as an index set...

@joehuchette
Copy link
Contributor

Well we can always make

S = [Colon()]
@defVar(m, x[S])

an error...

@joehuchette
Copy link
Contributor

It's weird, but I'm not sure we can disambiguate the case @IainNZ mentions and this one:

julia> @defVar(m, y[[:]]);

julia> y[:]
1-element Array{JuMP.Variable,1}:
 y[Colon()]

@mlubin mlubin reopened this May 31, 2016
@mlubin
Copy link
Member

mlubin commented May 31, 2016

@joehuchette, not sure I understand. Can we disambiguate it if we disallow colons in keys?

@joehuchette
Copy link
Contributor

I guess? Seems kinda arbitrary and brittle

@mlubin
Copy link
Member

mlubin commented May 31, 2016

Not having slicing work is also brittle and seemingly arbitrary since it works for some kinds of JuMP variables and not others.

@joehuchette
Copy link
Contributor

It's certainly less brittle to reliably throw an error than give completely unexpected behavior if you use a : or Colon() in your index set for some reason. I'm open to the idea of allowing slices for JuMPDicts, but I don't think the implementation will be particularly straightforward.

@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
Development

No branches or pull requests

3 participants