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] add option
short_circuit_operators
for shor-circuiting boole…
…an ops (taichi-dev#3572)
- Loading branch information
Showing
3 changed files
with
112 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import taichi as ti | ||
|
||
|
||
@ti.test(debug=True, short_circuit_operators=True) | ||
def test_and_shorted(): | ||
a = ti.field(ti.i32, shape=10) | ||
|
||
@ti.func | ||
def explode() -> ti.i32: | ||
return a[-1] | ||
|
||
@ti.kernel | ||
def func() -> ti.i32: | ||
return False and explode() | ||
|
||
assert func() == 0 | ||
|
||
|
||
@ti.test(debug=True, short_circuit_operators=True) | ||
def test_and_not_shorted(): | ||
@ti.kernel | ||
def func() -> ti.i32: | ||
return True and False | ||
|
||
assert func() == 0 | ||
|
||
|
||
@ti.test(debug=True, short_circuit_operators=True) | ||
def test_or_shorted(): | ||
a = ti.field(ti.i32, shape=10) | ||
|
||
@ti.func | ||
def explode() -> ti.i32: | ||
return a[-1] | ||
|
||
@ti.kernel | ||
def func() -> ti.i32: | ||
return True or explode() | ||
|
||
assert func() == 1 | ||
|
||
|
||
@ti.test(debug=True, short_circuit_operators=True) | ||
def test_or_not_shorted(): | ||
@ti.kernel | ||
def func() -> ti.i32: | ||
return False or True | ||
|
||
assert func() == 1 |