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

Support for Base.OneTo(3) #933

Closed
colinfang opened this issue Jan 9, 2017 · 4 comments
Closed

Support for Base.OneTo(3) #933

colinfang opened this issue Jan 9, 2017 · 4 comments
Milestone

Comments

@colinfang
Copy link

colinfang commented Jan 9, 2017

Shall we support Base.OneTo now that it becomes commonly used in Base.

m = Model()
@variable(m, 0 <= x[Base.OneTo(3), 1:2] <= 3, Int)

0≤x i,j≤3,∈ℤ,∀i∈{1,2,3},j∈{2}

@constraint(m, sum(x[:, 1]) == 1)
Failed attempt to index JuMPArray along dimension 1: Colon() ∉ Base.OneTo(3)
@mlubin
Copy link
Member

mlubin commented Jan 9, 2017

What's the point of this if you can write 1:3?

@colinfang
Copy link
Author

colinfang commented Jan 9, 2017

I want to define variables/constraints programmatically. I used to do it like the following because Julia recommends eachindex(x) over 1:length(x). However after v0.5 the former returns OneTo

m = Model()
idx = eachindex(A) # I could write idx = 1:length(A)

@variable(m, 0 <= x[idx, 1:2] <= 3, Int)
@constraint(m, sum(x[:, 1]) == 1)

@mlubin
Copy link
Member

mlubin commented Jan 9, 2017

idx is not used in that example

@mlubin
Copy link
Member

mlubin commented Jan 9, 2017

Anyway since OneTo is a range with "lower limit ... guaranteed (by the type system) to be 1" it's a potential solution for the type instability issue in #346. So it's possible to support, although I don't understand your use case.

@mlubin mlubin added this to the 1.0 milestone Jun 9, 2017
@mlubin mlubin mentioned this issue Sep 17, 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
None yet
Development

No branches or pull requests

2 participants