Skip to content

Commit

Permalink
[lang] Throw proper error message if calling ti.append with vector/ma…
Browse files Browse the repository at this point in the history
…trix

related: taichi-dev#6205
  • Loading branch information
Ailing Zhang authored and taichi-gardener committed Oct 14, 2022
1 parent 3fe2a81 commit 721264b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python/taichi/lang/snode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
20 changes: 20 additions & 0 deletions tests/python/test_dynamic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from taichi.lang.exception import TaichiCompilationError

import taichi as ti
from tests import test_utils
Expand Down Expand Up @@ -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()

0 comments on commit 721264b

Please sign in to comment.