Commit 627ad747 authored by Martin Bauer's avatar Martin Bauer
Browse files

Removed unused code in dot printing

parent 8c744109
......@@ -8,10 +8,9 @@ class DotPrinter(Printer):
A printer which converts ast to DOT (graph description language).
def __init__(self, node_to_str_function, full, **kwargs):
def __init__(self, node_to_str_function, **kwargs):
super(DotPrinter, self).__init__()
self._node_to_str_function = node_to_str_function
self.full = full = Digraph(**kwargs) = lang.quote
......@@ -36,11 +35,6 @@ class DotPrinter(Printer):
def _print_SympyAssignment(self, assignment):, style='filled', fillcolor='#56db7f',
if self.full:
for node in assignment.args:
for node in assignment.args:, str(id(node)))
def _print_Conditional(self, expr):, style='filled', fillcolor='#56bd7f', label=self._node_to_str_function(expr))
......@@ -50,16 +44,6 @@ class DotPrinter(Printer):
self._print(expr.false_block), str(id(expr.false_block)))
def empty_printer(self, expr):
if self.full:, label=self._node_to_str_function(expr))
for node in expr.args:
for node in expr.args:, str(id(node)))
raise NotImplementedError('DotPrinter cannot print', type(expr), expr)
def doprint(self, expr):
......@@ -83,23 +67,19 @@ def __shortened(node):
raise NotImplementedError("Cannot handle node type %s" % (type(node),))
def print_dot(node, view=False, short=False, full=False, **kwargs):
def print_dot(node, view=False, short=False, **kwargs):
Returns a string which can be used to generate a DOT-graph
:param node: The ast which should be generated
:param view: Boolean, if rendering of the image directly should occur.
:param short: Uses the __shortened output
:param full: Prints the whole tree with type information
:param kwargs: is directly passed to the DotPrinter class:
:return: string in DOT format
node_to_str_function = repr
if short:
node_to_str_function = __shortened
elif full:
def node_to_str_function(expr):
return repr(type(expr)) + repr(expr)
printer = DotPrinter(node_to_str_function, full, **kwargs)
printer = DotPrinter(node_to_str_function, **kwargs)
dot = printer.doprint(node)
if view:
return graphviz.Source(dot)
......@@ -3,7 +3,7 @@ from typing import Any, Dict, Optional
from pystencils.astnodes import KernelFunction
def to_dot(expr: sp.Expr, graph_style: Optional[Dict[str, Any]] = None):
def to_dot(expr: sp.Expr, graph_style: Optional[Dict[str, Any]] = None, short=True):
"""Show a sympy or pystencils AST as dot graph"""
from pystencils.astnodes import Node
import graphviz
......@@ -11,7 +11,7 @@ def to_dot(expr: sp.Expr, graph_style: Optional[Dict[str, Any]] = None):
if isinstance(expr, Node):
from import print_dot
return graphviz.Source(print_dot(expr, short=True, graph_attr=graph_style))
return graphviz.Source(print_dot(expr, short=short, graph_attr=graph_style))
from import dotprint
return graphviz.Source(dotprint(expr, graph_attr=graph_style))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment