-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Improve quantile in corner cases of collection eltype #30938
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
25d7277
Allow union with Missing in quantile
bkamins dd08824
an improved implementation
bkamins 64fac8d
fix typo
bkamins 00de656
fix after a review
bkamins e75d6e4
add PR number
bkamins 09b7eaf
merge methods
bkamins b7105fb
add more tests
bkamins d1e9b7e
improve type inference
bkamins 25909a5
tests for type stability
bkamins 94b164b
improve tests
bkamins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could be worth testing with
p::Vector{Any}
when it is non-empty, since we allow for it.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.
Good point. I have added two more tests. What is relevant here is that using
map
we have some type instability (this problem was present with tuple version already) - I expose this instability in tests.Here is the problem (I show it on tuple which works the same before and after 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.
Ah, that's annoying. Maybe change:
to
Or maybe we can just do
T = typeof(v[1]*h)
? What's the point of using promotion?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.
Both proposals are not ideal as
v[1]
may have a type unrelated to the type we actually need, e.g. forVector{Real}
with heterogeneous inputs. I have proposed something else that I think better captures what we want - it always combines the types of elements required and the type of quantile required.Note that in corner cases of
0
or1
as quantile we still get an integer:but I think it is OK to leave it as is (we could enforce these cases to produce a float result, but I am not sure if we should, as in general we do not guarantee that
quantile
returns anAbstractFloat
).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.
Makes sense. Just to be sure: when you say we get an integer for
0
and1
, that's not the case with0.0
and1.0
, right?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.
Right. Simply only if you pass an integer as a quantile (which is possible if the quantile is equal to
0
or1
). The key line isf0 = (lv - 1)*p
with evaluates to an integer ifp
is an integer, and this propagates (as we only have additions and multiplications later).