-
Notifications
You must be signed in to change notification settings - Fork 25.7k
kthvalue consistency with sort in the presence of NaN #17824
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
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.
|
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. |
|
@t-vi yes taking sort's behavior with nans (placing them as last descending) is reasonable. |
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.
@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
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) |
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
* 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) ...
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.