[RFC] Syntax sugar: v = [1, 2, 3] instead of v = ti.Vector([1, 2, 3]) ? #3877
Replies: 4 comments 2 replies
-
The first syntax ( By the way, we can make |
Beta Was this translation helpful? Give feedback.
-
Agreed on the verbosity issue. I think We can further think about how to deal with arithmetic, especially if we'd like to support a pure-Python mode. Today when I was porting Taichi kernels back to Python, I had to replace all Finally, I think we can look into Python Array API, and make Taichi's tensors (or fields?) as much API-compatible as possible |
Beta Was this translation helpful? Give feedback.
-
We should be careful of the types and not rely as heavily on type inference as it might be prone to user mistakes. A user forget to add |
Beta Was this translation helpful? Give feedback.
-
Sorry I forgot to add our conclusion here: This syntax sugar could prevent the support for local array. And users might actually assume If our type system is more robust, I think we can have this slightly more cumbersome way to define a vector: v3f = ti.Vector(dtype=ti.f32, n=3)
@ti.kernel
def foo():
v: v3f = [1.0, 2.0, 3.0]
v2 = v3f([1, 2, 3]) See #4230 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It seems that the writing
v = ti.Vector([1, 2, 3])
is too verbose for creating a vector in Taichi kernels. It might make sense to create a vector simply use a syntax likev = [1, 2, 3]
orv = {1, 2, 3}
. Similar syntax sugars apply to matrices.Note that we already support a similar syntax when writing to a field:
taichi/python/taichi/examples/simulation/mpm99.py
Line 31 in 0a7a7c4
Making this work for vector/matrix creation may simplify programs. WDYT?
Beta Was this translation helpful? Give feedback.
All reactions