Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lang] Raise an error when struct-for indices number mismatch #1357

Merged

Conversation

archibate
Copy link
Collaborator

@archibate archibate commented Jun 29, 2020

Related issue = #

[Click here for the format server]


Before this PR, the following code won't raise any error at all:

x = ti.var(ti.f32, (3, 4))

@ti.kernel
def func():
    for i in x:  # either use `for i, j in x` or `for I in ti.grouped(x)` instead!
        print(i)

func()

So I'm making struct-for mismatch raise IndexError now.

But I apply the same to ndrange-for, cause it seems ti.ndrange transformer needs refactoring anyway... IMO it should share the same error checker if we decide to do so.

I think just alerting mismatch struct-for and saying maybe you want to use ti.grouped() instead is good enough, since user can see range numbers if using ndrange-for.


Btw, I think we may default to ti.grouped at this case?

Copy link
Member

@yuanming-hu yuanming-hu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM except for some wording issues.

Btw, I think we may default to ti.grouped at this case?

That sounds too smart to me. I'd rather keep everything explicit :-)

python/taichi/lang/impl.py Outdated Show resolved Hide resolved
taichi/transforms/simplify.cpp Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jul 1, 2020

Codecov Report

Merging #1357 into master will decrease coverage by 1.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1357      +/-   ##
==========================================
- Coverage   66.51%   65.40%   -1.12%     
==========================================
  Files          37       37              
  Lines        5149     5009     -140     
  Branches      932      934       +2     
==========================================
- Hits         3425     3276     -149     
- Misses       1562     1571       +9     
  Partials      162      162              
Impacted Files Coverage Δ
python/taichi/lang/transformer.py 93.54% <ø> (-0.10%) ⬇️
python/taichi/lang/impl.py 89.93% <100.00%> (-0.17%) ⬇️
python/taichi/misc/image.py 56.00% <0.00%> (-11.57%) ⬇️
python/taichi/misc/task.py 75.00% <0.00%> (-5.00%) ⬇️
python/taichi/lang/ast_checker.py 70.58% <0.00%> (-1.64%) ⬇️
python/taichi/lang/ops.py 92.30% <0.00%> (-1.45%) ⬇️
python/taichi/main.py 40.42% <0.00%> (-1.03%) ⬇️
python/taichi/lang/expr.py 89.10% <0.00%> (-0.72%) ⬇️
python/taichi/misc/gui.py 23.94% <0.00%> (-0.71%) ⬇️
python/taichi/lang/matrix.py 90.03% <0.00%> (-0.68%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c83a7e3...3b98182. Read the comment docs.

@archibate archibate merged commit bbffac3 into taichi-dev:master Jul 1, 2020
@FantasyVR FantasyVR mentioned this pull request Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants