提交 84265eb9 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Add an auto_name option to aesara.printing.debugprint

上级 33743b89
......@@ -356,6 +356,7 @@ def _debugprint(
- ``"id"``: print the python id value,
- ``"int"``: print integer character,
- ``"CHAR"``: print capital character,
- ``"auto"``: print the ``auto_name`` value,
- ``""``: don't print an identifier.
stop_on_name
When True, if a node in the graph has a name, we don't print anything
......@@ -408,6 +409,8 @@ def _debugprint(
id_str = f"[id {len(used_ids)}]"
elif ids == "CHAR":
id_str = f"[id {char_from_number(len(used_ids))}]"
elif ids == "auto":
id_str = f"[id {r.auto_name}]"
elif ids == "":
id_str = ""
if get_printed:
......
......@@ -14,7 +14,7 @@ from aesara.printing import (
pydot_imported,
pydotprint,
)
from aesara.tensor.type import dvector, matrix
from aesara.tensor.type import dmatrix, dvector, matrix
@pytest.mark.skipif(not pydot_imported, reason="pydot not available")
......@@ -250,7 +250,30 @@ def test_debugprint():
assert s == reference
def test_subtensor():
def test_debugprint_ids():
a_at = dvector()
b_at = dmatrix()
d_at = b_at.dot(a_at)
e_at = d_at + a_at
s = StringIO()
debugprint(e_at, ids="auto", file=s)
s = s.getvalue()
exp_res = f"""Elemwise{{add,no_inplace}} [id {e_at.auto_name}] ''
|dot [id {d_at.auto_name}] ''
| |<TensorType(float64, matrix)> [id {b_at.auto_name}]
| |<TensorType(float64, vector)> [id {a_at.auto_name}]
|<TensorType(float64, vector)> [id {a_at.auto_name}]
"""
assert [l.strip() for l in s.split("\n")] == [
l.strip() for l in exp_res.split("\n")
]
def test_pprint():
x = dvector()
y = x[1]
assert pp(y) == "<TensorType(float64, vector)>[ScalarConstant{1}]"
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论