From 6baf5d94054f1cc2996a352c730a346c21fd63fb Mon Sep 17 00:00:00 2001 From: Ailing Zhang Date: Fri, 14 Oct 2022 12:41:43 +0800 Subject: [PATCH] [lang] Throw proper error message if calling ti.append with vector/matrix related: #6205 --- python/taichi/lang/snode.py | 4 +++- tests/python/test_dynamic.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/python/taichi/lang/snode.py b/python/taichi/lang/snode.py index f59ece970e344e..53463753db7936 100644 --- a/python/taichi/lang/snode.py +++ b/python/taichi/lang/snode.py @@ -368,8 +368,10 @@ def append(node, indices, val): Args: node (:class:`~taichi.SNode`): Input SNode. indices (Union[int, :class:`~taichi.Vector`]): the indices to visit. - val (:mod:`~taichi.types`): the data to be appended. + val (:mod:`~taichi.types.primitive_types`): the scalar data to be appended, only i32 value is support for now. """ + if isinstance(val, matrix.Matrix): + raise ValueError("ti.append only supports appending a scalar value") a = impl.expr_init( _ti_core.expr_snode_append(node._snode.ptr, expr.make_expr_group(indices), diff --git a/tests/python/test_dynamic.py b/tests/python/test_dynamic.py index 94d286131d8426..feeba0df9f9fd5 100644 --- a/tests/python/test_dynamic.py +++ b/tests/python/test_dynamic.py @@ -1,4 +1,5 @@ import pytest +from taichi.lang.exception import TaichiCompilationError import taichi as ti from tests import test_utils @@ -209,3 +210,22 @@ def func(): assert l[0] == m assert l[1] == 21 assert l[2] == 21 + + +@test_utils.test(require=ti.extension.sparse) +def test_append_vec(): + x = ti.Vector.field(3, ti.f32) + block = ti.root.dense(ti.i, 16) + pixel = block.dynamic(ti.j, 16) + pixel.place(x) + + @ti.kernel + def make_lists(): + for i in range(5): + for j in range(i): + x_vec3 = ti.math.vec3(i, j, j * j) + ti.append(x.parent(), i, x_vec3) + + with pytest.raises(TaichiCompilationError, + match=r'append only supports appending a scalar value'): + make_lists()