Skip to content

Conversation

@zou3519
Copy link
Contributor

@zou3519 zou3519 commented Nov 6, 2019

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:

  • new tests

Differential Revision: D18453387

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]
zou3519 added a commit that referenced this pull request Nov 6, 2019
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
@zou3519 zou3519 requested review from gchanan, izdeby and nairbv November 6, 2019 21:00
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]
zou3519 added a commit that referenced this pull request Nov 6, 2019
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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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)) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

@nairbv nairbv left a 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]
zou3519 added a commit that referenced this pull request Nov 11, 2019
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]
zou3519 added a commit that referenced this pull request Nov 11, 2019
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]
zou3519 added a commit that referenced this pull request Nov 12, 2019
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
zdevito pushed a commit to zdevito/ATen that referenced this pull request Nov 13, 2019
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
@facebook-github-bot
Copy link
Contributor

@zou3519 merged this pull request in ed215b1.

@facebook-github-bot facebook-github-bot deleted the gh/zou3519/212/head branch November 17, 2019 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants