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 cast to field.fill() interface #7899

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions python/taichi/_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

# A set of helper (meta)functions
@kernel
def fill_tensor(tensor: template(), val: template()):
for I in grouped(tensor):
tensor[I] = val
def fill_field(field: template(), val: template()):
value = ops.cast(val, field.dtype)
neozhaoliang marked this conversation as resolved.
Show resolved Hide resolved
for I in grouped(field):
field[I] = value


@kernel
Expand Down
4 changes: 2 additions & 2 deletions python/taichi/lang/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ def __init__(self, var):
def fill(self, val):
"""Fills this scalar field with a specified value."""
if in_python_scope():
from taichi._kernels import fill_tensor # pylint: disable=C0415
from taichi._kernels import fill_field # pylint: disable=C0415

fill_tensor(self, val)
fill_field(self, val)
else:
from taichi._funcs import field_fill_taichi_scope # pylint: disable=C0415

Expand Down