-
Notifications
You must be signed in to change notification settings - Fork 71
feat: replace enumerate #397
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #397 +/- ##
==========================================
+ Coverage 87.19% 87.24% +0.04%
==========================================
Files 38 38
Lines 9498 9533 +35
==========================================
+ Hits 8282 8317 +35
Misses 1216 1216
Continue to review full report at Codecov.
|
It's not "not allowed" so much as "not supported yet".
Ideally, you could search for all for ix_ind = Base.OneTo(length(A))
ix_var = A[ix_ind + firstindex(A) - 1]
A[ix_ind] = ix_ind + ix_var
end However, you could also disallow it for now, because what if someone was doing something other than indexing into |
A human may not write code like this, but replacing enumerate may generated this code. for (i, n) in enumerate(1:2)
end would be replaced like this: for i = Base.OneTo(length(1:2))
n = (1:2)[(i + firstindex(1:2)) - 1]
end One possible solution is naming the literal range in loop like this for i = Base.OneTo(length(1:2))
r = 1:2
n = r[(i + firstindex(r)) - 1]
end but turbo on it shows Maybe create a block warp the |
I would definitely name it out of the loop. |
It would probably be easier to do this within the The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
ls = LoopSet(mod) | ||
check_inputs!(q, ls.prepreamble) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, moving check_inputs!
in here is better.
I'm working on the issue #393 by replacing enumerate which can be integrated in the check of loop body. However, I have some difficulties.
First, turbo for a expression instead of a symbol may cause
LoadError
like:may cause
ERROR: LoadError: "Indexing into the following expression was not recognized: 1:10"
. This error is not related to this PR and not common, feel free to ignore it, if this is not allowed.Second, for
where the index
i
and variablex
are not unboxed. I tried to generate symbols firstly and regroup them as a tuple like thiswhere the expression
(ix_ind, ix_var)
can't not be recognized. Maybe this form should not be allowed.