-
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] Add ti.Vector.ndarray and ti.Matrix.ndarray #2808
Conversation
/format |
/format |
python/taichi/lang/ndarray.py
Outdated
"""Class for accessing VectorNdarray/MatrixNdarray in Python scope. | ||
Args: | ||
arr (Union[VectorNdarray, MatrixNdarray]): See above. | ||
indices_first (Tuple[Int]): Indices of first-level access. |
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.
What are first level and second level?
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.
First level refers to coordinates in the field, while second level refers to indices inside the vector/matrix. Maybe I should make it clearer?
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.
Using first/second is to tell users this is what they write in the first/second pair of brackets.
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.
Explanations are added.
@@ -57,8 +58,25 @@ def __init__(self, element_shape=(), layout=Layout.AOS): | |||
self.layout = layout | |||
|
|||
def extract(self, x): | |||
shape = tuple(x.shape) | |||
from taichi.lang.matrix import MatrixNdarray, VectorNdarray |
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.
move to top? (or will it cause circular import?)
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.
It will cause circular import :-(
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!
assert v[4][9] == 9 | ||
|
||
|
||
# number of compiled functions |
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.
is this comment not longer needed?
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.
It's used to separate three different parts of tests of this file.
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!
Related issue = #2771
This PR adds
ti.Vector.ndarray
andti.Matrix.ndarray
, which support Python-scope and Taichi-scope access. When passing them into kernels, we need to useti.any_arr()
annotation withelement_shape
and optionallayout
(default value:ti.Layout.AOS
) to enforce type consistency.