Skip to content

Conversation

@xuhdev
Copy link
Collaborator

@xuhdev xuhdev commented Jun 28, 2019

Stack from ghstack:

Close #20024, Close #22246, Close #22262

Related #22324

Differential Revision: D16183577

@pytorchbot pytorchbot added module: internals Related to internal abstractions in c10 and ATen module: operators module: pybind Related to our Python bindings / interactions with other Python libraries labels Jun 28, 2019
@xuhdev xuhdev requested review from colesbury and izdeby June 28, 2019 00:05
@li-roy li-roy added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 28, 2019
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
@xuhdev
Copy link
Collaborator Author

xuhdev commented Jun 28, 2019

This commit changes the ~ operator from being a simple 1-self to have a bitwise NOT functionality, because it is usually understood so in Python. Indeed, two mentioned issues, #22246 and #22324, (mis-)understand this operator as a "bitwise" operator.

Previously, as discussed in #4082, ~ was kept as 1-self because ByteTensor was playing double duty of uint8 and bool. Given that we have BoolTensor now, do you think it is time to make the switch? @apaszke @colesbury

auto& self_ = reinterpret_cast<THPVariable*>(self)->cdata;
if (self_.scalar_type() != at::kByte) {
throw TypeError("~ (operator.invert) is only implemented on byte tensors");
if (!isIntegralType(self_.scalar_type()) && self_.scalar_type() != at::kBool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't bool an integral type? It's not different than uint1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's defined here. It's probably worth another independent PR for discussing it...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like current usage and definition of isIntegralType are more of semantic sense (bool is technically integral, but semantically it is not used as an integer). I would lean toward keep it as it is now.

Examples:

xuhdev added 2 commits June 30, 2019 09:23
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
@xuhdev xuhdev requested a review from apaszke June 30, 2019 16:25
@xuhdev
Copy link
Collaborator Author

xuhdev commented Jun 30, 2019

@pytorchbot retest this please

1 similar comment
@xuhdev
Copy link
Collaborator Author

xuhdev commented Jul 1, 2019

@pytorchbot retest this please

xuhdev added 3 commits July 1, 2019 13:04
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
@xuhdev xuhdev requested a review from colesbury July 1, 2019 22:25
xuhdev added 7 commits July 1, 2019 15:27
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
xuhdev added 4 commits July 2, 2019 20:24
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
Delegate Python ~ (invert operator) to Tensor.bitwise_not().

Close #20024, Close #22246, Close #22262

Related #22324

gh-metadata: pytorch pytorch 22326 gh/xuhdev/8/head
@colesbury
Copy link
Member

@xuhdev is this stack of PRs ready?

@xuhdev
Copy link
Collaborator Author

xuhdev commented Jul 9, 2019

@colesbury Yes.

@xuhdev
Copy link
Collaborator Author

xuhdev commented Jul 10, 2019

@pytorchbot merge this please

@pytorchbot pytorchbot added the merge-this-please Was marked for merge with @pytorchbot merge this please label Jul 10, 2019
@xuhdev xuhdev deleted the gh/xuhdev/8/head branch July 10, 2019 19:25
@facebook-github-bot
Copy link
Contributor

@colesbury merged this pull request in 9c4c9c3.

@colesbury
Copy link
Member

I'm reverting this for now. The problem is that comparison operators still return torch.uint8 and now ~ behaves differently. Once comparison operators return torch.bool we can re-land this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-this-please Was marked for merge with @pytorchbot merge this please Merged module: bc-breaking Related to a BC-breaking change module: internals Related to internal abstractions in c10 and ATen module: pybind Related to our Python bindings / interactions with other Python libraries open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants