def test_destroyers_loop(): # AddInPlace(x, y) and AddInPlace(y, x) should not coexist x, y, z = inputs() e1 = add(x, y) e2 = add(y, x) g = Env([x,y,z], [e1, e2]) chk = g.checkpoint() consistent(g) g.replace_validate(e1, add_in_place(x, y)) consistent(g) try: g.replace_validate(e2, add_in_place(y, x)) raise Exception("Shouldn't have reached this point.") except InconsistencyError: pass consistent(g) g.revert(chk) g.replace_validate(e2, add_in_place(y, x)) consistent(g) try: g.replace_validate(e1, add_in_place(x, y)) raise Exception("Shouldn't have reached this point.") except InconsistencyError: pass consistent(g)
def test_misc(): x, y, z = inputs() e = transpose_view(transpose_view(transpose_view(transpose_view(x)))) g = Env([x,y,z], [e]) consistent(g) chk = g.checkpoint() PatternOptimizer((transpose_view, (transpose_view, 'x')), 'x').optimize(g) assert str(g) == "[x]" new_e = add(x,y) g.replace_validate(x, new_e) assert str(g) == "[Add(x, y)]" g.replace(new_e, dot(add_in_place(x,y), transpose_view(x))) assert str(g) == "[Dot(AddInPlace(x, y), TransposeView(x))]" inconsistent(g) g.revert(chk) consistent(g) assert str(g) == "[TransposeView(TransposeView(TransposeView(TransposeView(x))))]"