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

[bug] TensorType arithmetic gives wrong results #7258

Closed
turbo0628 opened this issue Jan 30, 2023 · 0 comments · Fixed by #7526
Closed

[bug] TensorType arithmetic gives wrong results #7258

turbo0628 opened this issue Jan 30, 2023 · 0 comments · Fixed by #7526
Assignees
Milestone

Comments

@turbo0628
Copy link
Member

turbo0628 commented Jan 30, 2023

As a follow-up of #7061, I found some vector arithmetics gave me wrong numerical results:

import taichi as ti

ti.init(arch=ti.cuda, print_kernel_llvm_ir_optimized=True, print_ir=True, real_matrix_scalarize=False)

f = ti.ndarray(ti.math.vec4, 4)

@ti.kernel
def fill(arr: ti.types.ndarray()):
    v0 = ti.math.vec4([0.0, 1.0, 2.0, 3.0])
    v1 = ti.math.vec4([1.0, 2.0, 3.0, 4.0])
    v2 = ti.math.vec4([2.0, 3.0, 4.0, 5.0])
    v3 = ti.math.vec4([4.0, 5.0, 6.0, 7.0])
    arr[0] = v0
    arr[1] = v1
    arr[2] = v2
    arr[3] = v3

@ti.kernel
def vec_test(arr : ti.types.ndarray()):
    v0 = arr[0]
    v1 = arr[1]
    v2 = arr[2]
    v3 = arr[3]

    arr[0] = v0 * v1 + v2
    arr[1] = v1 * v2 + v3
    arr[2] = v0 * v2 + v3

fill(f)
vec_test(f)
print(f.to_numpy())

Screen output was

[[ 2.  6.  4.  9.]
 [16. 31.  7.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]

Which is apparently unexpected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants