taichi
taichi copied to clipboard
default_ip=ti.i64 doesn't work with if
To Reproduce
import taichi as ti
ti.init(default_ip=ti.i64)
@ti.kernel
def test_kernel():
stop = 0
if stop:
stop = 1
test_kernel()
Log/Screenshots
[Taichi] version 1.0.5, llvm 10.0.0, commit 40712d7d, linux, python 3.9.12
[Taichi] Starting on arch=x64
Traceback (most recent call last):
File "/home/lin/test/yu.py", line 10, in <module>
test_kernel()
File "/home/lin/taichi/python/taichi/lang/kernel_impl.py", line 926, in wrapped
raise type(e)('\n' + str(e)) from None
taichi.lang.exception.TaichiTypeError:
`if` conditions must be of type i32; found i64. Consider using `if x != 0` instead of `if x` for float values.
maybe @strongoier
cc: @re-xyr
I think we should make Expr(True/False)
return i32
and then inform user of their difference from using 0
and 1
directly (which returns default_ip
). Are there any cases where we must use 0/1 instead of True/False?
Many people use if x
to determine whether x
is zero or not, x
can be any integer. It's weird only i32 works while i64 doesn't.
Boolean values being i32
is a workaround; we will make it proper i1
in the future. In the meantime I think we'd better keep enforcing one single type for conditionals; using if x
to see whether x
is zero is not good software engineering practice anyway, and we've advised users to write if x != 0
in the error message.