-
-
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
WIP: Refactor JuMPDict code #192
Conversation
Conflicts: src/JuMPDict.jl
Conflicts: src/JuMPDict.jl
Somewhat maybe working now, besides printing. There's a 14x slowdown on |
|
||
function Base.getindex{T,N}(d::JuMPArray{T,N,UnitRange{Int}},indices::Int...) | ||
length(indices) == N || error("Wrong number of indices for ",d.name,", expected ",length(d.indexsets)) | ||
idx = Array(Int, N) |
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.
We could probably use a single int here and just compute the linear index in innerArray
.
Still over 2x slower once we special case 1d and 2d. We'll have to look at the code generation issues. |
Something not getting inlined perhaps |
I think the |
Probably. Unfortunately NTuple is not currently inlined into datatypes. Fixing that is extremely high on my todo list. |
Is there a workaround besides generating the types for each N with a macro? |
No not currently. Honestly if you can temporarily live with the slowdown, just use it and I promise it'll be fixed soon. I don't know of a good workaround other than what you suggested. |
Do you think its something that will sneak into to 0.3? |
Ah, that's a good question. I'm not sure if we'll be able to do that. @JeffBezanson? |
There's enough on the plate already for 0.3, I think :) |
It'd be a shame to take the performance hit, especially since JuMPArrays are probably the cases where performance is most critical. Can we retain the old type generation for JuMPArrays and use the new stuff for everything else, so we can get diagonal indexing and all the other goodies? |
Just restored the old code for JuMPArrays, so no performance hits to the benchmarks. JuMPDict is now a plain dictionary. Just need to update the printing. |
We should save the trashed code somewhere so we can add it once 0.4 drops (or whatever release won't have the performance hit). |
It's still there. |
Yep, saw that as soon as I left the comment :) |
TODO for merging this:
|
Thoughts on how to support conditions? |
It's easy, we can do |
Actually julia doesn't like that syntax |
I agree, but without |
I put in the request at JuliaLang/julia#7225 |
We don't need to block this on the conditional syntax, that can come later. |
Do you want to merge this and just eat the performance hit for the time being? |
We already restored the fast and ugly code for range indices, so there's no performance hit. Just need to clean up and get tests passing. |
What's left to do here? I'm seeing
during the test suite. |
Yes, printing needs to be rewritten. |
@IainNZ any chance you can take a look at the printing code on this branch? :) |
I can get printing working. It says there is a merge conflict, and I see a new file that isn't actually included... I haven't been following this PR, is it possible to do a quick tidy up first? |
I'll tidy it up |
Conflicts: src/JuMP.jl src/JuMPDict.jl src/macros.jl
Ok, merge conflicts fixed |
Guys, printing JuMPDicts is now, well, much harder, because it doesn't store what the index sets are. Now, if the JuMPDict is the product of a conditional thing, I don't think pretty printing is really possible, but it'd be nice if it worked when its just indexed over simple sets. The best I can think of do right now is to collect a vector for each index, sort it, and print it like we do arbitrary sets now (which would work nicely for 1:2:9, for example). But I'd want a flag if it was produced with a conditional filter so I could not do that in that case (misleading). Thoughts? |
I think I'd prefer to lump |
(If this were the case, we could just punt on printing JuMPDicts altogether and not worry about trying to piece together some sort of hidden structure). |
Will this all need to change again when we can switch to this new-and-improved JuMPArrays? and is there any benefit before we can do conditionals? |
The commented-out new JuMPArrays already support step ranges. For JuMPDicts we could special case the detection of index sets without conditions, however, there's nothing stopping users from adding additional variables to the JuMPDict at a later point, and we probably want to allow this. What we can get from the JuMPDict is the number of index sets, and we could store their names at creation. What about trying to detect if the JuMPDict is indexed by a cartesian product of sets at print time? I think that can be done in linear space and time. |
Trying to detect cartesian sets seems like a good idea if we can do it somewhat efficiently. We can also cache the results and have some kind of marker if new variables are added. Relatedly: what should the behavior be if I want to add a new variable to a JuMPArray? Should everything be copied over and I end up with a JuMPDict? |
Here's a fast algorithm to detect cartesian sets: Initialize a set s[k] for each dimension k Adding new variables to JuMPArrays is tricky... We can't change the type of the container at runtime. Not sure the best way to handle this. |
Can we close this in lieu of #241? |
Mostly doing this to get a diff on the entire repo.