diff --git a/python/taichi/_kernels.py b/python/taichi/_kernels.py index 2ba84da6dec70..69664fed0d8e8 100644 --- a/python/taichi/_kernels.py +++ b/python/taichi/_kernels.py @@ -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) + for I in grouped(field): + field[I] = value @kernel diff --git a/python/taichi/lang/field.py b/python/taichi/lang/field.py index 40b31fcaf7acf..4c7c026450108 100644 --- a/python/taichi/lang/field.py +++ b/python/taichi/lang/field.py @@ -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