diff --git a/python/taichi/lang/ast/ast_transformer.py b/python/taichi/lang/ast/ast_transformer.py index 5561af8198a83..79a2bb8cf7297 100644 --- a/python/taichi/lang/ast/ast_transformer.py +++ b/python/taichi/lang/ast/ast_transformer.py @@ -1153,16 +1153,11 @@ def build_ndrange_for(ctx, node): I = impl.expr_init(ndrange_loop_var) targets = ASTTransformer.get_for_loop_targets(node) if len(targets) != len(ndrange_var.dimensions): - warnings.warn_explicit( + raise TaichiSyntaxError( "Ndrange for loop with number of the loop variables not equal to " - "the dimension of the ndrange is deprecated, " - "and it will be removed in Taichi 1.6.0. " + "the dimension of the ndrange is not supported. " "Please check if the number of arguments of ti.ndrange() is equal to " - "the number of the loop variables.", - DeprecationWarning, - ctx.file, - node.lineno + ctx.lineno_offset, - module="taichi", + "the number of the loop variables." ) for i, target in enumerate(targets): if i + 1 < len(targets): diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index 671231c5ac391..f1feeaa4f54aa 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -82,23 +82,6 @@ def func(): func() -@test_utils.test() -def test_deprecate_ndrange(): - with pytest.warns( - DeprecationWarning, - match="Ndrange for loop with number of the loop variables not equal to " - "the dimension of the ndrange is deprecated, " - "and it will be removed in Taichi 1.6.0. ", - ): - - @ti.kernel - def func(): - for i in ti.ndrange(4, 4): - pass - - func() - - @pytest.mark.skipif(not _ti_core.GGUI_AVAILABLE, reason="GGUI Not Available") @test_utils.test(arch=ti.cpu) def test_deprecate_ti_ui_window(): diff --git a/tests/python/test_ndrange.py b/tests/python/test_ndrange.py index 9dd8ff47dc0e1..ab69e853003cb 100644 --- a/tests/python/test_ndrange.py +++ b/tests/python/test_ndrange.py @@ -312,20 +312,6 @@ def example(): example() -@test_utils.test(exclude=[ti.amdgpu]) -def test_n_loop_var_neq_dimension(): - @ti.kernel - def iter(): - for i in ti.ndrange(1, 4): - print(i) - - with pytest.warns( - DeprecationWarning, - match="Ndrange for loop with number of the loop variables not equal to", - ): - iter() - - @test_utils.test(exclude=[ti.cc]) def test_2d_loop_over_ndarray(): @ti.kernel @@ -336,3 +322,19 @@ def foo(arr: ti.types.ndarray(dtype=ti.i32, ndim=1)): array = ti.ndarray(ti.i32, shape=(16,)) foo(array) + + +@test_utils.test() +def test_dimension_error(): + with pytest.raises( + ti.TaichiSyntaxError, + match="Ndrange for loop with number of the loop variables not equal to " + "the dimension of the ndrange is not supported", + ): + + @ti.kernel + def func(): + for i in ti.ndrange(4, 4): + pass + + func()