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

Reassign of vector/variable with different types #4678

Closed
xuhao1 opened this issue Mar 30, 2022 · 1 comment · Fixed by #4843
Closed

Reassign of vector/variable with different types #4678

xuhao1 opened this issue Mar 30, 2022 · 1 comment · Fixed by #4843
Labels
potential bug Something that looks like a bug but not yet confirmed
Milestone

Comments

@xuhao1
Copy link

xuhao1 commented Mar 30, 2022

Describe the bug
When reassigning a variable/vector with a different type, the original type does not change, this may lead to confusion as people are easier to think taichi works similar to python (but not C)

To Reproduce

import taichi as ti
@ti.kernel
def test_kernel2():
    p0 = ti.Vector([1, 2, 3], ti.i32)
    p1 = ti.Vector([8, 6, 4], ti.i32)
    print(p0)
    mu = 0.5
    p = p0
    p = p0 + mu*(p1-p0)
    print("interlop", p)
    p = ti.Vector([1.4, 2.4, 3.2], ti.f32)
    print("reassign", p)

    a = 1
    print(a)
    a = 1.5
    print(a)
ti.init(arch=ti.cpu)
test_kernel2()

Log/Screenshots

➜  TaichiSLAM git:(main) ✗ python tests/test.py
[Taichi] version 0.9.3, llvm 10.0.0, commit c902db62, linux, python 3.8.10
[Taichi] Starting on arch=x64
[W 03/30/22 22:38:51.391 3010] [type_check.cpp:visit@145] [$183] Local store may lose precision (target = i32, value = f32), at
183
[W 03/30/22 22:38:51.391 3010] [type_check.cpp:visit@145] [$185] Local store may lose precision (target = i32, value = f32), at
185
[W 03/30/22 22:38:51.391 3010] [type_check.cpp:visit@145] [$187] Local store may lose precision (target = i32, value = f32), at
187
[W 03/30/22 22:38:51.391 3010] [type_check.cpp:visit@145] [$202] Local store may lose precision (target = i32, value = f32), at
202
[W 03/30/22 22:38:51.391 3010] [type_check.cpp:visit@145] [$204] Local store may lose precision (target = i32, value = f32), at
204
[W 03/30/22 22:38:51.391 3010] [type_check.cpp:visit@145] [$206] Local store may lose precision (target = i32, value = f32), at
206
[W 03/30/22 22:38:51.391 3010] [type_check.cpp:visit@145] [$217] Local store may lose precision (target = i32, value = f32), at
217
[1, 2, 3]
interlop [4, 4, 3]
reassign to float [1, 2, 3]
1
1.5 1

Additional comments
My suggestion is to either of:

  • Gives a clear warning or error indication that the line has Implicit converting. now we can't find which line the error is on.
  • Convert lvalue to the type of rvalue (like Python)
@xuhao1 xuhao1 added the potential bug Something that looks like a bug but not yet confirmed label Mar 30, 2022
@strongoier
Copy link
Contributor

Thanks for your suggestion! Taichi is a statically-typed language, so option 1 is preferred. #4840 makes source code info available in warnings. Your code snippet illustrates another bug in type check for local stores, and I will send another PR to fix that.

@strongoier strongoier moved this to Untriaged in Taichi Lang Apr 22, 2022
@strongoier strongoier moved this from Untriaged to In Progress in Taichi Lang Apr 22, 2022
@strongoier strongoier added this to the Taichi v1.0.1 milestone Apr 22, 2022
Repository owner moved this from In Progress to Done in Taichi Lang Apr 22, 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.

2 participants