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

Implement DoubleDicts #1126

Merged
merged 12 commits into from
Jul 24, 2020
Merged

Implement DoubleDicts #1126

merged 12 commits into from
Jul 24, 2020

Conversation

joaquimg
Copy link
Member

@joaquimg joaquimg commented Jul 12, 2020

Improve performance of IndexMap for constraints.

Open for name suggestions.

src/Utilities/DoubleDict.jl Outdated Show resolved Hide resolved
src/Utilities/DoubleDict.jl Outdated Show resolved Hide resolved
src/Utilities/DoubleDict.jl Outdated Show resolved Hide resolved
@joaquimg joaquimg changed the title [RFC] Double Dict Implement DoubleDicts Jul 14, 2020
@joaquimg joaquimg requested a review from blegat July 14, 2020 04:36
@joaquimg joaquimg requested a review from blegat July 14, 2020 20:05
const MOI = MathOptInterface
const CI{F,S} = MOI.ConstraintIndex{F,S}

abstract type AbstractDoubleDict{V, D<:AbstractDict{Int64, V}, D2<:AbstractDict{Tuple{DataType, DataType}, D}} end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it an AbstractDict ? I would maybe do AbstractDoubleDict{K, V, ...} <: AbstractDict{K, V}.
For D, I would just do D <: AbstractDict{Int64}. Indeed, for instance, you might want DoubleDict to contain F. In this case you have D = AbstractDict{Int64, F} so the type of the dict is different for each (F, S). If you impose it to be Dict{Int64, MO.AbstractFunction} then this will convert the inner type-stable dicts to type unstable dicts Dict{Int64, MO.AbstractFunction}. This is the case for UniversalFallback for instance which stores functions, sets pairs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it can be an AbstractDict, if we add the key type K to the parameters it will always be not concrete because the are CI{F,S} for multiple F,S pairs. By not typing the key type at all we have a special structure that can dispatch properly and well typed for those "unstable" keys.

Copy link
Member Author

@joaquimg joaquimg Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the second part,
We might do that as a third DoubleDict type, could be KeyDependentDoubleDict, so we can have the inner dict values type depending on the keys.
The upper dict will not be type-stable for this third type, however, the lower dict could be type stable, which indeed might be more important for performance.

and make double dict a subtype of abstract dict
@joaquimg joaquimg requested a review from blegat July 18, 2020 23:27
@joaquimg
Copy link
Member Author

@blegat now there is a FunctionSetDoubleDict that can be used in universallfallback.
What do you think of the current state?

@joaquimg joaquimg requested a review from blegat July 19, 2020 16:17
@blegat blegat merged commit 8d7f492 into master Jul 24, 2020
@blegat blegat added this to the v0.9.15 milestone Jul 24, 2020
@odow odow deleted the jg/doubledict branch September 2, 2020 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants