提交 83d3075f authored 作者: Dustin Webb's avatar Dustin Webb 提交者: Amjad Almahairi

Added some tests for the new optimizations.

上级 2e539adb
......@@ -3924,6 +3924,38 @@ class T_useless_elemwise(unittest.TestCase):
assert len(topo) == 1
assert topo[0].op == deep_copy_op
def assert_eqs_const(self, topo, val):
elem = topo[0]
assert len(topo) == 1
assert elem.op == deep_copy_op
assert len(elem.inputs) == 1
assert isinstance(elem.inputs[0], T.TensorConstant)
assert T.extract_constant(elem.inputs[0]) == val
def test_and(self):
x = T.scalar('x', dtype='int64')
func = theano.function([x], T.and_(x, 0), mode=self.mode)
self.assert_eqs_const(func.maker.fgraph.toposort(), 0)
func = theano.function([x], T.and_(0, x), mode=self.mode)
self.assert_eqs_const(func.maker.fgraph.toposort(), 0)
def test_or(self):
x = T.scalar('x', dtype='int64')
func = theano.function([x], T.or_(x, 1), mode=self.mode)
self.assert_eqs_const(func.maker.fgraph.toposort(), 1)
func = theano.function([x], T.or_(1, x), mode=self.mode)
self.assert_eqs_const(func.maker.fgraph.toposort(), 1)
def test_xor(self):
x = T.scalar('x', dtype='int64')
func = theano.function([x], T.xor(x, x), mode=self.mode)
self.assert_eqs_const(func.maker.fgraph.toposort(), 0)
class T_cast_cast(unittest.TestCase):
def setUp(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论