SIGN IN SIGN UP
taichi-dev / taichi UNCLAIMED

Productive, portable, and performant GPU programming in Python.

2019-10-01 17:33:26 -04:00
import taichi as ti
from tests import test_utils
2019-08-16 21:23:58 -07:00
2020-03-18 21:30:23 -04:00
@test_utils.test()
2019-08-16 21:23:58 -07:00
def test_while():
x = ti.field(ti.f32)
2019-08-16 21:23:58 -07:00
2019-10-22 15:56:03 -04:00
N = 1
2019-08-16 21:23:58 -07:00
ti.root.dense(ti.i, N).place(x)
2019-08-16 21:23:58 -07:00
2019-10-22 15:56:03 -04:00
@ti.kernel
def func():
i = 0
s = 0
while i < 10:
s += i
i += 1
x[0] = s
func()
assert x[0] == 45
2019-12-16 17:45:36 -05:00
@test_utils.test()
2019-12-16 17:45:36 -05:00
def test_break():
ret = ti.field(ti.i32, shape=())
2020-03-18 21:30:23 -04:00
2019-12-16 17:45:36 -05:00
@ti.kernel
def func():
i = 0
s = 0
while True:
s += i
i += 1
if i > 10:
break
ret[None] = s
2020-03-18 21:30:23 -04:00
2019-12-16 17:45:36 -05:00
func()
2020-07-04 17:14:27 -04:00
assert ret[None] == 55