-
Notifications
You must be signed in to change notification settings - Fork 393
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
Addition / Subtraction Simplification for the stop parameter in sum / prod #115
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
The logic looks good, thanks!
Please add appropriate unit tests into function_codegen_test.py
as well.
@Casper-Guo Could you resolve the conflicts introduced by recent changes on |
…stop parameter for sum and prod
… using ast.Num instead of ast.Constant
@Casper-Guo It is not easy to select only your stuff. Try |
I rebased on main before pushing the new changes which should conceal all the new commits... Not sure why it didn't turn out that way. I will try to figure out a way to tidy it up. Edit: Should be all set for your review now. Sorry for the confusion |
900010f
to
acdb3a3
Compare
Looks great, thanks! |
Overview
This PR addresses issue #74.
Details
Implementation
First check the
stop
parameter ofrange_info
isast.BinOp
and represents an addition or subtraction. If so, the minus one is applied toBinOp.right
and a newast.BinOp
node is created. Then the existing visit function is leveraged to create the needed Latex.Note the special cases
+ 1 - 1
and- (-1) - 1
for which onlyBinOp.left
is kept.Added test cases to
regression_test.py
. Please let me know if these are more appropriate elsewhere (e.g.function_codegen_test.py
)Caveats
n+1-1
can be reduced ton
but1+n-1
cannot. This is becauserange(1+n)
is unlikely and unusual. Support for this can be easily added if desiredn + 3+4-1
will becomen+3+3
notn+6
. This is in line with how other chained BinOps are currently handled and may be addressed in a future issueQuestions
The implementation is slightly verbose and perhaps should be written as a separate function. Might other future PRs need this similar functionality?
References
Issue #74