Skip to content

Logical short circuit#11116

Closed
eellison wants to merge 5 commits intopytorch:masterfrom
eellison:logical_short_circuit
Closed

Logical short circuit#11116
eellison wants to merge 5 commits intopytorch:masterfrom
eellison:logical_short_circuit

Conversation

@eellison
Copy link
Contributor

@eellison eellison commented Aug 30, 2018

Adding short circuit evaluation to AND or OR. The second expression of and AND or OR gets lifted into an if branch, which is conditionally evaluated.

BatchOps was using the expression dims = dims1 or dims2, where dims is often an empty tensor. This nows throws an error, because dims1 gets cast to a boolean, and you can't convert an empty tensor to a scalar. It now matches the behavior of pytorch in python.

One thing that came up is if the second expression in an and/or in python gets returned, it does not get coerced to a boolean.

tensor == (False or tensor)
tensor == (True and tensor)

We do not currently support this.

edit: wording

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@eellison eellison force-pushed the logical_short_circuit branch 2 times, most recently from 280b6bd to 90cb749 Compare August 31, 2018 17:48
@eellison eellison force-pushed the logical_short_circuit branch from 90cb749 to caa6fcb Compare August 31, 2018 17:55
test/test_jit.py Outdated
self.assertExpectedGraph(testNoThrows.graph)
with self.assertRaises(RuntimeError):
throwsOr(t)
with self.assertRaises(RuntimeError):

This comment was marked as off-topic.

This comment was marked as off-topic.

auto first_expr = [&] {
return emitExpr(expr.true_expr());
};
auto second_expr = [&] {

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@eellison
Copy link
Contributor Author

@pytorchbot retest this please

PenghuiCheng pushed a commit to PenghuiCheng/pytorch that referenced this pull request Sep 11, 2018
Summary:
Adding short circuit evaluation to AND or OR. The second expression of and AND or OR gets lifted into an if branch, which is conditionally evaluated.

BatchOps was using the expression `dims = dims1 or dims2`, where dims is often an empty tensor. This nows throws an error, because dims1 gets cast to a boolean, and you can't convert an empty tensor to a scalar. It now matches the behavior of pytorch in python.

One thing that came up is if the second expression in an and/or in python gets returned, it does not get coerced to a boolean.

`tensor == (False or tensor)`
`tensor == (True and tensor)`

We do not currently support this.

edit: wording
Pull Request resolved: pytorch#11116

Differential Revision: D9618168

Pulled By: eellison

fbshipit-source-id: 93b202be2f222d41f85d38d9c95f04d1749e8343
@ezyang ezyang added the merged label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants