提交 90789025 authored 作者: Frederic Bastien's avatar Frederic Bastien

test more case of may_share_memory

上级 8e303f5b
"""
test the tensor and sparse type. The CudaNdarray type is tested in sandbox/cuda/tests/test_tensor_op.py.test_may_share_memory_cuda
"""
import numpy import numpy
import theano import theano
...@@ -13,19 +17,34 @@ from theano.misc.may_share_memory import may_share_memory ...@@ -13,19 +17,34 @@ from theano.misc.may_share_memory import may_share_memory
def test_may_share_memory(): def test_may_share_memory():
a=numpy.random.rand(5,4) a=numpy.random.rand(5,4)
b=numpy.random.rand(5,4) b=numpy.random.rand(5,4)
as_ar = lambda a: theano._asarray(a, dtype='int32') va = a.view()
vb = b.view()
ra = a.reshape((4,5))
rb = b.reshape((4,5))
ta = a.T
tb = b.T
for a_,b_,rep in [(a,a,True),(b,b,True),(a,b,False), for a_,b_,rep in [(a,a,True),(b,b,True),(a,b,False),
(a,a[0],True),(a,a[:,0],True), (a,a[0],True),(a,a[:,0],True),(a,a.T,True),
(a,(0,),False),(a,1,False), (a,(0,),False),(a,1,False),(a,None,False),
(a,va,True),(b,vb,True),(va,b,False),(a,vb,False),
(a,ra,True),(b,rb,True),(ra,b,False),(a,rb,False),
(a,ta,True),(b,tb,True),(ta,b,False),(a,tb,False),
]: ]:
assert may_share_memory(a_,b_,False)==rep assert may_share_memory(a_,b_,False)==rep
assert may_share_memory(b_,a_,False)==rep
if rep == False: if rep == False:
try: try:
may_share_memory(a_,b_) may_share_memory(a_,b_)
raise Exception("An error was expected") raise Exception("An error was expected")
except: except:
pass pass
try:
may_share_memory(b_,a_)
raise Exception("An error was expected")
except:
pass
if scipy_imported: if scipy_imported:
def test_may_share_memory_scipy(): def test_may_share_memory_scipy():
...@@ -41,9 +60,15 @@ if scipy_imported: ...@@ -41,9 +60,15 @@ if scipy_imported:
]: ]:
assert may_share_memory(a_,b_)==rep assert may_share_memory(a_,b_)==rep
assert may_share_memory(b_,a_)==rep
if rep == False: if rep == False:
try: try:
may_share_memory(a_,b_) may_share_memory(a_,b_)
raise Exception("An error was expected") raise Exception("An error was expected")
except: except:
pass pass
try:
may_share_memory(b_,a_)
raise Exception("An error was expected")
except:
pass
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论