kthvalue consistency with sort in the presence of NaN#17824
Closed
t-vi wants to merge 3 commits intopytorch:masterfrom
Closed
kthvalue consistency with sort in the presence of NaN#17824t-vi wants to merge 3 commits intopytorch:masterfrom
t-vi wants to merge 3 commits intopytorch:masterfrom
Conversation
This PR causes kthvalue to be consistent with sort (i.e. treat NaN as larger than any number), so that a.kthvalue(n) == a.sort()[n - 1]. One drawback is that median with a NaN argument does not return NaN, which is a deviation from NumPy. Thank you, @ngimel, for raising this.
Collaborator
Author
|
This will get tests, but I'd thought I'd see if anyone has an opinion whether it's OK to take sort as a model here. |
Collaborator
|
@t-vi yes taking sort's behavior with nans (placing them as last descending) is reasonable. |
ezyang
approved these changes
Mar 11, 2019
Contributor
facebook-github-bot
left a comment
There was a problem hiding this comment.
@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Collaborator
|
Currently sort places nans as last ascending (and so would this pr, so topK of an array having at least K nans will be all nans) |
zdevito
pushed a commit
to zdevito/ATen
that referenced
this pull request
Mar 12, 2019
Summary: This PR causes kthvalue to be consistent with sort (i.e. treat NaN as larger than any number), so that `a.kthvalue(n) == a.sort()[n - 1]`. One drawback is that median with a NaN argument does not return NaN, which is a deviation from NumPy. Thank you, ngimel, for raising this. Pull Request resolved: pytorch/pytorch#17824 Differential Revision: D14410092 Pulled By: ezyang fbshipit-source-id: bdec2d8272dc4c65bcf2f9b8995e237774c44c02
petrex
pushed a commit
to petrex/pytorch
that referenced
this pull request
Mar 14, 2019
* upstream/master: (87 commits) Make Variable::set_data non-const; cosmetic fixes. remove warning for upsample code (pytorch#17921) Optimize TileOp (pytorch#17290) Optimize channel_stats_op (pytorch#16243) enable shape inference for elementwise operators (pytorch#17885) Remove remaining test jit expects redux (pytorch#17924) Handle Scalars Better (pytorch#17875) Fixed a formatting issue in doc comments (pytorch#17505) Add nbytes, itemsize, element_size to at::Tensor. (pytorch#17810) Fix lint in test_distributions.py Fix lint in test_jit.py Fix lint errors in test_autograd Added a few extra python bindings to help with walking the IR graph from Python (pytorch#17822) kthvalue consistency with sort in the presence of NaN (pytorch#17824) Fix minor grammatical mistakes in torch/nn/modules/loss.py (pytorch#17892) Remove (almost all) TensorOptions from native_functions.yaml (pytorch#17385) Restore full Windows tests (pytorch#17102) Prevent VS2017 from emitting ambiguous symbol errors (second time) Fix windows test hang (pytorch#17778) torch.btrifact for tensors with greater than 3 dimensions (pytorch#14964) ...
laurentdupin
pushed a commit
to laurentdupin/pytorch
that referenced
this pull request
Apr 24, 2026
Summary: This PR causes kthvalue to be consistent with sort (i.e. treat NaN as larger than any number), so that `a.kthvalue(n) == a.sort()[n - 1]`. One drawback is that median with a NaN argument does not return NaN, which is a deviation from NumPy. Thank you, ngimel, for raising this. Pull Request resolved: pytorch#17824 Differential Revision: D14410092 Pulled By: ezyang fbshipit-source-id: bdec2d8272dc4c65bcf2f9b8995e237774c44c02
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR causes kthvalue to be consistent with sort
(i.e. treat NaN as larger than any number), so that
a.kthvalue(n) == a.sort()[n - 1].One drawback is that median with a NaN argument does not return NaN,
which is a deviation from NumPy.
Thank you, @ngimel, for raising this.