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

[Lang] Add warning message when converting dynamic snode to numpy #6853

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions python/taichi/lang/field.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import taichi.lang
from taichi._lib import core as _ti_core
from taichi._logging import warn
from taichi.lang import impl
from taichi.lang.exception import TaichiSyntaxError
from taichi.lang.util import (in_python_scope, python_scope, to_numpy_type,
Expand Down Expand Up @@ -289,6 +290,10 @@ def fill(self, val):
def to_numpy(self, dtype=None):
"""Converts this field to a `numpy.ndarray`.
"""
if self.parent()._snode.ptr.type == _ti_core.SNodeType.dynamic:
warn(
"You are trying to convert a dynamic snode to a numpy array, be aware that inactive items in the snode will be converted to zeros in the resulting array."
)
if dtype is None:
dtype = to_numpy_type(self.dtype)
import numpy as np # pylint: disable=C0415
Expand Down