def test_elemwise(self):
# float Ops
mats = theano.tensor.matrices('cabxy')
c, a, b, x, y = mats
s1 = T.switch(c, a, b)
s2 = T.switch(c, x, y)
for op in (T.add, T.sub, T.mul, T.true_div, T.int_div, T.floor_div,
T.minimum, T.maximum, T.gt, T.lt, T.ge, T.le, T.eq, T.neq,
T.pow):
g = optimize(FunctionGraph(mats, [op(s1, s2)]))
assert str(g).count('Switch') == 1
# integer Ops
mats = theano.tensor.imatrices('cabxy')
c, a, b, x, y = mats
s1 = T.switch(c, a, b)
s2 = T.switch(c, x, y)
for op in (T.and_, T.or_, T.xor,
T.bitwise_and, T.bitwise_or, T.bitwise_xor):
g = optimize(FunctionGraph(mats, [op(s1, s2)]))
assert str(g).count('Switch') == 1
# add/mul with more than two inputs
u, v = theano.tensor.matrices('uv')
s3 = T.switch(c, u, v)
for op in (T.add, T.mul):
g = optimize(FunctionGraph(mats + [u, v], [op(s1, s2, s3)]))
assert str(g).count('Switch') == 1
评论列表
文章目录