Taichi: [Lang] Confusing behavior when functions have multiple returns

Created on 5 Sep 2020  路  4Comments  路  Source: taichi-dev/taichi

Describe the bug
When using the all(stmt) judgment in taichi scope and the result is False, the function seems to stop unexpectedly. Please see the screenshots and code below.

To Reproduce

import taichi as ti

@ti.func
def is_in_bound(vec: ti.template(), AABB_min: ti.template(), AABB_max: ti.template()):
    if all(AABB_min <= vec) and all(vec <= AABB_max):
        print('all judge is True')
        return 1
    else:
        print('all judge is False')
        return 0

@ti.kernel
def test():
    x_inside = ti.Vector([0.5, 0.5, 2.5])
    x_outside = ti.Vector([0.5, 0.5, 3.5])
    AABB_min = ti.Vector([0, 0, 0])
    AABB_max = ti.Vector([1, 2, 3])
    print('test inside point', is_in_bound(x_inside, AABB_min, AABB_max))
    print('---')
    print('test outside point', is_in_bound(x_outside, AABB_min, AABB_max))

test()

Log
image

potential bug welcome contribution

All 4 comments

The problem is concerning multiple returns. Thankx~~~but you may find it useful to give out a warning here.

image

Thanks for reporting! The frontend compiler should generate a SyntaxError in this case. If anyone is interested in implement this, please go ahead. Thanks!

In fact we have two solutions:

  1. Give out an SyntaxError or warning in this case.
  2. Support multiple return in functions ultimately.

If 2 is easy, we'd better go for 2 directly, WDYT?

Thanks for the proposals! I suggest we go 1 at this moment. Solution 2 is likely not easy - that needs us to somehow implement real functions (instead of inlined ones).

Was this page helpful?
0 / 5 - 0 ratings