-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
[Containers] use OrderedDict as the data structure for SparseAxisArray #3681
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3681 +/- ##
==========================================
+ Coverage 98.33% 98.36% +0.03%
==========================================
Files 43 43
Lines 5696 5698 +2
==========================================
+ Hits 5601 5605 +4
+ Misses 95 93 -2 ☔ View full report in Codecov by Sentry. |
Shouldnt the iteration ordering comment be part of docs? |
Yeah. I guess my first question is: should we do this? If we do, we need more docs on the specifics of the order and slicing, and when things can go wrong. Also: https://github.com/jump-dev/JuMP.jl/actions/runs/7944311147 |
The slicing issues you showed seem pretty dangerous. The only downside would be the performance penalty? Did you benchmark it? |
I didn't benchmark it, but I think the risk of incorrect usage outweighs the cost. It's probably slower because creating an ordered dict is slower. But it shouldn't be too bad. |
I agree correctness must come first. Is there any other downside? |
I added a warning. I guess the main downside is that existing iteration orders may change. But that could have happened anyway, because we used a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change of order of eachindex
is indeed sub-optimal since we want SparseAxisArrays
to match the behavior of Array
it is dense and it's indices are Base.OneTo
. However, it doesn't seem that this could be done in general and it's still a strict improvement to the behavior before this PR.
Before merging, we should check if we can trigger issues like We should also audit open issues in OrderedCollections for other potential problems. |
I audited all the open issues. I think we're safe from the The most up for debate issue is: JuliaCollections/OrderedCollections.jl#82 julia> Containers.@container(x[k in 1:2], k, container = SparseAxisArray)
JuMP.Containers.SparseAxisArray{Int64, 1, Tuple{Int64}} with 2 entries:
[1] = 1
[2] = 2
julia> Containers.@container(y[k in 2:-1:1], k, container = SparseAxisArray)
JuMP.Containers.SparseAxisArray{Int64, 1, Tuple{Int64}} with 2 entries:
[2] = 2
[1] = 1
julia> x == y
true But this coincidentally just reproduces the behavior of the current JuMP: julia> Containers.@container(x[k in 1:2], k, container = SparseAxisArray)
JuMP.Containers.SparseAxisArray{Int64, 1, Tuple{Int64}} with 2 entries:
[1] = 1
[2] = 2
julia> Containers.@container(y[k in 2:-1:1], k, container = SparseAxisArray)
JuMP.Containers.SparseAxisArray{Int64, 1, Tuple{Int64}} with 2 entries:
[1] = 1
[2] = 2
julia> x == y
true |
JuliaCollections/OrderedCollections.jl#82 isn't too concerning to me. |
So good to merge then? |
Closes #3678
Closes #3680
The issue is still really that
SparseAxisArray
is not a regular n-dimensional Array. Each slice can have a different length with different axes. It doesn't make sense to support a lot of operations with it.The only thing that we should support are vectors.
This PR has the problem that the current iteration order is the transpose of what it "should" be (row-major, instead of column-major).
This is needed because the second and subsequent dimensions can depend on the first and prior. So it isn't really meaningful to iterate "down" the first index holding all else constant.
I can see this being a constant source of future problems.