-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[Discussion] Expected behavior of logical expressions in Taichi #3635
Comments
I think the behavior should be identical to Python's because most Python users would expect taichi's grammar is similar to Python's. |
I second @lin-hitonami 's idea, python frontend's behavior should be close to python convention as much as possible. ;) |
According to the discussions in this line, we will make the behavior of logical expressions in Taichi the same as Python. |
There is a problem if we make the behavior the same as Python. For this program: @ti.kernel
def foo(a: ti.i32, b: ti.f32):
c = a and b What is the type of |
Yes this is indeed a problem. We cannot have exactly the same behavior as Python because Taichi is statically typed. In Taichi, all operands of logical expressions should be enforced to have a same type. Then the core problem is more related to the order of our compilation process - we should do type check first, and then do transformations which may lose type enforcement information. |
Currently, there isn't a clear description of expected behavior of logical expressions (
and
/or
) in Taichi. The implementation,taichi/python/taichi/lang/ops.py
Lines 792 to 793 in 71dd174
logical_and
/logical_or
is simply treated asbitwise_and
/bitwise_or
. This leads to the non-short-circuit behavior (#3572) and the non-intuitive computation result:In Python, the behavior of logical expressions is like:
which is short-circuiting and uses the determining expression as the result.
Should we make logical expressions in Taichi behave the same as in Python, keep the original behavior in Taichi, or define yet-another behavior? Opinions are welcome.
The text was updated successfully, but these errors were encountered: