Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default_ip=ti.i64 doesn't work with if #5675

Closed
lin-hitonami opened this issue Aug 8, 2022 · 5 comments · Fixed by #5763
Closed

default_ip=ti.i64 doesn't work with if #5675

lin-hitonami opened this issue Aug 8, 2022 · 5 comments · Fixed by #5763
Assignees
Labels
potential bug Something that looks like a bug but not yet confirmed

Comments

@lin-hitonami
Copy link
Contributor

To Reproduce

import taichi as ti
ti.init(default_ip=ti.i64)

@ti.kernel
def test_kernel():
    stop = 0
    if stop:
        stop = 1

test_kernel()

Log/Screenshots

[Taichi] version 1.0.5, llvm 10.0.0, commit 40712d7d, linux, python 3.9.12
[Taichi] Starting on arch=x64
Traceback (most recent call last):
  File "/home/lin/test/yu.py", line 10, in <module>
    test_kernel()
  File "/home/lin/taichi/python/taichi/lang/kernel_impl.py", line 926, in wrapped
    raise type(e)('\n' + str(e)) from None
taichi.lang.exception.TaichiTypeError: 
`if` conditions must be of type i32; found i64. Consider using `if x != 0` instead of `if x` for float values.
@lin-hitonami lin-hitonami added the potential bug Something that looks like a bug but not yet confirmed label Aug 8, 2022
@taichi-gardener taichi-gardener moved this to Untriaged in Taichi Lang Aug 8, 2022
@lin-hitonami
Copy link
Contributor Author

maybe @strongoier

@strongoier
Copy link
Contributor

cc: @re-xyr

@re-xyr
Copy link
Contributor

re-xyr commented Aug 8, 2022

I think we should make Expr(True/False) return i32 and then inform user of their difference from using 0 and 1 directly (which returns default_ip). Are there any cases where we must use 0/1 instead of True/False?

@lin-hitonami
Copy link
Contributor Author

lin-hitonami commented Aug 8, 2022

Many people use if x to determine whether x is zero or not, x can be any integer. It's weird only i32 works while i64 doesn't.

@re-xyr
Copy link
Contributor

re-xyr commented Aug 8, 2022

Boolean values being i32 is a workaround; we will make it proper i1 in the future. In the meantime I think we'd better keep enforcing one single type for conditionals; using if x to see whether x is zero is not good software engineering practice anyway, and we've advised users to write if x != 0 in the error message.

@qiao-bo qiao-bo moved this from Untriaged to In Progress in Taichi Lang Aug 12, 2022
Repository owner moved this from In Progress to Done in Taichi Lang Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential bug Something that looks like a bug but not yet confirmed
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants