forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lang] [type] Add bool type in python as an alias to i32 (taichi-dev#…
…6742) Issue: taichi-dev#577 taichi-dev#6036 ### Brief Summary This PR adds `bool` as an alias to `ti.i32`. Specifically, - `x: bool` is equivalent to `x: i32` - `-> bool` is equivalent to `-> i32` - `bool(x)` is equivalent to `ti.cast(x, i32)`. This is a temporary solution while we work towards a standalone bool type. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
924403d
commit 7904eed
Showing
6 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import taichi as ti | ||
from tests import test_utils | ||
|
||
|
||
@test_utils.test(debug=True) | ||
def test_bool_type_anno(): | ||
@ti.func | ||
def f(x: bool) -> bool: | ||
return not x | ||
|
||
@ti.kernel | ||
def test(): | ||
assert f(True) == False | ||
assert f(False) == True | ||
|
||
test() | ||
|
||
|
||
@test_utils.test(debug=True) | ||
def test_bool_type_conv(): | ||
@ti.func | ||
def f(x: ti.u32) -> bool: | ||
return bool(x) | ||
|
||
@ti.kernel | ||
def test(): | ||
assert f(1000) == 1000 | ||
assert f(ti.u32(4_294_967_295)) == -1 | ||
|
||
test() |