-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lang] Raise an error when struct-for indices number mismatch (#1357)
* [lang] Raise an error when struct-for indices number mismatch * [skip ci] enforce code format * [skip ci] Apply suggestions from code review Co-authored-by: Yuanming Hu <[email protected]> Co-authored-by: Taichi Gardener <[email protected]> Co-authored-by: Yuanming Hu <[email protected]>
- Loading branch information
1 parent
6100ee2
commit bbffac3
Showing
4 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import taichi as ti | ||
|
||
|
||
@ti.must_throw(IndexError) | ||
@ti.host_arch_only | ||
def test_struct_for_mismatch(): | ||
x = ti.var(ti.f32, (3, 4)) | ||
|
||
@ti.kernel | ||
def func(): | ||
for i in x: | ||
print(i) | ||
|
||
func() | ||
|
||
|
||
@ti.must_throw(IndexError) | ||
@ti.host_arch_only | ||
def test_struct_for_mismatch2(): | ||
x = ti.var(ti.f32, (3, 4)) | ||
|
||
@ti.kernel | ||
def func(): | ||
for i, j, k in x: | ||
print(i, j, k) | ||
|
||
func() | ||
|
||
|
||
@ti.must_throw(IndexError) | ||
@ti.host_arch_only | ||
def _test_grouped_struct_for_mismatch(): | ||
# doesn't work for now | ||
# need grouped refactor | ||
# for now, it just throw a unfriendly message: | ||
# AssertionError: __getitem__ cannot be called in Python-scope | ||
x = ti.var(ti.f32, (3, 4)) | ||
|
||
@ti.kernel | ||
def func(): | ||
for i, j in ti.grouped(x): | ||
print(i, j) | ||
|
||
func() | ||
|
||
|
||
@ti.must_throw(IndexError) | ||
@ti.host_arch_only | ||
def _test_ndrange_for_mismatch(): | ||
# doesn't work for now | ||
# need ndrange refactor | ||
@ti.kernel | ||
def func(): | ||
for i in ti.ndrange(3, 4): | ||
print(i) | ||
|
||
func() | ||
|
||
|
||
@ti.must_throw(IndexError) | ||
@ti.host_arch_only | ||
def _test_ndrange_for_mismatch2(): | ||
# doesn't work for now | ||
# need ndrange and grouped refactor | ||
@ti.kernel | ||
def func(): | ||
for i, j, k in ti.ndrange(3, 4): | ||
print(i, j, k) | ||
|
||
func() | ||
|
||
|
||
@ti.must_throw(IndexError) | ||
@ti.host_arch_only | ||
def _test_grouped_ndrange_for_mismatch(): | ||
# doesn't work for now | ||
# need ndrange and grouped refactor | ||
@ti.kernel | ||
def func(): | ||
for i in ti.grouped(ti.ndrange(3, 4)): | ||
print(i) | ||
|
||
func() | ||
|
||
|
||
@ti.must_throw(IndexError) | ||
@ti.host_arch_only | ||
def _test_static_ndrange_for_mismatch(): | ||
# doesn't work for now | ||
# need ndrange and static refactor | ||
@ti.kernel | ||
def func(): | ||
for i in ti.static(ti.ndrange(3, 4)): | ||
print(i) | ||
|
||
func() |