Skip to content

Commit

Permalink
[bug] Accept numpy integers in ndrange (#5245)
Browse files Browse the repository at this point in the history
  • Loading branch information
feisuzhu committed Jul 4, 2022
1 parent 752a843 commit 42a9cae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/taichi/lang/_ndrange.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections.abc

import numpy as np
from taichi.lang import ops
from taichi.lang.exception import TaichiSyntaxError, TaichiTypeError
from taichi.lang.expr import Expr
Expand All @@ -20,7 +21,7 @@ def __init__(self, *args):
args[i] = (args[i][0], ops.max(args[i][0], args[i][1]))
for arg in args:
for bound in arg:
if not isinstance(bound, int) and not (
if not isinstance(bound, (int, np.integer)) and not (
isinstance(bound, Expr)
and is_integral(bound.ptr.get_ret_type())):
raise TaichiTypeError(
Expand Down
12 changes: 12 additions & 0 deletions tests/python/test_ndrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ def example():
example()


@test_utils.test()
def test_ndrange_should_accept_numpy_integer():
a, b = np.int64(0), np.int32(10)

@ti.kernel
def example():
for i in ti.ndrange((a, b)):
pass

example()


@test_utils.test()
def test_static_ndrange_non_integer_arguments():
@ti.kernel
Expand Down

0 comments on commit 42a9cae

Please sign in to comment.