Concisely describe the proposed feature
It seems that we can automatically cast range into int32?
import taichi as ti
@ti.kernel
def func():
n = 2.6 # float!!!
for i in range(n): # range(f32) = range(int(f32))
print(i)
func()
```
[Taichi] mode=release
[Taichi] version 0.6.14, llvm 10.0.0, commit c83a7e3d, python 3.8.3
0
1
It's really useful! ...according to my experience in working with Taichi THREE.
But would it also be great to **automatically cast tensor index into int32**? e.g., the GAMES 201 advocated example:
```py
@ti.kernel
def semi_lagragian():
for pos in ti.grouped(img):
bt_pos = pos * dx - vel[pos] # now bt_pos is vector of float32!
new_img[pos] = img[int(round(bt_pos / dx))] # we have to convert `int` since round returns float32!
See? It would be useful to simply cast all indices into int32.
Describe the solution you'd like (if any)
Either in python/lang/transform.py or impl.subscript, add a expr_group.cast(ti.i32).
Additional comments
Or we may give a warning when non-int range/index is used?
Or we may give a warning when non-int range/index is used?
I actually think this is better. We'd better not make the system too smart. Explicit is better than implicit.
SGTM, let's give a warning for both them but not crash, so that user can rid these warning when they're final-polishing their program and seek possible bugs.
Most helpful comment
SGTM, let's give a warning for both them but not crash, so that user can rid these warning when they're final-polishing their program and seek possible bugs.