Add torch.can_cast(from, to) function#26805
Conversation
|
@pytorchbot rebase this please |
zou3519
left a comment
There was a problem hiding this comment.
Are there tests for at::canCast somewhere?
|
|
||
| - func: result_type.Scalar_Scalar(Scalar scalar1, Scalar scalar2) -> ScalarType | ||
|
|
||
| - func: can_cast(ScalarType from, ScalarType to) -> bool |
There was a problem hiding this comment.
This is removing variants: function from result_type. However that's the default so it doesn't matter, but I am mentioning that just in case
There was a problem hiding this comment.
ah didn't notice, that probably happened when I fixed my merge conflict with myself. Interesting that it's the default too.
|
|
||
| def test_can_cast(self): | ||
| self.assertTrue(torch.can_cast(torch.double, torch.float)) | ||
| self.assertFalse(torch.can_cast(torch.float, torch.int)) |
There was a problem hiding this comment.
Do you have unit tests for canCast (the cpp function) somewhere?
There was a problem hiding this comment.
I don't, do you think it'd be helpful? it's called/used pretty heavily in the actual arithmetic operators and in tensoriterator, which does have a lot of python test coverage.
There was a problem hiding this comment.
Hmm ideally we'd unit test heavily-used helper functions like canCast during development instead of testing them indirectly by testing arithmetic operators so that we can be sure that we're building on top of working code. But since we have all of those tests for arithmetic operators and type promotion this should be fine.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@nairbv is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: pytorch/pytorch#25472 Pull Request resolved: pytorch/pytorch#26805 Differential Revision: D17628434 Pulled By: nairbv fbshipit-source-id: 6af8031ac3afda1505d338075c0637ad043f8b7e
Summary: pytorch#25472 Pull Request resolved: pytorch#26805 Differential Revision: D17628434 Pulled By: nairbv fbshipit-source-id: 6af8031ac3afda1505d338075c0637ad043f8b7e
Summary: pytorch#25472 Pull Request resolved: pytorch#26805 Differential Revision: D17628434 Pulled By: nairbv fbshipit-source-id: 6af8031ac3afda1505d338075c0637ad043f8b7e
#25472