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

make code more clear following code review: changed some variable name and use named argument.

上级 8f047057
...@@ -832,7 +832,7 @@ test_shared_options = theano.tensor.tests.test_sharedvar.makeSharedTester( ...@@ -832,7 +832,7 @@ test_shared_options = theano.tensor.tests.test_sharedvar.makeSharedTester(
theano_fct_ = theano.tensor.exp, theano_fct_ = theano.tensor.exp,
ref_fct_ = numpy.exp, ref_fct_ = numpy.exp,
cast_value_ = numpy.asarray, cast_value_ = numpy.asarray,
add_matrix_ = True) op_by_matrix_ = True)
if __name__ == '__main__': if __name__ == '__main__':
test_many_arg_elemwise() test_many_arg_elemwise()
......
...@@ -501,11 +501,17 @@ def test_may_share_memory(): ...@@ -501,11 +501,17 @@ def test_may_share_memory():
import theano.tensor.tests.test_sharedvar import theano.tensor.tests.test_sharedvar
test_shared_options=theano.tensor.tests.test_sharedvar.makeSharedTester( test_shared_options=theano.tensor.tests.test_sharedvar.makeSharedTester(
theano.sparse.shared, 'float64', shared_constructor_ = theano.sparse.shared,
True, True, True, scipy.sparse.csc_matrix, scipy.sparse.issparse, dtype_ = 'float64',
lambda a: dense_from_sparse(a*2.), get_value_borrow_true_alias_ = True,
lambda a: numpy.asarray((a*2).todense()), shared_borrow_true_alias_ = True,
scipy.sparse.csr_matrix) set_value_borrow_true_alias_ = True,
internal_type_ = scipy.sparse.csc_matrix,
test_internal_type_ = scipy.sparse.issparse,
theano_fct_ = lambda a: dense_from_sparse(a*2.),
ref_fct_ = lambda a: numpy.asarray((a*2).todense()),
cast_value_ = scipy.sparse.csr_matrix)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -17,7 +17,7 @@ def makeSharedTester(shared_constructor_, ...@@ -17,7 +17,7 @@ def makeSharedTester(shared_constructor_,
theano_fct_, theano_fct_,
ref_fct_, ref_fct_,
cast_value_ = numpy.asarray, cast_value_ = numpy.asarray,
add_matrix_ = False): op_by_matrix_ = False):
""" """
This is a generic fct to allow reusing the same test function This is a generic fct to allow reusing the same test function
for many shared variable of many types. for many shared variable of many types.
...@@ -35,7 +35,7 @@ def makeSharedTester(shared_constructor_, ...@@ -35,7 +35,7 @@ def makeSharedTester(shared_constructor_,
ref_fct = staticmethod(ref_fct_) ref_fct = staticmethod(ref_fct_)
set_value_borrow_true_alias = set_value_borrow_true_alias_ set_value_borrow_true_alias = set_value_borrow_true_alias_
cast_value = staticmethod(cast_value_) cast_value = staticmethod(cast_value_)
add_matrix = add_matrix_ op_by_matrix = op_by_matrix_
def test_shared_dont_alias(self): def test_shared_dont_alias(self):
dtype = self.dtype dtype = self.dtype
...@@ -146,12 +146,12 @@ def makeSharedTester(shared_constructor_, ...@@ -146,12 +146,12 @@ def makeSharedTester(shared_constructor_,
x = x_shared.get_value(borrow = True, return_internal_type = True) x = x_shared.get_value(borrow = True, return_internal_type = True)
assert self.test_internal_type(x) assert self.test_internal_type(x)
values_to_add = .5 values_to_div = .5
if self.add_matrix: if self.op_by_matrix:
#supported for cudandarray, but not ndarray. #supported for cudandarray, but not ndarray.
values_to_add = self.internal_type( values_to_div = self.internal_type(
numpy.ones(x.shape,dtype=dtype)/2) numpy.ones(x.shape,dtype=dtype)/2)
x /= values_to_add#supported by ndarray and CudaNdarray x /= values_to_div#supported by ndarray and CudaNdarray
#this is not required by the contract but it is a feature we can #this is not required by the contract but it is a feature we can
#implement for some type of SharedVariable. #implement for some type of SharedVariable.
...@@ -160,7 +160,7 @@ def makeSharedTester(shared_constructor_, ...@@ -160,7 +160,7 @@ def makeSharedTester(shared_constructor_,
x = x_shared.get_value(borrow = False, return_internal_type = True) x = x_shared.get_value(borrow = False, return_internal_type = True)
assert self.test_internal_type(x) assert self.test_internal_type(x)
assert x is not x_shared.container.value assert x is not x_shared.container.value
x /= values_to_add#supported by ndarray and CudaNdarray x /= values_to_div#supported by ndarray and CudaNdarray
#this is required by the contract #this is required by the contract
assert not numpy.allclose(self.ref_fct(x), total_func()) assert not numpy.allclose(self.ref_fct(x), total_func())
...@@ -198,12 +198,12 @@ def makeSharedTester(shared_constructor_, ...@@ -198,12 +198,12 @@ def makeSharedTester(shared_constructor_,
get_x = x_shared.get_value(borrow=True, return_internal_type=True) get_x = x_shared.get_value(borrow=True, return_internal_type=True)
assert get_x is not x_orig#borrow=False to shared_constructor assert get_x is not x_orig#borrow=False to shared_constructor
assert self.test_internal_type(get_x) assert self.test_internal_type(get_x)
values_to_add = .5 values_to_div = .5
if self.add_matrix: if self.op_by_matrix:
values_to_add = self.internal_type(numpy.ones(x.shape,dtype=dtype)/2)#supported for cudandarray, but not ndarray. 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_add) assert self.test_internal_type(values_to_div)
get_x /= values_to_add#supported by ndarray and CudaNdarray get_x /= values_to_div#supported by ndarray and CudaNdarray
assert self.test_internal_type(get_x) assert self.test_internal_type(get_x)
x_shared.set_value(get_x, borrow=True) x_shared.set_value(get_x, borrow=True)
x = x_shared.get_value(borrow=True, return_internal_type=True) x = x_shared.get_value(borrow=True, return_internal_type=True)
...@@ -420,4 +420,4 @@ test_shared_options=makeSharedTester( ...@@ -420,4 +420,4 @@ test_shared_options=makeSharedTester(
theano_fct_ = theano.tensor.sum, theano_fct_ = theano.tensor.sum,
ref_fct_ = numpy.sum, ref_fct_ = numpy.sum,
cast_value_ = numpy.asarray, cast_value_ = numpy.asarray,
add_matrix_ = False) op_by_matrix_ = False)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论