提交 0a029e57 authored 作者: Pascal Lamblin's avatar Pascal Lamblin 提交者: Frederic Bastien

Add more direct tests for the scalar and the elemwise Ops

上级 8d3412b5
...@@ -154,6 +154,17 @@ class test_composite(unittest.TestCase): ...@@ -154,6 +154,17 @@ class test_composite(unittest.TestCase):
si3 = theano.scalar.float32() si3 = theano.scalar.float32()
sop.make_node(si0 * si3, si1, si2) sop.make_node(si0 * si3, si1, si2)
def test_composite_neg_bool(self):
# Check that taking the negation of a Boolean intermediate value
# works correctly with Python code. It used to be an issue because
# `-numpy.bool_(True)` is False and `-numpy.bool_(False)` is True.
x = floats('x')
y = - (x > 0)
z = Composite([x], [y]).make_node(x).outputs[0]
f = theano.function([x], z, mode=theano.Mode(linker='py'))
for inp, out in zip([-1, 0, 1], [0, 0, -1]):
self.assertTrue(f(inp) == out)
class test_logical(unittest.TestCase): class test_logical(unittest.TestCase):
def test_gt(self): def test_gt(self):
......
...@@ -8105,6 +8105,15 @@ def test_symbolic_slice(): ...@@ -8105,6 +8105,15 @@ def test_symbolic_slice():
output = a.eval({x: numpy.zeros((5, 4, 3, 2), dtype=theano.config.floatX)}) output = a.eval({x: numpy.zeros((5, 4, 3, 2), dtype=theano.config.floatX)})
assert output == numpy.array(5) assert output == numpy.array(5)
def test_composite_neg_bool():
# Check that taking the negation of a Boolean intermediate value
# works correctly with Python code. It used to be an issue because
# `-numpy.bool_(True)` is False and `-numpy.bool_(False)` is True.
x = theano.tensor.vector()
f = theano.function([x], - (x > 0), mode=theano.Mode(linker='py'))
utt.assert_allclose(f([-1, 0, 1]), [0, 0, -1])
""" """
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论