提交 165a7ae5 authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix opt bug not release that make in the end a stability opt not applied.

reported by David Huggins Daines
上级 60ec46ad
......@@ -3936,7 +3936,7 @@ def attempt_distribution(factor, num, denum):
neg_pairs))), num, denum
@gof.local_optimizer([T.mul])
@gof.local_optimizer([T.mul, T.true_div])
def local_greedy_distributor(node):
"""
This optimization tries to apply distributivity of multiplication
......@@ -3948,9 +3948,10 @@ def local_greedy_distributor(node):
The following expressions are simplified:
1. ((a/x + b/y) * x * y) --> a*y + b*x
2. ((a/x + b) * x) --> a + b*x
3. There other form too where node is a true_div.
The following expressions are not simplified:
3. ((a + b) * x) -/-> a*x + b*x
4. ((a + b) * x) -/-> a*x + b*x
This optimization aims to reduce computational cost. It may also
increase numerical stability, e.g. when x and/or y tend to 0 in
......
......@@ -162,13 +162,26 @@ def test_add_canonizer_problem0():
class test_greedy_distribute(unittest.TestCase):
def test_main(self):
a, b, c, d, x, y, z = matrices('abcdxyz')
#1. ((a/x + b/y) * x * y) --> a*y + b*x
e = (a / z + b / x) * x * z
g = FunctionGraph([a, b, c, d, x, y, z], [e])
##print pprint(g.outputs[0])
#print pprint(g.outputs[0])
mul_canonizer.optimize(g)
gof.TopoOptimizer(gof.LocalOptGroup(local_greedy_distributor),
order='out_to_in').optimize(g)
#print pprint(g.outputs[0])
assert str(pprint(g.outputs[0])) == "((a * x) + (b * z))"
#2. ((a/x + b) * x) --> a + b*x
e = (a / x + b) * x
g = FunctionGraph([a, b, x], [e])
#print pprint(g.outputs[0])
mul_canonizer.optimize(g)
gof.TopoOptimizer(gof.LocalOptGroup(local_greedy_distributor),
order='out_to_in').optimize(g)
##print pprint(g.outputs[0])
#print pprint(g.outputs[0])
assert str(pprint(g.outputs[0])) == "(a + (b * x))"
def test_kording_bug(self):
x, y = vectors('xy')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论