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

Remove pointless print statements and some evaluations

上级 616f8d26
...@@ -174,23 +174,19 @@ class TestGreedyDistribute: ...@@ -174,23 +174,19 @@ class TestGreedyDistribute:
# 1. ((a/x + b/y) * x * y) --> a*y + b*x # 1. ((a/x + b/y) * x * y) --> a*y + b*x
e = (a / z + b / x) * x * z e = (a / z + b / x) * x * z
g = FunctionGraph([a, b, c, d, x, y, z], [e]) g = FunctionGraph([a, b, c, d, x, y, z], [e])
# print pprint(g.outputs[0])
mul_canonizer.optimize(g) mul_canonizer.optimize(g)
TopoOptimizer( TopoOptimizer(
LocalOptGroup(local_greedy_distributor), order="out_to_in" LocalOptGroup(local_greedy_distributor), order="out_to_in"
).optimize(g) ).optimize(g)
# print pprint(g.outputs[0])
assert str(pprint(g.outputs[0])) == "((a * x) + (b * z))" assert str(pprint(g.outputs[0])) == "((a * x) + (b * z))"
# 2. ((a/x + b) * x) --> a + b*x # 2. ((a/x + b) * x) --> a + b*x
e = (a / x + b) * x e = (a / x + b) * x
g = FunctionGraph([a, b, x], [e]) g = FunctionGraph([a, b, x], [e])
# print pprint(g.outputs[0])
mul_canonizer.optimize(g) mul_canonizer.optimize(g)
TopoOptimizer( TopoOptimizer(
LocalOptGroup(local_greedy_distributor), order="out_to_in" LocalOptGroup(local_greedy_distributor), order="out_to_in"
).optimize(g) ).optimize(g)
# print pprint(g.outputs[0])
assert str(pprint(g.outputs[0])) == "(a + (b * x))" assert str(pprint(g.outputs[0])) == "(a + (b * x))"
def test_kording_bug(self): def test_kording_bug(self):
...@@ -233,9 +229,7 @@ class TestAlgebraicCanonize: ...@@ -233,9 +229,7 @@ class TestAlgebraicCanonize:
# e = (x / x) * (y / y) # e = (x / x) * (y / y)
e = (-1 * x) / y / (-2 * z) e = (-1 * x) / y / (-2 * z)
g = FunctionGraph([x, y, z, a, b, c, d], [e]) g = FunctionGraph([x, y, z, a, b, c, d], [e])
print(pprint(g.outputs[0]))
mul_canonizer.optimize(g) mul_canonizer.optimize(g)
print(pprint(g.outputs[0]))
def test_elemwise_multiple_inputs_optimisation(self): def test_elemwise_multiple_inputs_optimisation(self):
# verify that the AlgebraicCanonizer merge sequential Elemwise({mul,add}) part 1 # verify that the AlgebraicCanonizer merge sequential Elemwise({mul,add}) part 1
...@@ -856,8 +850,6 @@ class TestAlgebraicCanonize: ...@@ -856,8 +850,6 @@ class TestAlgebraicCanonize:
mode = get_default_mode().excluding("local_elemwise_fusion") mode = get_default_mode().excluding("local_elemwise_fusion")
f = function([x], [(4 * x) / abs(2 * x)], mode=mode) f = function([x], [(4 * x) / abs(2 * x)], mode=mode)
print(f.maker.fgraph.toposort())
print()
f(0.1) f(0.1)
f(-1) f(-1)
# some stabilization optimization make the output be finite instead of nan # some stabilization optimization make the output be finite instead of nan
...@@ -869,8 +861,6 @@ class TestAlgebraicCanonize: ...@@ -869,8 +861,6 @@ class TestAlgebraicCanonize:
assert f.maker.fgraph.toposort()[0].op == sgn assert f.maker.fgraph.toposort()[0].op == sgn
f = function([x], [(4 * x) / abs(x / 2)], mode=mode) f = function([x], [(4 * x) / abs(x / 2)], mode=mode)
print(f.maker.fgraph.toposort())
print()
f(0.1) f(0.1)
f(-1) f(-1)
# some stabilization optimization make the output be finite instead of nan # some stabilization optimization make the output be finite instead of nan
...@@ -1038,7 +1028,6 @@ def test_cast_in_mul_canonizer(): ...@@ -1038,7 +1028,6 @@ def test_cast_in_mul_canonizer():
o2 = e * go o2 = e * go
mode = get_default_mode().excluding("fusion").including("fast_run") mode = get_default_mode().excluding("fusion").including("fast_run")
f = function([x, y], [o1, o2], mode=mode) f = function([x, y], [o1, o2], mode=mode)
aesara.printing.debugprint(f, print_type=True)
nodes = f.maker.fgraph.apply_nodes nodes = f.maker.fgraph.apply_nodes
assert ( assert (
len( len(
...@@ -1992,6 +1981,7 @@ class TestLocalUselessElemwiseComparison: ...@@ -1992,6 +1981,7 @@ class TestLocalUselessElemwiseComparison:
self.rng = np.random.RandomState(utt.fetch_seed()) self.rng = np.random.RandomState(utt.fetch_seed())
def test_local_useless_elemwise_comparison(self): def test_local_useless_elemwise_comparison(self):
# TODO FIXME: This is not a real test!
# TODO: test each case individually. # TODO: test each case individually.
# The following case is what made me discover those cases. # The following case is what made me discover those cases.
X = matrix("X") X = matrix("X")
...@@ -2667,19 +2657,17 @@ class TestLocalErf: ...@@ -2667,19 +2657,17 @@ class TestLocalErf:
assert [n.op for n in f.maker.fgraph.toposort()] == [ assert [n.op for n in f.maker.fgraph.toposort()] == [
erfc erfc
], f.maker.fgraph.toposort() ], f.maker.fgraph.toposort()
print(f(val)) f(val)
f = function([x], 1 + (-erf(x)), mode=self.mode) f = function([x], 1 + (-erf(x)), mode=self.mode)
assert [n.op for n in f.maker.fgraph.toposort()] == [ assert [n.op for n in f.maker.fgraph.toposort()] == [
erfc erfc
], f.maker.fgraph.toposort() ], f.maker.fgraph.toposort()
print(f(val))
f = function([x], (-erf(x)) + 1, mode=self.mode) f = function([x], (-erf(x)) + 1, mode=self.mode)
assert [n.op for n in f.maker.fgraph.toposort()] == [ assert [n.op for n in f.maker.fgraph.toposort()] == [
erfc erfc
], f.maker.fgraph.toposort() ], f.maker.fgraph.toposort()
print(f(val))
f = function([x], 2 - erf(x), mode=self.mode) f = function([x], 2 - erf(x), mode=self.mode)
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
...@@ -2689,7 +2677,6 @@ class TestLocalErf: ...@@ -2689,7 +2677,6 @@ class TestLocalErf:
assert isinstance(topo[1].op.scalar_op, aes.Add) or isinstance( assert isinstance(topo[1].op.scalar_op, aes.Add) or isinstance(
topo[1].op.scalar_op, aes.Sub topo[1].op.scalar_op, aes.Sub
), f.maker.fgraph.toposort() ), f.maker.fgraph.toposort()
print(f(val))
def test_local_erf_minus_one(self): def test_local_erf_minus_one(self):
val = np.asarray([-30, -3, -2, -1, 0, 1, 2, 3, 30], dtype=config.floatX) val = np.asarray([-30, -3, -2, -1, 0, 1, 2, 3, 30], dtype=config.floatX)
...@@ -2697,15 +2684,13 @@ class TestLocalErf: ...@@ -2697,15 +2684,13 @@ class TestLocalErf:
f = function([x], erf(x) - 1, mode=self.mode) f = function([x], erf(x) - 1, mode=self.mode)
assert [n.op for n in f.maker.fgraph.toposort()] == [erfc, mul] assert [n.op for n in f.maker.fgraph.toposort()] == [erfc, mul]
print(f(val)) f(val)
f = function([x], erf(x) + (-1), mode=self.mode) f = function([x], erf(x) + (-1), mode=self.mode)
assert [n.op for n in f.maker.fgraph.toposort()] == [erfc, mul] assert [n.op for n in f.maker.fgraph.toposort()] == [erfc, mul]
print(f(val))
f = function([x], -1 + erf(x), mode=self.mode) f = function([x], -1 + erf(x), mode=self.mode)
assert [n.op for n in f.maker.fgraph.toposort()] == [erfc, mul] assert [n.op for n in f.maker.fgraph.toposort()] == [erfc, mul]
print(f(val))
f = function([x], erf(x) - 2, mode=self.mode) f = function([x], erf(x) - 2, mode=self.mode)
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
...@@ -2715,7 +2700,6 @@ class TestLocalErf: ...@@ -2715,7 +2700,6 @@ class TestLocalErf:
assert isinstance(topo[1].op.scalar_op, aes.Add) or isinstance( assert isinstance(topo[1].op.scalar_op, aes.Add) or isinstance(
topo[1].op.scalar_op, aes.Sub topo[1].op.scalar_op, aes.Sub
) )
print(f(val))
@pytest.mark.skipif( @pytest.mark.skipif(
...@@ -2743,13 +2727,12 @@ class TestLocalErfc: ...@@ -2743,13 +2727,12 @@ class TestLocalErfc:
assert [n.op for n in f.maker.fgraph.toposort()] == [ assert [n.op for n in f.maker.fgraph.toposort()] == [
erf erf
], f.maker.fgraph.toposort() ], f.maker.fgraph.toposort()
print(f(val)) f(val)
f = function([x], (-erfc(x)) + 1, mode=self.mode) f = function([x], (-erfc(x)) + 1, mode=self.mode)
assert [n.op for n in f.maker.fgraph.toposort()] == [ assert [n.op for n in f.maker.fgraph.toposort()] == [
erf erf
], f.maker.fgraph.toposort() ], f.maker.fgraph.toposort()
print(f(val))
f = function([x], 2 - erfc(x), mode=self.mode) f = function([x], 2 - erfc(x), mode=self.mode)
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
...@@ -2757,11 +2740,9 @@ class TestLocalErfc: ...@@ -2757,11 +2740,9 @@ class TestLocalErfc:
assert topo[0].op == erfc, f.maker.fgraph.toposort() assert topo[0].op == erfc, f.maker.fgraph.toposort()
assert isinstance(topo[1].op, Elemwise), f.maker.fgraph.toposort() assert isinstance(topo[1].op, Elemwise), f.maker.fgraph.toposort()
assert isinstance(topo[1].op.scalar_op, aes.Sub), f.maker.fgraph.toposort() assert isinstance(topo[1].op.scalar_op, aes.Sub), f.maker.fgraph.toposort()
print(f(val))
def test_local_erf_neg_minus_one(self): def test_local_erf_neg_minus_one(self):
# test opt: (-1)+erfc(-x)=>erf(x) # test opt: (-1)+erfc(-x)=>erf(x)
val = np.asarray([-30, -3, -2, -1, 0, 1, 2, 3, 30], dtype=config.floatX) val = np.asarray([-30, -3, -2, -1, 0, 1, 2, 3, 30], dtype=config.floatX)
x = vector("x") x = vector("x")
...@@ -2769,19 +2750,17 @@ class TestLocalErfc: ...@@ -2769,19 +2750,17 @@ class TestLocalErfc:
assert [n.op for n in f.maker.fgraph.toposort()] == [ assert [n.op for n in f.maker.fgraph.toposort()] == [
erf erf
], f.maker.fgraph.toposort() ], f.maker.fgraph.toposort()
print(f(val)) f(val)
f = function([x], erfc(-x) - 1, mode=self.mode) f = function([x], erfc(-x) - 1, mode=self.mode)
assert [n.op for n in f.maker.fgraph.toposort()] == [ assert [n.op for n in f.maker.fgraph.toposort()] == [
erf erf
], f.maker.fgraph.toposort() ], f.maker.fgraph.toposort()
print(f(val))
f = function([x], erfc(-x) + (-1), mode=self.mode) f = function([x], erfc(-x) + (-1), mode=self.mode)
assert [n.op for n in f.maker.fgraph.toposort()] == [ assert [n.op for n in f.maker.fgraph.toposort()] == [
erf erf
], f.maker.fgraph.toposort() ], f.maker.fgraph.toposort()
print(f(val))
@pytest.mark.xfail() @pytest.mark.xfail()
def test_local_log_erfc(self): def test_local_log_erfc(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论