-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: Prevent reconstructions (eg unpickling) from unpicking opti…
…mizations
- Loading branch information
1 parent
168df51
commit 80dd5d4
Showing
7 changed files
with
99 additions
and
9 deletions.
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
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,33 @@ | ||
import sympy | ||
|
||
from devito.ir import cluster_pass | ||
from devito.symbolics import reuse_if_untouched, q_leaf | ||
from devito.symbolics.unevaluation import Add, Mul, Pow | ||
|
||
__all__ = ['unevaluate'] | ||
|
||
|
||
@cluster_pass | ||
def unevaluate(cluster): | ||
exprs = [_unevaluate(e) for e in cluster.exprs] | ||
|
||
return cluster.rebuild(exprs=exprs) | ||
|
||
|
||
mapper = { | ||
sympy.Add: Add, | ||
sympy.Mul: Mul, | ||
sympy.Pow: Pow | ||
} | ||
|
||
|
||
def _unevaluate(expr): | ||
if q_leaf(expr): | ||
return expr | ||
|
||
args = [_unevaluate(a) for a in expr.args] | ||
|
||
try: | ||
return mapper[expr.func](*args) | ||
except KeyError: | ||
return reuse_if_untouched(expr, args) |
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,21 @@ | ||
import sympy | ||
|
||
__all__ = ['Add', 'Mul', 'Pow'] | ||
|
||
|
||
class UnevaluableMixin(object): | ||
|
||
def __new__(cls, *args, evaluate=None, **kwargs): | ||
return cls.__base__.__new__(cls, *args, evaluate=False, **kwargs) | ||
|
||
|
||
class Add(sympy.Add, UnevaluableMixin): | ||
__new__ = UnevaluableMixin.__new__ | ||
|
||
|
||
class Mul(sympy.Mul, UnevaluableMixin): | ||
__new__ = UnevaluableMixin.__new__ | ||
|
||
|
||
class Pow(sympy.Pow, UnevaluableMixin): | ||
__new__ = UnevaluableMixin.__new__ |
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
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