def test_low_use_ratio(self): x, y, z = map(MyVariable, 'xyz') e = op3(op4(x, y)) g = FunctionGraph([x, y, z], [e]) # print 'before', g # display pesky warnings along with stdout # also silence logger for 'theano.gof.opt' _logger = logging.getLogger('theano.gof.opt') oldlevel = _logger.level _logger.setLevel(logging.CRITICAL) try: opt = EquilibriumOptimizer( [PatternSub((op1, 'x', 'y'), (op2, 'x', 'y')), PatternSub((op4, 'x', 'y'), (op1, 'x', 'y')), PatternSub((op3, (op2, 'x', 'y')), (op4, 'x', 'y')) ], max_use_ratio=1. / len(g.apply_nodes)) # each opt can only be applied once opt.optimize(g) finally: _logger.setLevel(oldlevel) # print 'after', g assert str(g) == '[Op1(x, y)]'
def test_low_use_ratio(self): x, y, z = map(MyVariable, "xyz") e = op3(op4(x, y)) g = FunctionGraph([x, y, z], [e]) # print 'before', g # display pesky warnings along with stdout # also silence logger for 'theano.gof.opt' _logger = logging.getLogger("theano.gof.opt") oldlevel = _logger.level _logger.setLevel(logging.CRITICAL) try: opt = EquilibriumOptimizer( [ PatternSub((op1, "x", "y"), (op2, "x", "y")), PatternSub((op4, "x", "y"), (op1, "x", "y")), PatternSub((op3, (op2, "x", "y")), (op4, "x", "y")), ], max_use_ratio=1.0 / len(g.apply_nodes), ) # each opt can only be applied once opt.optimize(g) finally: _logger.setLevel(oldlevel) # print 'after', g assert str(g) == "FunctionGraph(Op1(x, y))"