Implement NumPy-like function torch.msort()#48440
Implement NumPy-like function torch.msort()#48440Kiyosora wants to merge 7 commits intopytorch:masterfrom
Conversation
c3fe50c to
19ba246
Compare
💊 CI failures summary and remediationsAs of commit 8428c25 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 37 times. |
bf0e607 to
7648bee
Compare
There was a problem hiding this comment.
I appreciate that this is more consistent with PyTorch, but let's just return values to be consistent with NumPy.
There was a problem hiding this comment.
Gotcha! Thanks for your advice!
There was a problem hiding this comment.
With just values supported, msort_out won't take indices.
There was a problem hiding this comment.
Let's not implement the descending argument for now. NumPy's msort doesn't have one.
There was a problem hiding this comment.
These look good but see comments above for tweaks.
There was a problem hiding this comment.
msort will be removed from this list once it returns only the tensor.
There was a problem hiding this comment.
msort will be removed from this list, too, once it returns only the tensor
There was a problem hiding this comment.
PyTorch now requires NumPy to run the test suite, so we no longer need to test for it. This line can be removed.
There was a problem hiding this comment.
Add a 1D shape and an empty shape, too.
There was a problem hiding this comment.
Addressed! But it's seem that np.msort() does not support empty shape tensor, so I distinguish the judging condition of this situation from the general.
>>> import torch
>>> import numpy as np
>>> t=torch.empty([])
>>> t
tensor(0.)
>>> torch.msort(t)
tensor(0.)
>>> np.msort(t.cpu().numpy())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 5, in msort
File "C:\Users\Medius Axman\anaconda3\envs\pytorch\lib\site-packages\numpy\lib\function_base.py", line 3374, in msort
b.sort(0)
numpy.AxisError: axis 0 is out of bounds for array of dimension 0
There was a problem hiding this comment.
Thank you for noticing this. NumPy is inconsistent with its support of empty tensors, and it's great that we support them even when NumPy doesn't.
There was a problem hiding this comment.
This will need to be updated.
There was a problem hiding this comment.
This will need to be updated per the above comments
There was a problem hiding this comment.
This sentence an be removed.
There was a problem hiding this comment.
This sentence can be removed.
There was a problem hiding this comment.
This will need a small update to be equivalent to torch.sort(t, dim=0)[0]
There was a problem hiding this comment.
This can be updated to just be "{out}"
There was a problem hiding this comment.
When a name is needed for only a single tensor use "t". Print the matrix before sorting it so users can understand the before and after of sorting.
There was a problem hiding this comment.
This case can be removed.
There was a problem hiding this comment.
"along the first" -> "along its first"
mruberry
left a comment
There was a problem hiding this comment.
Hey @Kiyosora! Thanks for implementing torch.msort. This looks great and I made a few comments for tweaks. The biggest change is that we can simplify the this implementation to be more consistent with NumPy. I appreciate your thoughtfulness in trying to be more consistent with PyTorch, but let's err on the side of caution for now.
7648bee to
08162c8
Compare
bcb05d2 to
b6321b6
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Thank you very much for reviewing this PR, @mruberry . |
|
I would like to recommend a the following options:
Do any of those sound interesting? |
Wow, thanks so much for such detailed introduction, @mruberry. 👍 These issues all look very attractive, I can't wait to implement them now. My good buddy (@RockingJavaBean) and I would start to work on them as soon, new PRs would be proposed in near future. |
|
Darn. Sorry @Kiyosora, tried to land this but we hit a merge conflict while it was landing. Would you rebase this, please? |
b6321b6 to
8428c25
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: - Related with pytorch#38349 - Implementing the NumPy-like function `torch.msort()` . Pull Request resolved: pytorch#48440 Reviewed By: bdhirsh Differential Revision: D25265753 Pulled By: mruberry fbshipit-source-id: 7709ac5e5667e7541a3dc9048b9c9896b1a6dfa1
) Summary: - Implementing the NumPy-like function`torch.fmax()` and `torch.fmin()` recommended in pytorch#48440 Pull Request resolved: pytorch#49312 Reviewed By: izdeby Differential Revision: D25887246 Pulled By: heitorschueroff fbshipit-source-id: d762eeff8b328bfcbe7d48b7ee9d2da72c249691
torch.msort().