Skip to content

Commit

Permalink
[test] Add test for recursive real function
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-hitonami committed Mar 8, 2022
1 parent 159895c commit d1e92f2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/python/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,25 @@ def run():
add(30, 2)

run()


@test_utils.test(arch=[ti.cpu, ti.gpu], cfg_optimization=False)
def test_recursion():
@ti.experimental.real_func
def sum(f: ti.template(), l: ti.i32, r: ti.i32) -> ti.i32:
ret = 0
if l == r:
ret = f[l]
else:
ret = sum(f, l, (l + r) // 2) + sum(f, (l + r) // 2 + 1, r)
return ret

f = ti.field(ti.i32, shape=100)
for i in range(100):
f[i] = i

@ti.kernel
def get_sum() -> ti.i32:
return sum(f, 0, 99)

assert get_sum() == 99 * 50

0 comments on commit d1e92f2

Please sign in to comment.