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

[error] Throw proper error message when an Ndarray is passed in via ti.template #5457

Merged
merged 1 commit into from
Jul 19, 2022
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
4 changes: 4 additions & 0 deletions python/taichi/lang/kernel_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ def extract_arg(arg, anno):
return tuple(
TaichiCallableTemplateMapper.extract_arg(item, anno)
for item in arg)
if isinstance(arg, taichi.lang._ndarray.Ndarray):
raise TaichiRuntimeTypeError(
'Ndarray shouldn\'t be passed in via `ti.template()`, please annotate your kernel using `ti.types.ndarray(...)` instead'
)
return arg
if isinstance(anno, texture_type.TextureType):
return '#'
Expand Down
14 changes: 14 additions & 0 deletions tests/python/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,17 @@ def func(a: ti.types.ndarray()):
for k in range(2):
for p in range(2):
assert a2[i, j][k, p] == k * k


@test_utils.test(arch=supported_archs_taichi_ndarray)
def test_ndarray_as_template():
@ti.kernel
def func(arr_src: ti.template(), arr_dst: ti.template()):
for i, j in ti.ndrange(*arr_src.shape):
arr_dst[i, j] = arr_src[i, j]

arr_0 = ti.ndarray(ti.f32, shape=(5, 10))
arr_1 = ti.ndarray(ti.f32, shape=(5, 10))
with pytest.raises(ti.TaichiRuntimeTypeError,
match=r"Ndarray shouldn't be passed in via"):
func(arr_0, arr_1)