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

[ir] ti.func parameter types are not casted #7946

Closed
bobcao3 opened this issue May 7, 2023 · 0 comments · Fixed by #8193
Closed

[ir] ti.func parameter types are not casted #7946

bobcao3 opened this issue May 7, 2023 · 0 comments · Fixed by #8193
Assignees
Labels
bug We've confirmed that this is an BUG ir IR related issues

Comments

@bobcao3
Copy link
Collaborator

bobcao3 commented May 7, 2023

Repro:

import taichi as ti

ti.init()

field = ti.field(dtype=ti.f32, shape=(50))
index = ti.field(dtype=ti.i16, shape=())

@ti.func
def get_data(idx : ti.i32):
    return field[idx]

@ti.kernel
def run() -> ti.f32:
    return get_data(index[None])

run()

This emits warning:

[W 05/06/23 17:30:22.109 12880] [type_check.cpp:taichi::lang::TypeCheck::visit@154] [$11] Field index 0 not int32, casting into int32 implicitly
File "C:\Users\bobca\source\repos\meshy\repro0.py", line 10, in get_data:
    return field[idx]
           ^^^^^^^^^^

I'd expect if I declare function parameter as ti.i32, when I'm calling the function argument should be passed by value and casted to i32, it seems it stayed as i16.

@bobcao3 bobcao3 added bug We've confirmed that this is an BUG ir IR related issues labels May 7, 2023
@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang May 7, 2023
@feisuzhu feisuzhu moved this from Untriaged to Todo in Taichi Lang May 12, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in Taichi Lang Jun 16, 2023
lin-hitonami added a commit that referenced this issue Jun 16, 2023
…type hints exist (#8193)

Issue: fix #7946

### Brief Summary

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 6275116</samp>

This pull request implements automatic scalar casting for function
arguments and return values based on type annotations in Taichi. It also
adds two test cases in `test_argument.py` and `test_return.py` to verify
the feature.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at 6275116</samp>

* Add automatic scalar casting for function arguments and return values
([link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-3e22417ffade4af0564893b98dc5101d714b8ba6fd4423ab5bc5129e360fee8fR740-R744),
[link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-3e22417ffade4af0564893b98dc5101d714b8ba6fd4423ab5bc5129e360fee8fR863-R864))
* Add test cases for scalar argument and return value casting
([link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87R264-R276),
[link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8R251-R263))
L2ncE pushed a commit to L2ncE/taichi that referenced this issue Jun 20, 2023
…type hints exist (taichi-dev#8193)

Issue: fix taichi-dev#7946

### Brief Summary

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 6275116</samp>

This pull request implements automatic scalar casting for function
arguments and return values based on type annotations in Taichi. It also
adds two test cases in `test_argument.py` and `test_return.py` to verify
the feature.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at 6275116</samp>

* Add automatic scalar casting for function arguments and return values
([link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-3e22417ffade4af0564893b98dc5101d714b8ba6fd4423ab5bc5129e360fee8fR740-R744),
[link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-3e22417ffade4af0564893b98dc5101d714b8ba6fd4423ab5bc5129e360fee8fR863-R864))
* Add test cases for scalar argument and return value casting
([link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87R264-R276),
[link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8R251-R263))
PGZXB pushed a commit to PGZXB/taichi that referenced this issue Jul 13, 2023
…type hints exist (taichi-dev#8193)

Issue: fix taichi-dev#7946

### Brief Summary

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 6275116</samp>

This pull request implements automatic scalar casting for function
arguments and return values based on type annotations in Taichi. It also
adds two test cases in `test_argument.py` and `test_return.py` to verify
the feature.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at 6275116</samp>

* Add automatic scalar casting for function arguments and return values
([link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-3e22417ffade4af0564893b98dc5101d714b8ba6fd4423ab5bc5129e360fee8fR740-R744),
[link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-3e22417ffade4af0564893b98dc5101d714b8ba6fd4423ab5bc5129e360fee8fR863-R864))
* Add test cases for scalar argument and return value casting
([link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87R264-R276),
[link](https://github.com/taichi-dev/taichi/pull/8193/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8R251-R263))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug We've confirmed that this is an BUG ir IR related issues
Projects
Status: Done
3 participants