-
Notifications
You must be signed in to change notification settings - Fork 35
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
Priority as number #90
Conversation
Codecov Report
@@ Coverage Diff @@
## master #90 +/- ##
==========================================
+ Coverage 98.17% 98.20% +0.02%
==========================================
Files 10 10
Lines 274 278 +4
==========================================
+ Hits 269 273 +4
Misses 5 5
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I'll work on resolving the issues next week. |
@@ -63,7 +63,7 @@ function remove_callback(cb::Function, ev::AbstractEvent) | |||
i != 0 && deleteat!(ev.bev.callbacks, i) | |||
end | |||
|
|||
function schedule(ev::AbstractEvent, delay::Number=zero(Float64); priority::Int=0, value::Any=nothing) | |||
function schedule(ev::AbstractEvent, delay::Number=0; priority::Number=0, value::Any=nothing) |
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.
It seems a lot of these type restriction can simply be dropped. Types in function signatures are used only for dispatch, they do not provide performance improvements. And it seems types in kwargs do not even participate in dispatch (see https://discourse.julialang.org/t/force-specialization-on-kwargs/34789/14 ). So this makes types for kwargs (and in particular abstract types) not particularly valuable. In most of these situations (function signatures) you can just delete the ::Int
, no need to add ::Number
.
TODO: should make order of parameters consistent in both resource types (Containers has it as the first parameter. Stores has it as the second).
TODO:
|
@Krastanov, I got it to work without introducing a breaking change. One of the tests on GitHub fails on something with makedocs (nightly). Not sure what that is. Let me know what you think of this PR. Thanks |
I will look into this by the end of the weekend. The documentation tests are unrelated and probably fixed in #93 |
This looks good to me. Could you add tests that it works reliably? E.g.:
And maybe something with BigInt and BigFloat. Mainly to make sure there is no older code that makes some implicit assumptions and breaks. That would also test whether we are missing some |
In the meantime I will fix some of the currently hidden / broken tests. The failure on nightly is unrelated and comes from MacroTools. I will try to fix it upstream sometime soon (see FluxML/MacroTools.jl#195 (feel free to jump in if you feel like it :D ) |
Merging the other pull request caused conflicts. I think I resolved them all, but please double check my merge commit above (and pull it locally if you need to add something more) |
All of the new documentation failures come from a single newly added test. In particular, I think the constructor for |
The error was because that doctest was using the wrong type for capacity. The capacity in a |
put_queue :: DataStructures.PriorityQueue{Put, StorePutKey{T}} | ||
get_queue :: DataStructures.PriorityQueue{Get, StoreGetKey} | ||
function Store{T}(env::Environment; capacity=typemax(UInt)) where {T} | ||
new(env, UInt(capacity), zero(UInt), Dict{T, UInt}(), zero(UInt), DataStructures.PriorityQueue{Put, StorePutKey{T}}(), DataStructures.PriorityQueue{Get, StoreGetKey}()) |
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 explicit UInt(capacity)
cast is removed in the new version. That cast is necessary in order to make capacity=10
work as a keyword argument (which used to be the case until this PR).
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.
SimJulia.jl had the UInt
signature in the capacity
kwarg. I like the idea of using UInt(capacity)
instead of imposing this type on the kwarg, making it possible to use capacity=10
as you suggest. However, we need to still convert to UInt
so that a Store
cannot have a negative capacity.
convert to the resource's priority type
""" | ||
put!(sto::Store, item::T) | ||
|
||
Put an item into the store. Returns the put event, blocking if the store is full. | ||
""" | ||
function put!(sto::Store{T}, item::T; priority::Int=0) where T |
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.
This does not need to be modified, but just FYI, the ::T
in the priority kwarg (and the previously existing ::Int
) are unnecessary (if I understand Julia's dispatch rules correctly). Basically, type signatures of keyword arguments are not used for dispatch, so they are frequently superfluous.
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.
They are still useful as a type assert though
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 now convert to the appropriate type given the type of the Store
Wonderful! I will fix the documentation break that was introduced with the merge with the other PR and will merge this as well. |
Sorry to be a killjoy... I was going through the rest of the code because I was extremely surprised that the Rather now that you have made It is here:
I am a bit on the fence about this. What I plan to do is to add a few broken tests as a reminder that this is something that should probably be fixed in the future. I will add the tests, create a new issue to have them recorded, and merge this. |
Actually, I do not know how to do a recursive isconcretetype check anyway... So I can not write a useful broken test. Given that the heap key is already abstract, I am not too worried about changes in performance, but in the future this would be something to improve. |
You know, now that I think about this. I don't think we should have priorities be |
If you have the bandwidth to do that, I would be very much in favor. |
Replaces #77
change type on
priority
fromInt
toNumber
. This allows passing aFloat
as a priority.Advantages:
This is a more general expression of priority which may make it easier at some point to use rank functions (#75).
This also avoids having to normalize (and sometimes scaling) priorities so that they are integer in queueing systems.