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

Iterable JuMPArray #833

Closed
ccoffrin opened this issue Aug 17, 2016 · 5 comments
Closed

Iterable JuMPArray #833

ccoffrin opened this issue Aug 17, 2016 · 5 comments
Labels
Category: Containers Related to the Containers submodule

Comments

@ccoffrin
Copy link
Contributor

It would be nice if the JuMPArray was iterable for clean use in for loops.

@mlubin
Copy link
Member

mlubin commented Aug 17, 2016

What do you want this to look like? JuMPArray is sort of more like a dictionary than an array. You can use keys to iterate through it (see #646).

@ccoffrin
Copy link
Contributor Author

Aaa I see. With a generic Julia Dict you can do this,

for (k,v) in dict
   println(k) #key
   println(v) #value
end

which can cover the case when you only need the key or the value as well as when you want both. What do you think about adding support for that?

@mlubin
Copy link
Member

mlubin commented Aug 17, 2016

The larger issue is the inconsistencies between Array{Variable} and JuMPArray{Variable}, because sometimes it's a JuMP artifact which type is returned:

S = 1:3
x = @variable(m, [S]) # JuMPArray
y = @variable(m, [1:3]) # Julia Array

It's a bad idea to have different iteration syntax for x and y, so I'd like to figure out a consistent global approach (including solving #646) before adding any new features that might be broken later.

@ccoffrin
Copy link
Contributor Author

Agreed, this is a bigger issue. My first impression is that JuMPArray is a more general data-structure so that could be the standard type to return. Then you only need to define iteration over JuMPArrays and its always consistent.

As a side note, in my case I am using getvariable(m, symbol) and getting a JuMPArray.

@mlubin
Copy link
Member

mlubin commented Aug 17, 2016

If you're indexing over anything other than a product of 1-based ranges, then you won't get a plain Julia array.

@mlubin mlubin added the Category: Containers Related to the Containers submodule label Jan 8, 2017
@mlubin mlubin mentioned this issue Sep 16, 2017
3 tasks
mlubin added a commit that referenced this issue Sep 17, 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)
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

2 participants