-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add support for scalars and numpy in torch.testing #55786
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
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 30b74a8 (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. ghstack-source-id: 741591d Pull Request resolved: #55786
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
Are there corner cases where casting an ndarray or a scalar to a Tensor is not the right thing to do? For instance, comparing a complex-valued scalar to an ndarray succeeds but casting them to Tensors and them comparing them fails? |
Before we continue our implementation review cycle, we should probably define what kind of inputs we allow. My idea is to allow all "array-and-scalar-like" inputs. This includes tensors as well as every other object from which a tensor can be created with I would also allow sequences and mappings of the former types ("container of array-and-scalar-likes") for both inputs simultaneously. In this case the checks are performed elementwise. I think this is a straight-forward UI in all but one case:
In the first case the error message would point to index Still, IMO the special case of comparing two multi-level sequences of scalars does not outweigh the benefits of this more general approach. All of this requires
I would simply set the default value to |
From offline discussion:
Note this means that [1, 2] != torch.tensor((1, 2)) and that 2 != complex(2, 0). @pmeier asks (offline): Why is it so horrible if we support Python types not matching? Like, why can't [1, 2] == torch.tensor((1, 2,))? This just goes to readability and reviewability. This is only useful if the expected object differs from the actual object, and it will require test reviewers to understand what's actually being returned by the operator independent of the test. It's much easier for reviewers to check the expected object and know it's actually what the function must return, not something "like" what the function is returning. |
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
@mruberry Should be all done except for
I agree that we should do that, but lets wait with that until we figured out what to do with #55890. |
Sounds good; I'll take a look later today |
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
This is a tricky stack to parse. So let me just ask a few questions and then maybe we can revisit this code after this stack. What will happen with the following tests:
|
@mruberry Assuming
|
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.
Cool!
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. [ghstack-poisoned]
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. Differential Revision: [D27903814](https://our.internmc.facebook.com/intern/diff/D27903814) [ghstack-poisoned]
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. Differential Revision: [D27903814](https://our.internmc.facebook.com/intern/diff/D27903814) [ghstack-poisoned]
Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. Differential Revision: [D27903814](https://our.internmc.facebook.com/intern/diff/D27903814) [ghstack-poisoned]
Summary: Pull Request resolved: pytorch#55786 Add support to compare scalars as well as `np.ndarray`'s with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor. Test Plan: Imported from OSS Reviewed By: albanD Differential Revision: D27903814 Pulled By: mruberry fbshipit-source-id: fe3d063d0c9513cbd8b3408a2023e94c490c817e
Stack from ghstack:
torch.testing
to docs #56373 addtorch.testing
to docstest_testing.py::TestAsserts
for multiple devices #56365 Splittest_testing.py::TestAsserts
for multiple devicestorch.testing
#55890 enable support for custom error messages intorch.testing
torch.testing
#55385 Add support for checking tensor containers intorch.testing
Add support to compare scalars as well as
np.ndarray
's with torch.testing. We are reusing the mathcing functionality that is already in place for tensors, by casting the inputs. The approach can easily extended if we want to support other input types as long as they can be cast to a tensor.Differential Revision: D27903814