-
Notifications
You must be signed in to change notification settings - Fork 73
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
Experimental AST rewriter and JIT decorator #326
Open
hugohadfield
wants to merge
27
commits into
pygae:experimental/abc-mangling
Choose a base branch
from
hugohadfield:gnarly_hacks
base: experimental/abc-mangling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
9e3724c
Added numba overloaded functions to layout
hugohadfield 03826c5
Added a GA specific ast transformer
hugohadfield ef61257
Added a jit_func decorator to ast transform and numba jit
hugohadfield c13bc94
Corrected jit_func, added a test
hugohadfield 51f8a42
remove duplication in ast_transformer
hugohadfield 8022092
convert to abstract numeric types in the numba jit overload
hugohadfield f14521b
Improved handling globals, added a TODO
hugohadfield 5fdbb86
Added ast_pretty warning if not installed
hugohadfield d6c6e06
removed unnescary print
hugohadfield 8094a61
Added reversion to AST rewriter and JIT
hugohadfield 1767342
Added grade selection via the call syntax
hugohadfield 81601ce
Set up pytest benchmark
hugohadfield d905393
Make node visitation recursive for Call
hugohadfield 750ec85
Add ImportError type for astpretty
hugohadfield e0263f8
Improve warning whitespace
hugohadfield e878dbe
Make the Call rewrite exception an AttributeError
hugohadfield 482b091
Moved the decorator removal to the AST level
hugohadfield ff9648d
Add scalar and multivector constants to decorator arguments
hugohadfield 5d27874
Fix nested function call transformer
hugohadfield 6c2cea6
Improve speed of linear_operator_to_matrix
hugohadfield 307874f
Add testing for new jit decorator features
hugohadfield c5be87a
Added a nested jitted function test
hugohadfield 8f02960
Fixed flake8 complaints
hugohadfield 8e96d81
Apply suggestions from Eric code review
hugohadfield 2315f3f
Fix up review comments
hugohadfield 87a41b9
Moved jit_impls into jit_func
hugohadfield ccf5551
Moved jit_func into an experimental directory
hugohadfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
import ast | ||
|
||
|
||
class DecoratorRemover(ast.NodeTransformer): | ||
""" Strip decorators from top-level FunctionDefs""" | ||
def visit_FunctionDef(self, node): | ||
node.decorator_list = [] | ||
return node | ||
|
||
|
||
class GATransformer(ast.NodeTransformer): | ||
""" | ||
This is an AST transformer that converts operations into | ||
JITable counterparts that work on MultiVector value arrays. | ||
We crawl the AST and convert BinOps and UnaryOps into numba | ||
overloaded functions. | ||
""" | ||
def visit_BinOp(self, node): | ||
ops = { | ||
ast.Mult: 'ga_mul', | ||
ast.BitXor: 'ga_xor', | ||
ast.BitOr: 'ga_or', | ||
ast.Add: 'ga_add', | ||
ast.Sub: 'ga_sub', | ||
} | ||
try: | ||
func_name = ops[type(node.op)] | ||
except KeyError: | ||
return node | ||
else: | ||
return ast.Call( | ||
func=ast.Name(id=func_name, ctx=ast.Load()), | ||
args=[self.visit(node.left), self.visit(node.right)], | ||
keywords=[] | ||
) | ||
|
||
def visit_UnaryOp(self, node): | ||
ops = { | ||
ast.Invert: 'ga_rev' | ||
} | ||
try: | ||
func_name = ops[type(node.op)] | ||
except KeyError: | ||
return node | ||
else: | ||
return ast.Call( | ||
func=ast.Name(id=func_name, ctx=ast.Load()), | ||
args=[self.visit(node.operand)], | ||
keywords=[] | ||
) | ||
|
||
def visit_Call(self, node): | ||
if len(node.args) == 1: | ||
node = self.generic_visit(node) | ||
node.args = [node.func] + node.args | ||
node.func = ast.Name(id='ga_call', ctx=ast.Load()) | ||
return node | ||
else: | ||
return self.generic_visit(node) |
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
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice find
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.
Probably makes sense to spin out a quick PR with just this fix against master.
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.
yeah I was thinking that