-
Notifications
You must be signed in to change notification settings - Fork 26.3k
named tensor support for torch.equal #29322
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
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests [ghstack-poisoned]
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests ghstack-source-id: 9e05747 Pull Request resolved: #29322
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests [ghstack-poisoned]
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests ghstack-source-id: 5c0d544 Pull Request resolved: #29322
| return equal; | ||
| } | ||
|
|
||
| int THTensor_(equal)(THTensor *ta, THTensor* tb) { |
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.
it looks like this is only called from functions like bool _th_equal in LegacyTHFunctionsCPU.cpp. Would it be easy to return a bool here (and in the cuda version) instead of returning an int and casting farther up the stack?
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.
The original function returned an int so I am following that convention. I don't know the answer to whether or not a bool return here changes the behavior.
| } | ||
|
|
||
| bool are_names_equal(TensorImpl* self, TensorImpl* other) { | ||
| if (!impl::has_names(self) && !impl::has_names(other)) { |
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.
nit: I don't know if this is better since it might be less clear to read, but I'd be tempted to put:
if (!impl::has_names(self)) {
return !impl::has_names(other);
}
short-circuits the case where they're not equal and only the second arg has names.
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.
That's not correct. If other doesn't have names and self does have names, their names can still be equal if all of self's names are None.
nairbv
left a comment
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.
minor suggestions but looks good
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests [ghstack-poisoned]
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests ghstack-source-id: 71151c3 Pull Request resolved: #29322
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests [ghstack-poisoned]
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests ghstack-source-id: f61b2a6 Pull Request resolved: #29322
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests [ghstack-poisoned]
torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests ghstack-source-id: 3fa5177 Pull Request resolved: #29322
Summary: Pull Request resolved: pytorch/pytorch#29322 torch.equal checks if two tensors are equal in both size and values. For named tensors, it also checks that the names are exactly equal. There is an argument to be made for alternative semantics (check that the names *match*), but for an API that is called "equal" I would expect it to check equality on names as well. Test Plan: - new tests Differential Revision: D18453387 Pulled By: zou3519 fbshipit-source-id: d52bde4e3fdd7f331eef097a3b31d35c89c78049
Stack from ghstack:
torch.equal checks if two tensors are equal in both size and values. For
named tensors, it also checks that the names are exactly equal. There is
an argument to be made for alternative semantics (check that the names
match), but for an API that is called "equal" I would expect it to
check equality on names as well.
Test Plan:
Differential Revision: D18453387