-
Notifications
You must be signed in to change notification settings - Fork 398
More and more refactoring. #72
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
if lstr is None: | ||
lstr = r"\mathrm{" + callee_str + r"}\left(" | ||
rstr = r"\right)" | ||
if func_str in ("sum", "prod") and isinstance(node.args[0], ast.GeneratorExp): |
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.
sum / prod handler here LGTM.
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.
LGTM
r"\mathrm{f}(x) \triangleq " | ||
r"{3}\left( \left( x^{{2}} \right) + \left( x^{{2}} \right) \right)" | ||
|
||
def test_reduce_assignments_with_if() -> None: |
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.
so nice
Overview
reduce_assignments
behavior totransformers/AssignmentReducer
.NodeVisitorBase
implementation.LatexifyVisitor
tocodegen/FunctionCodegen
Details
Substitution sign
amssymb
package is loaded, which is not compatible with the bare LaTeX. This behavior often confuses users who try to compile the obtained LaTeX source by themselves.The sign is replaced to$=$ at this point, because I thought that this sign is the most neutral choice to every user.
We may further need to provide some flags to replace this sign by users.
Other refactoring
This change improves the modulability of the whole library.
The
visit_*
functions in the newFunctionCodegen
visitor returns alwaysstr
, while ad-hoc processes are moved away to the new AST transformerAssignmentReducer
or some private functions.AssignmentReducer
directly modifies the AST by replacing subtrees with substitution. This could reduce some unnecessary parenthesis pairs\left(
and\right)
caused by ad-hoc processing in the old Visitor.This change also removes all "actions" from the original Visitor so that we can use the standard
ast.NodeVisitor
as the base class of the codegen.References
Blocked by
NA