提交 683ea133 authored 作者: Caglar's avatar Caglar

fixed the unit tests.

上级 a85b58d3
...@@ -56,19 +56,9 @@ class test_ScalarOps(unittest.TestCase): ...@@ -56,19 +56,9 @@ class test_ScalarOps(unittest.TestCase):
): ):
self.assertTrue(fn(a,b) == a%b, (a,)) self.assertTrue(fn(a,b) == a%b, (a,))
def test_clip(self):
x, y, z = inputs()
a = clip(x, y, z)
fn = gof.DualLinker().accept(FunctionGraph([x, y, z], [a])).make_function()
numpy.random.seed(1)
xval = numpy.random.rand(1)
yval = numpy.random.rand(1)
zval = numpy.random.rand(1)
aval = fn(xval, yval, zval)
np_aval = numpy.clip(xval, yval, zval)
self.assertTrue(aval == np_aval)
def test_clip_grad(self): def test_clip_grad(self):
#This is testing for the issue #633
x, y = floats('xy') x, y = floats('xy')
a = theano.tensor.clip(x, y, x) a = theano.tensor.clip(x, y, x)
g = theano.gradient.grad(a, x) g = theano.gradient.grad(a, x)
...@@ -78,14 +68,22 @@ class test_ScalarOps(unittest.TestCase): ...@@ -78,14 +68,22 @@ class test_ScalarOps(unittest.TestCase):
a2 = theano.tensor.clip(x, x, y) a2 = theano.tensor.clip(x, x, y)
g2 = theano.gradient.grad(a2, x) g2 = theano.gradient.grad(a2, x)
fn2 = gof.DualLinker().accept(FunctionGraph([x, y], [g2])).make_function() fn2 = gof.DualLinker().accept(FunctionGraph([x, y], [g2])).make_function()
rng = numpy.random.RandomState(1)
ntests = 3
for i in xrange(ntests):
xval = rng.rand(1)
#To ensure that the min is smaller than the value for x.
yval_mn = rng.rand(1) - 0.5
#To ensure that the max is larger than the value for y.
yval_mx = rng.rand(1) + 0.5
aval = fn(xval, yval_mn)
aval2 = fn2(xval, yval_mx)
numpy.random.seed(1) self.assertTrue(aval == 1.)
xval = numpy.random.rand(1).astype("int64") self.assertTrue(aval2 == 1.)
yval = numpy.random.rand(1).astype("int64")
aval = fn(xval, yval)
aval2 = fn2(xval, yval)
self.assertTrue(aval == 1)
self.assertTrue(aval2 == 1)
class test_composite(unittest.TestCase): class test_composite(unittest.TestCase):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论