Skip to content
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

For dynamic snodes, calling to_numpy() results a whole array padded with zeros, not the actual length #6841

Closed
neozhaoliang opened this issue Dec 8, 2022 · 1 comment · Fixed by #6853
Assignees

Comments

@neozhaoliang
Copy link
Contributor

neozhaoliang commented Dec 8, 2022

Let's say we have an empty dynamic snode like this:

import taichi as ti
ti.init(arch=ti.cpu)
x = ti.field(int)
ti.root.dynamic(ti.i, 1024, chunk_size=32).place(x)

@ti.kernel
def test():
    print(x.length())  #0

arr = x.to_numpy()  # array of size 1024

This behavior may cause problems, for example, using arr to draw gui.circle or gui.lines will give false results at the origin.
We should make the returned array have the same size with the actual length of the dynamic snode.

@taichi-gardener taichi-gardener moved this to Untriaged in Taichi Lang Dec 8, 2022
@neozhaoliang neozhaoliang changed the title Dynamic snode to_numpy() results a whole array padded with zeros, not the actual length For dynamic snodes, calling to_numpy() results a whole array padded with zeros, not the actual length Dec 8, 2022
@turbo0628 turbo0628 moved this from Untriaged to Todo in Taichi Lang Dec 9, 2022
@neozhaoliang
Copy link
Contributor Author

neozhaoliang commented Dec 9, 2022

This might be difficult to solve in the python frontend. Since to_numpy must be called in the python scope, and we cannot know the actual length of a dynamic snode in the python scope. Also, we cannot define a suitable depth for the numpy array if the dynamic snode is a multidimensional array. For a workaround, we should better raise a warning message here.

neozhaoliang added a commit that referenced this issue Dec 14, 2022
)

This PR adds a warning message when the user tries to call the
`to_numpy` method of a dynamic snode.

close: #6841

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Repository owner moved this from Todo to Done in Taichi Lang Dec 14, 2022
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
…ichi-dev#6853)

This PR adds a warning message when the user tries to call the
`to_numpy` method of a dynamic snode.

close: taichi-dev#6841

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant