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

Clean up FunctionGraph str and repr implementation

上级 55ca059a
...@@ -144,12 +144,12 @@ def test_misc(): ...@@ -144,12 +144,12 @@ def test_misc():
g = Env([x, y, z], [e]) g = Env([x, y, z], [e])
assert g.consistent() assert g.consistent()
PatternOptimizer((transpose_view, (transpose_view, "x")), "x").optimize(g) PatternOptimizer((transpose_view, (transpose_view, "x")), "x").optimize(g)
assert str(g) == "[x]" assert str(g) == "FunctionGraph(x)"
new_e = add(x, y) new_e = add(x, y)
g.replace_validate(x, new_e) g.replace_validate(x, new_e)
assert str(g) == "[Add(x, y)]" assert str(g) == "FunctionGraph(Add(x, y))"
g.replace(new_e, dot(add_in_place(x, y), transpose_view(x))) g.replace(new_e, dot(add_in_place(x, y), transpose_view(x)))
assert str(g) == "[Dot(AddInPlace(x, y), TransposeView(x))]" assert str(g) == "FunctionGraph(Dot(AddInPlace(x, y), TransposeView(x)))"
assert not g.consistent() assert not g.consistent()
...@@ -325,7 +325,10 @@ def test_long_destroyers_loop(): ...@@ -325,7 +325,10 @@ def test_long_destroyers_loop():
OpSubOptimizer(add, add_in_place).optimize(g) OpSubOptimizer(add, add_in_place).optimize(g)
assert g.consistent() assert g.consistent()
# we don't want to see that! # we don't want to see that!
assert str(g) != "[Dot(Dot(AddInPlace(x, y), AddInPlace(y, z)), AddInPlace(z, x))]" assert (
str(g)
!= "FunctionGraph(Dot(Dot(AddInPlace(x, y), AddInPlace(y, z)), AddInPlace(z, x)))"
)
e2 = dot(dot(add_in_place(x, y), add_in_place(y, z)), add_in_place(z, x)) e2 = dot(dot(add_in_place(x, y), add_in_place(y, z)), add_in_place(z, x))
with pytest.raises(InconsistencyError): with pytest.raises(InconsistencyError):
Env(*graph.clone([x, y, z], [e2])) Env(*graph.clone([x, y, z], [e2]))
......
差异被折叠。
...@@ -173,12 +173,12 @@ class TestComposite: ...@@ -173,12 +173,12 @@ class TestComposite:
gof.DualLinker().accept(g).make_function() gof.DualLinker().accept(g).make_function()
assert str(g) == ( assert str(g) == (
"[*1 -> Composite{((i0 + i1) + i2)," "FunctionGraph(*1 -> Composite{((i0 + i1) + i2),"
" (i0 + (i1 * i2)), (i0 / i1), " " (i0 + (i1 * i2)), (i0 / i1), "
"(i0 // Constant{5}), " "(i0 // Constant{5}), "
"(-i0), (i0 - i1), ((i0 ** i1) + (-i2))," "(-i0), (i0 - i1), ((i0 ** i1) + (-i2)),"
" (i0 % Constant{3})}(x, y, z), " " (i0 % Constant{3})}(x, y, z), "
"*1::1, *1::2, *1::3, *1::4, *1::5, *1::6, *1::7]" "*1::1, *1::2, *1::3, *1::4, *1::5, *1::6, *1::7)"
) )
def test_make_node_continue_graph(self): def test_make_node_continue_graph(self):
......
差异被折叠。
...@@ -812,11 +812,8 @@ class FunctionGraph(utils.object2): ...@@ -812,11 +812,8 @@ class FunctionGraph(utils.object2):
"Inconsistent clients list.", variable, node.inputs[i] "Inconsistent clients list.", variable, node.inputs[i]
) )
def __str__(self):
return f"[{', '.join(graph.as_string(self.inputs, self.outputs))}]"
def __repr__(self): def __repr__(self):
return self.__str__() return f"FunctionGraph({', '.join(graph.as_string(self.inputs, self.outputs))})"
def clone(self, check_integrity=True): def clone(self, check_integrity=True):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论