taichi
taichi copied to clipboard
Do not the Kernel arguments support the class 'bool'?
When I set the type-hinted of my Kernel arguments as 'bool', there existed an error:
TaichiSyntaxError: Invalid type annotation (argument 0) of Taichi kernel: <class 'bool'>
So, do not the Kernel arguments support the class 'bool'?
Thanks for the issue.
Currently bool
type is not (explicitly) one of the primitive types in Taichi. There is a u1
type, which is used as bool
. A workaround is to use int
(or other integer types) to mimic its behavior.
@strongoier I noticed that the u1
type is defined in C++ but not exposed to the Python frontend (used in export_lang.cpp
but not referenced in primitive_types.py
). Should we use it when encountering the bool
type during compilation?
u1
type has not been fully supported yet (https://github.com/taichi-dev/taichi/issues/577), and we plan to support it in the future. For now we need to use int
as a workaround.
As a first step towards adding the proper bool type, we're going to add bool
as an alias of i32
.
Specifically:
-
x: bool
is equivalent tox: i32
-
-> bool
is equivalent to-> i32
-
bool(x)
is equivalent toti.cast(x, i32)
.
This is only a temporary workaround as we work on a more permanent solution.