提交 f0f84950 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

merge

...@@ -110,7 +110,7 @@ class Test_pfunc(unittest.TestCase): ...@@ -110,7 +110,7 @@ class Test_pfunc(unittest.TestCase):
f = pfunc([Param(a, strict=False)], [out]) f = pfunc([Param(a, strict=False)], [out])
f(numpy.random.rand(8)) # works, rand generates float64 by default f(numpy.random.rand(8)) # works, rand generates float64 by default
f(numpy.array([1,2,3,4], dtype='int32')) # works, casting is allowed f(numpy.array([1,2,3,4], dtype='int32')) # works, casting is allowed
f = pfunc([Param(a, strict=True)], [out]) f = pfunc([Param(a, strict=True)], [out])
try: try:
f(numpy.array([1,2,3,4], dtype='int32')) # fails, f expects float64 f(numpy.array([1,2,3,4], dtype='int32')) # fails, f expects float64
...@@ -471,7 +471,7 @@ class Test_pfunc(unittest.TestCase): ...@@ -471,7 +471,7 @@ class Test_pfunc(unittest.TestCase):
a.default_update = a+3 a.default_update = a+3
c = a+ 10 c = a+ 10
f = pfunc([],c, givens = { a: a+10} ) f = pfunc([],c, givens = { a: a+10} )
assert f() == 21 assert f() == 21
assert f() == 34 assert f() == 34
...@@ -515,7 +515,36 @@ class Test_aliasing_rules(unittest.TestCase): ...@@ -515,7 +515,36 @@ class Test_aliasing_rules(unittest.TestCase):
# rule #2 reading back from theano-managed memory # rule #2 reading back from theano-managed memory
assert not numpy.may_share_memory(A.get_value(borrow=False), data_of(A)) assert not numpy.may_share_memory(A.get_value(borrow=False), data_of(A))
def test_potential_input_aliasing_affecting_inplace_operations(self):
## Note: to trigger this bug with theano rev 4586:2bc6fc7f218b,
# you need to make in inputs mutable ( so that inplace
# operations are used) and to break the elemwise composition
# with some non-elemwise op ( here dot )
x = theano.tensor.dvector()
y = theano.tensor.dvector()
m1 = theano.tensor.dmatrix()
m2 = theano.tensor.dmatrix()
f = theano.function( [theano.In(x, mutable = True),
theano.In(y, mutable = True),
theano.In(m1, mutable = True),
theano.In(m2, mutable = True)],
theano.dot(x*2,m1)+theano.dot(y*3,m2))
# Compute bogus values
v = numpy.asarray([1,2], dtype = 'float64')
m = numpy.asarray([[1,0],[0,1]], dtype = 'float64')
bogus_vals = f(v,v,m,m)
# Since we used inplace operation v and m may be corrupted
# so we need to recreate them
m = numpy.asarray([[1,0],[0,1]], dtype = 'float64')
v = numpy.asarray([1,2], dtype = 'float64')
m_copy = m.copy()
v_copy = v.copy()
vals = f(v,v_copy,m,m_copy)
assert numpy.allclose(vals, bogus_vals)
def test_potential_output_aliasing_induced_by_updates(self): def test_potential_output_aliasing_induced_by_updates(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论