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

Add test for {Tensor,CudaNdarray,Sparse}Type.value_eq[_approx].

上级 ed61205c
...@@ -919,7 +919,7 @@ test_shared_options = theano.tensor.tests.test_sharedvar.makeSharedTester( ...@@ -919,7 +919,7 @@ test_shared_options = theano.tensor.tests.test_sharedvar.makeSharedTester(
test_internal_type_ = lambda a: isinstance(a,cuda_ndarray.CudaNdarray), test_internal_type_ = lambda a: isinstance(a,cuda_ndarray.CudaNdarray),
theano_fct_ = theano.tensor.exp, theano_fct_ = theano.tensor.exp,
ref_fct_ = numpy.exp, ref_fct_ = numpy.exp,
cast_value_ = cuda_ndarray.CudaNdarray, cast_value_ = cuda.as_cuda_array,
op_by_matrix_ = True) op_by_matrix_ = True)
#This test the case when the shared constructor view an ndarray as input #This test the case when the shared constructor view an ndarray as input
......
...@@ -575,6 +575,35 @@ def makeSharedTester(shared_constructor_, ...@@ -575,6 +575,35 @@ def makeSharedTester(shared_constructor_,
assert sum([node.op.__class__.__name__ in ["Gemm","GpuGemm","StructuredDot"] for node in topo])==1 assert sum([node.op.__class__.__name__ in ["Gemm","GpuGemm","StructuredDot"] for node in topo])==1
assert all(node.op == tensor.blas.gemm_inplace for node in topo if isinstance(node.op,tensor.blas.Gemm)) assert all(node.op == tensor.blas.gemm_inplace for node in topo if isinstance(node.op,tensor.blas.Gemm))
assert all(node.op.inplace for node in topo if node.op.__class__.__name__ == "GpuGemm") assert all(node.op.inplace for node in topo if node.op.__class__.__name__ == "GpuGemm")
def test_values_eq(self):
""" Test the type.values_eq[_approx] function"""
dtype = self.dtype
if dtype is None:
dtype = theano.config.floatX
# We need big shape as in the past there have been a bug in the
# sparse values_eq_approx.
shp = (1024,1024)
#Test the case with all zeros element
for x in [numpy.asarray(numpy.random.rand(*shp), dtype=dtype),
numpy.zeros(shp, dtype=dtype)]:
zeros = (x==0).all()
x = self.cast_value(x)
x_shared = self.shared_constructor(x, borrow=True)
y = x.copy()
y[0,0],y[1,0] = y[1,0],y[0,0]
y = self.cast_value(y)
assert x_shared.type.values_eq(x, x)
assert x_shared.type.values_eq_approx(x, x)
if not zeros:
assert not numpy.allclose(self.ref_fct(x), self.ref_fct(y))
assert not x_shared.type.values_eq(x, y)
assert not x_shared.type.values_eq_approx(x, y)
return SharedTester return SharedTester
...@@ -590,6 +619,6 @@ test_shared_options=makeSharedTester( ...@@ -590,6 +619,6 @@ test_shared_options=makeSharedTester(
internal_type_ = numpy.ndarray, internal_type_ = numpy.ndarray,
test_internal_type_ = lambda a: isinstance(a,numpy.ndarray), test_internal_type_ = lambda a: isinstance(a,numpy.ndarray),
theano_fct_ = theano.tensor.sum, theano_fct_ = theano.tensor.sum,
ref_fct_ = numpy.sum, ref_fct_ = lambda a: numpy.asarray((a*2)),
cast_value_ = numpy.asarray, cast_value_ = numpy.asarray,
op_by_matrix_ = False) op_by_matrix_ = False)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论