import taichi as ti
ti.init(arch=ti.gpu)
volCompliance = ti.field(dtype=ti.f32, shape=())
volCompliance[None] = 0.0
numTets = ti.field(dtype=ti.int32, shape=())
numTets[None] = int(1)
volIdOrder = ti.Vector.field(3, dtype=ti.i32, shape=4)
volIdOrder[0] = [1, 3, 2]
volIdOrder[1] = [0, 2, 3]
volIdOrder[2] = [0, 3, 1]
volIdOrder[3] = [0, 1, 2]
tetIds = ti.Vector.field(4, dtype=ti.i32, shape=1)
tetIds[0] = [0, 1, 2, 3]
print(volIdOrder[0][0])
@ti.func
def forArr(x: ti.i32, y: ti.i32) -> ti.i32:
value = tetIds[x][y]
return value
@ti.func
def solveVolumes(compliance: ti.f32, dt: ti.f32):
alpha = compliance / dt / dt
for i in range(numTets[None]): # self.numTets[None]
w = 0.0
for j in ti.static(range(4)):
# print(value)
arr = tetIds[i][volIdOrder[j][0]] # [volIdOrder[j][0]]
print(arr, '****')
@ti.kernel
def solve(dt: ti.f32):
solveVolumes(volCompliance[None], dt)
solve(0.006)
Traceback (most recent call last):
File "H:\PythonCodes\taichi_threeMesh\errorData.py", line 41, in <module>
solve(0.006)
File "H:\PythonCodes\taichi_threeMesh\venv\lib\site-packages\taichi\lang\kernel_impl.py", line 769, in wrapped
raise type(e)('\n' + str(e)) from None
taichi.lang.exception.TaichiSyntaxError:
On line 38 of file "H:\PythonCodes\taichi_threeMesh\errorData.py", in solve:
solveVolumes(volCompliance[None], dt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
On line 32 of file "H:\PythonCodes\taichi_threeMesh\errorData.py", in solveVolumes:
arr = tetIds[i][volIdOrder[j][0]] # [volIdOrder[j][0]]
^^^^^^^^^^^^^^^^^^^^^^^^^^^
The 0-th index of a Matrix/Vector must be a compile-time constant integer, got <class 'taichi.lang.expr.Expr'>.
This is because matrix operations will be **unrolled** at compile-time for performance reason.
If you want to *iterate through matrix elements*, use a static range:
for i in ti.static(range(3)):
print(i, "-th component is", vec[i])
def vec_read(A: ti.template(), i):
ret = A[0]
for ii in ti.static(range(A.n)):
if i == ii:
ret = A[ii]
return ret
def vec_write(A: ti.template(), i, val):
for ii in ti.static(range(A.n)):
if i == ii:
A[ii] = val
arr = vec_read(tetIds[i], volIdOrder[j][0])