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

Experimental AST rewriter and JIT decorator #326

Open
wants to merge 27 commits into
base: experimental/abc-mangling
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9e3724c
Added numba overloaded functions to layout
hugohadfield Jun 5, 2020
03826c5
Added a GA specific ast transformer
hugohadfield Jun 5, 2020
ef61257
Added a jit_func decorator to ast transform and numba jit
hugohadfield Jun 5, 2020
c13bc94
Corrected jit_func, added a test
hugohadfield Jun 5, 2020
51f8a42
remove duplication in ast_transformer
hugohadfield Jun 5, 2020
8022092
convert to abstract numeric types in the numba jit overload
hugohadfield Jun 5, 2020
f14521b
Improved handling globals, added a TODO
hugohadfield Jun 5, 2020
5fdbb86
Added ast_pretty warning if not installed
hugohadfield Jun 5, 2020
d6c6e06
removed unnescary print
hugohadfield Jun 5, 2020
8094a61
Added reversion to AST rewriter and JIT
hugohadfield Jun 5, 2020
1767342
Added grade selection via the call syntax
hugohadfield Jun 5, 2020
81601ce
Set up pytest benchmark
hugohadfield Jun 6, 2020
d905393
Make node visitation recursive for Call
hugohadfield Jun 6, 2020
750ec85
Add ImportError type for astpretty
hugohadfield Jun 6, 2020
e0263f8
Improve warning whitespace
hugohadfield Jun 6, 2020
e878dbe
Make the Call rewrite exception an AttributeError
hugohadfield Jun 6, 2020
482b091
Moved the decorator removal to the AST level
hugohadfield Jun 6, 2020
ff9648d
Add scalar and multivector constants to decorator arguments
hugohadfield Jun 7, 2020
5d27874
Fix nested function call transformer
hugohadfield Jun 7, 2020
6c2cea6
Improve speed of linear_operator_to_matrix
hugohadfield Jun 7, 2020
307874f
Add testing for new jit decorator features
hugohadfield Jun 7, 2020
c5be87a
Added a nested jitted function test
hugohadfield Jun 8, 2020
8f02960
Fixed flake8 complaints
hugohadfield Jun 8, 2020
8e96d81
Apply suggestions from Eric code review
hugohadfield Jun 9, 2020
2315f3f
Fix up review comments
hugohadfield Jun 9, 2020
87a41b9
Moved jit_impls into jit_func
hugohadfield Jun 9, 2020
ccf5551
Moved jit_func into an experimental directory
hugohadfield Jun 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions clifford/test/test_jit_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ def slow_test_func(A, B):

np.testing.assert_allclose(test_func(e1, e12).value, slow_test_func(e1, e12).value)

def test_nested_functions(self):
e1 = self.blades['e1']
e12 = self.blades['e12']

def test_func_1(A, B):
op = (A(1)+B(2))(1)
return op

def test_func_2(A):
op = ~A + 5*e12
return op

def compound_func(A, B):
return test_func_2(test_func_1(A, B))

test_func_1_jit = jit_func(self.layout)(test_func_1)
test_func_2_jit = jit_func(self.layout,
mv_constants={'e12': e12})(test_func_2)

test_compound_func = jit_func(self.layout,
mv_constants={'test_func_1': test_func_1_jit,
'test_func_2': test_func_2_jit})(compound_func)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a way to nest functions by using(abusing?) the mv_constants argument, it is clearly not a great solution but I'm not sure how to pull it off otherwise. Perhaps the decorator has knowledge of what functions are available?

Copy link
Member

Choose a reason for hiding this comment

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

The decorator can probably use inspect.currentframe().f_back.f_locals

Copy link
Member

Choose a reason for hiding this comment

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

I suspect you should be using f_globals instead of globals() too.


np.testing.assert_allclose(test_compound_func(e1, e12).value, compound_func(e1, e12).value)

def test_reverse(self):
e12 = self.blades['e12']

Expand Down Expand Up @@ -66,5 +91,4 @@ def test_func(A, B, C, D):
mv_constants={'e12345': e12345},
scalar_constants={'pi': pi}
)(test_func)
benchmark(test_func, self.blades['e1'], self.blades['e2'], self.layout.einf, self.blades['e34'])

benchmark(test_func, self.blades['e1'], self.blades['e2'], self.layout.einf, self.blades['e34'])