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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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.vectoras a type with two template parameters (nanddtype). 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, fshould 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 withfieldandndarray. To avoid breaking existing user code immediately, we can markti.Vectoras 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.typespackage for parameter type annotation...ti.types.vector,ti.types.matrixti.types.structti.types.ndarray... and these APIs under the top-level
tipackage for constructing the instances:ti.vector(andti.Vectorfor legacy reason),ti.matrix(andti.Matrixfor legacy reason)ti.structti.ndarrayti.fieldUsage:
Beta Was this translation helpful? Give feedback.
All reactions