-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Lang] [refactor] Add Field classes for ti.field/ti.Vector.field/ti.Matrix.field #2638
Conversation
/format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Could you briefly write up what's been added/refactored to ease the review process? An excellent example is #2495 (which is not that "brief"...)
Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the huge efforts!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! This will make #2627 much clearer than what it is now. It will also facilitate the implementation of recursive custom structs.
/format |
P.S. It looks like taichi_glsl defines extensions of the current Matrix/Expr classes. I'm not sure if the package will still be fully functional after the changes are merged. |
Thanks for catching this! Let's get this in first to move other things forward :-) |
Related issue = close #2499
Previously, a
ti.field
is aExpr
withis_global()=True
, while ati.Matrix.field
is aMatrix
withis_global()=True
. This is not intuitive. After this PR,ti.field
will become aScalarField
, andti.Matrix.field
will become aMatrixField
, which both inherit from a super classField
.The
Field
class keeps the original implementation way of using SNodes. A field is constructed by a list of field members. For example, a scalar field has 1 field member, while a 3x3 matrix field has 9 field members. A field member is a PythonExpr
wrapping a C++GlobalVariableExpression
. A C++GlobalVariableExpression
wraps the corresponding SNode.All methods belonging to
ti.field
/ti.Matrix.field
have been migrated fromExpr
/Matrix
classes toScalarField
/MatrixField
classes. If a method is implemented exactly the same in both classes, it will be put intoField
class. Otherwise common methods will be marked asNotImplemented
inField
class to avoid misuse.During migration, the property methods and meta (fill, to/from numpy/torch, copy) methods are mainly kept the same with slight cleaning in both implementation and docstrings. The biggest change is around subscript (both in Python scope and Taichi scope) - the main idea is that for
MatrixField
, after first subscript with coordinates, we should get aMatrix
, where each element is under the same state as if we are accessing a correspondingScalarField
. It acts just like aMatrix
so no moreProxy
classes are needed. By the way,Matrix.with_entries()
is just added for this purpose.Note:
x
is a field with 0-D shape, although deprecated, it can still be accessed viax
instead ofx[None]
. After this PR this invalid behavior will not work any more.