From 7ac1e3df86f90e8301fe200068c54efd665fef19 Mon Sep 17 00:00:00 2001 From: jim19930609 Date: Wed, 26 Apr 2023 14:24:50 +0800 Subject: [PATCH 1/2] [Lang] Add cast to field.fill() interface --- python/taichi/_kernels.py | 7 ++++--- python/taichi/lang/field.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/python/taichi/_kernels.py b/python/taichi/_kernels.py index 2ba84da6dec70..4fece1e7b962a 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()): + tmp = ops.cast(val, field.dtype) + for I in grouped(field): + field[I] = tmp @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 From 9f074777186ede0c362a52ce85ca1ee4f8e3bccc Mon Sep 17 00:00:00 2001 From: jim19930609 Date: Wed, 26 Apr 2023 14:27:51 +0800 Subject: [PATCH 2/2] adjustment --- python/taichi/_kernels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/taichi/_kernels.py b/python/taichi/_kernels.py index 4fece1e7b962a..69664fed0d8e8 100644 --- a/python/taichi/_kernels.py +++ b/python/taichi/_kernels.py @@ -20,9 +20,9 @@ # A set of helper (meta)functions @kernel def fill_field(field: template(), val: template()): - tmp = ops.cast(val, field.dtype) + value = ops.cast(val, field.dtype) for I in grouped(field): - field[I] = tmp + field[I] = value @kernel