提交 14a5a805 authored 作者: Frederic Bastien's avatar Frederic Bastien

make test about CudaNdarray shared variable work when the original data is already a CudaNdarray.

上级 f5dcfd94
......@@ -830,14 +830,14 @@ test_shared_options = theano.tensor.tests.test_sharedvar.makeSharedTester(
shared_constructor_ = tcn.shared_constructor,
dtype_ = 'float32',
get_value_borrow_true_alias_ = False,
shared_borrow_true_alias_ = False,
shared_borrow_true_alias_ = True,#True when the original value is already a CudaNdarray!
set_value_borrow_true_alias_ = False,
set_value_inplace_ = True,
internal_type_ = cuda_ndarray.CudaNdarray,
test_internal_type_ = lambda a: isinstance(a,cuda_ndarray.CudaNdarray),
theano_fct_ = theano.tensor.exp,
ref_fct_ = numpy.exp,
cast_value_ = numpy.asarray,
cast_value_ = cuda_ndarray.CudaNdarray,
op_by_matrix_ = True)
if __name__ == '__main__':
......
......@@ -59,8 +59,11 @@ def makeSharedTester(shared_constructor_,
assert numpy.allclose(self.ref_fct(x), total_val)
x /= .5
values_to_div = .5
if self.op_by_matrix:
values_to_div = self.internal_type(numpy.ones(x.shape,dtype=dtype)/2)#supported for cudandarray, but not ndarray.
assert self.test_internal_type(values_to_div)
x /= values_to_div
total_val_2 = total_func()
#value used to construct should not alias with internal
......@@ -195,7 +198,7 @@ def makeSharedTester(shared_constructor_,
assert x is get_x
else:
assert x is not get_x
assert numpy.allclose(self.ref_fct(x_orig/.5),self.ref_fct(x))
assert numpy.allclose(self.ref_fct(numpy.asarray(x_orig)/.5),self.ref_fct(x))
#test optimized get set value on the gpu(don't pass data to the cpu)
get_x = x_shared.get_value(borrow=True, return_internal_type=True)
......@@ -234,7 +237,12 @@ def makeSharedTester(shared_constructor_,
assert numpy.allclose(self.ref_fct(x), total_val)
x /= .5
values_to_div = .5
if self.op_by_matrix:
#supported for cudandarray, but not ndarray.
values_to_div = self.internal_type(numpy.ones(x.shape,dtype=dtype)/2)
assert self.test_internal_type(values_to_div)
x /= values_to_div
#not required by the contract but it is a feature we've implemented
if self.shared_borrow_true_alias:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论