aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mdpoly/util.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/mdpoly/util.py b/mdpoly/util.py
index c7f3b51..ae726ef 100644
--- a/mdpoly/util.py
+++ b/mdpoly/util.py
@@ -36,3 +36,16 @@ def iszero(x: float, eps: float =NUMERICS_EPS) -> bool:
def filtertype(t: type, seq: Iterable):
""" Filter based on type. """
yield from filter(lambda x: isinstance(x, t), seq)
+
+
+def showtree(expr):
+ """ Pretty print expression tree. """
+ from PrettyPrint import PrettyPrintTree
+ def getval(x):
+ if x.is_leaf:
+ return str(x)
+ return x.__class__.__qualname__
+
+ PrettyPrintTree(lambda x: x.children(), getval)(expr)
+
+