Proposal of defining types and constructing objects in a more consistent way #4183
strongoier
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
@strongoier I added a small use case, do we agree on this API? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, there are two common ways in Taichi to construct a vector:
They diverge in many aspects, and users can easily get confused. I think it is time for a unification.
Similar to discussions in #4085, we can consider
ti.types.vector
as a type with two template parameters (n
anddtype
). We need to first specialize it with 0, 1, or 2 of these parameters, and use the specialized type to construct an actual object:With type inference, each of
c, d, e, f
should be of the same typevector<3, i32>
. Then we can maketi.Vector([0, 0, 0])
simply as a shortcut forti.types.vector()([0, 0, 0])
in order to keep the old yet sweet API unchanged.In this way, all these things get linked together.
A remaining issue lies in the different use of lower/upper cases.
I suggest to consistently use the lower case (
ti.vector
,ti.types.vector
) throughout the API, which is also consistent withfield
andndarray
. To avoid breaking existing user code immediately, we can markti.Vector
as deprecated starting from a much later release in v1.x and remove it from v2.0.To summarize the current situation, we will have these APIs under the
ti.types
package for parameter type annotation...ti.types.vector
,ti.types.matrix
ti.types.struct
ti.types.ndarray
... and these APIs under the top-level
ti
package for constructing the instances:ti.vector
(andti.Vector
for legacy reason),ti.matrix
(andti.Matrix
for legacy reason)ti.struct
ti.ndarray
ti.field
Usage:
Beta Was this translation helpful? Give feedback.
All reactions