taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.05k stars 2.26k forks source link

Incorrct matrix multiplication : same value different type get different result #8503

Open thematteroftime opened 3 months ago

thematteroftime commented 3 months ago

Describe the bug same matrix multiply same value with different type, one is int the other is float, but get different result

To Reproduce

import taichi as ti

arch = ti.cpu
ti.init(arch=arch)
n = 4
K = ti.linalg.SparseMatrixBuilder(n, n, max_num_triplets=100)

@ti.kernel
def fill(A: ti.types.sparse_matrix_builder()):
    for i in range(n):
        A[i, i] += 1

fill(K)
K.print_triplets()
A = K.build()

print("----------------")
print(A * 3)
print("----------------")
print(A * 3.0)

Log/Screenshots

$ python my_sample_code.py
[Taichi] version 1.7.0, llvm 15.0.1, commit 2fd24490, win, python 3.9.18
[Taichi] Starting on arch=x64
n=4, m=4, num_triplets=4 (max=100)
[0, 0] = 1.0
[1, 1] = 1.0
[2, 2] = 1.0
[3, 3] = 1.0
----------------
None
----------------
[3, 0, 0, 0]
[0, 3, 0, 0]
[0, 0, 3, 0]
[0, 0, 0, 3]
...

hope this issue will be fixed well Thank you