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

Inspecting the Size of a JuMPArray #1294

Closed
ccoffrin opened this issue May 10, 2018 · 5 comments · Fixed by #1595
Closed

Inspecting the Size of a JuMPArray #1294

ccoffrin opened this issue May 10, 2018 · 5 comments · Fixed by #1595
Assignees
Milestone

Comments

@ccoffrin
Copy link
Contributor

ccoffrin commented May 10, 2018

Initially I tried to inspect the size of a JuMPArray as follows,

using JuMP

m = Model()
v = @variable(m, [i in [1,3,5,7,9], j=1:8], basename="$(i)_$(j)", lowerbound = 0, upperbound = 1)

length(v) # ERROR: JuMPArray does not define size().

v_slice = v[3,:]

length(v_slice) # ERROR: JuMPArray does not define size().

After inspecting the source, I determined this would do what I need,

length(indices(v)) # dimensions
length.(indices(v)) # dimension length check
length(indices(v_slice)) # dimensions
length.(indices(v_slice))[1] # dimension length check

It might be helpful to have some default behavior for the standard Julia array functions like length and size.

@mlubin
Copy link
Member

mlubin commented May 10, 2018

I was following https://docs.julialang.org/en/latest/devdocs/offset-arrays/, but the guidance may have changed for 0.6/0.7.

@ccoffrin
Copy link
Contributor Author

ccoffrin commented May 11, 2018

I see, the logic outlined in offset arrays makes sense to me, but I had not been exposed to them yet so I was lost for the function naming pattern. A more helpful error message would surely mitigate the issue.

Possibly the root of my confusion is Array in the name, it made me think it would behave like typical Julia array, but it is more flexible than that. Maybe something like JuMPCollection{N}, would be more semantics agnostic, and the dimension number N would give a hint that it has some features similar to standard multidimensional arrays.

@mlubin
Copy link
Member

mlubin commented May 11, 2018

The use of Array in JuMPArray is consistent with OffsetArrays and AxisArrays. I agree that the error messages should be more helpful.

@ccoffrin
Copy link
Contributor Author

An improved error message sounds good to me.

@mlubin mlubin added this to the 0.19 milestone Jun 4, 2018
@mlubin
Copy link
Member

mlubin commented Nov 8, 2018

Both OffsetArrays and AxisArrays now define size, so I think it's safe for us to do so also.

@blegat blegat self-assigned this Nov 10, 2018
blegat added a commit that referenced this issue Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants