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

Do not the Kernel arguments support the class 'bool'? #6036

Open
17150934 opened this issue Sep 11, 2022 · 3 comments
Open

Do not the Kernel arguments support the class 'bool'? #6036

17150934 opened this issue Sep 11, 2022 · 3 comments
Assignees
Labels
question Question on using Taichi

Comments

@17150934
Copy link

When I set the type-hinted of my Kernel arguments as 'bool', there existed an error:
TaichiSyntaxError: Invalid type annotation (argument 0) of Taichi kernel: <class 'bool'>
So, do not the Kernel arguments support the class 'bool'?

@17150934 17150934 added the question Question on using Taichi label Sep 11, 2022
@taichi-gardener taichi-gardener moved this to Untriaged in Taichi Lang Sep 11, 2022
@AD1024
Copy link
Contributor

AD1024 commented Sep 12, 2022

Thanks for the issue.
Currently bool type is not (explicitly) one of the primitive types in Taichi. There is a u1 type, which is used as bool. A workaround is to use int (or other integer types) to mimic its behavior.

@strongoier I noticed that the u1 type is defined in C++ but not exposed to the Python frontend (used in export_lang.cpp but not referenced in primitive_types.py). Should we use it when encountering the bool type during compilation?

@strongoier
Copy link
Contributor

u1 type has not been fully supported yet (#577), and we plan to support it in the future. For now we need to use int as a workaround.

@ailzhang ailzhang moved this from Untriaged to Todo in Taichi Lang Sep 16, 2022
@re-xyr
Copy link
Contributor

re-xyr commented Nov 26, 2022

As a first step towards adding the proper bool type, we're going to add bool as an alias of i32.

Specifically:

  • x: bool is equivalent to x: i32
  • -> bool is equivalent to -> i32
  • bool(x) is equivalent to ti.cast(x, i32).

This is only a temporary workaround as we work on a more permanent solution.

strongoier pushed a commit that referenced this issue Dec 3, 2022
Issue: #577 #6036

### Brief Summary

This PR adds `bool` as an alias to `ti.i32`. Specifically,

- `x: bool` is equivalent to `x: i32`
- `-> bool` is equivalent to `-> i32`
- `bool(x)` is equivalent to `ti.cast(x, i32)`.

This is a temporary solution while we work towards a standalone bool
type.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
…6742)

Issue: taichi-dev#577 taichi-dev#6036

### Brief Summary

This PR adds `bool` as an alias to `ti.i32`. Specifically,

- `x: bool` is equivalent to `x: i32`
- `-> bool` is equivalent to `-> i32`
- `bool(x)` is equivalent to `ti.cast(x, i32)`.

This is a temporary solution while we work towards a standalone bool
type.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question on using Taichi
Projects
Status: Todo
Development

No branches or pull requests

4 participants