提交 f3d712ef authored 作者: AndreiCostinescu's avatar AndreiCostinescu

Changed comments to docstrings where necessary in theano/tensor/tests

上级 3b205e97
...@@ -23,7 +23,6 @@ def gen_data(): ...@@ -23,7 +23,6 @@ def gen_data():
np.asarray(np.random.rand(10000)*10, dtype='int64')) np.asarray(np.random.rand(10000)*10, dtype='int64'))
test_set = (np.asarray(np.random.rand(10000, 784), dtype='float32'), test_set = (np.asarray(np.random.rand(10000, 784), dtype='float32'),
np.asarray(np.random.rand(10000)*10, dtype='int64')) np.asarray(np.random.rand(10000)*10, dtype='int64'))
def shared_dataset(data_xy): def shared_dataset(data_xy):
""" Function that loads the dataset into shared variables """ Function that loads the dataset into shared variables
......
...@@ -46,8 +46,9 @@ def sharedX(x, name): ...@@ -46,8 +46,9 @@ def sharedX(x, name):
class t_gemm(TestCase): class t_gemm(TestCase):
# This test suite is supposed to establish that gemm works as it """
# is supposed to. This test suite is supposed to establish that gemm works as it is supposed to.
"""
def setUp(self): def setUp(self):
unittest_tools.seed_rng() unittest_tools.seed_rng()
...@@ -437,9 +438,11 @@ def fail(msg): ...@@ -437,9 +438,11 @@ def fail(msg):
assert False assert False
# This test suite ensures that Gemm is inserted where it belongs, and """
# that the resulting functions compute the same things as the This test suite ensures that Gemm is inserted where it belongs, and
# originals. that the resulting functions compute the same things as the originals.
"""
def XYZab(): def XYZab():
return T.matrix(), T.matrix(), T.matrix(), T.scalar(), T.scalar() return T.matrix(), T.matrix(), T.matrix(), T.scalar(), T.scalar()
......
...@@ -115,10 +115,12 @@ class TestCGer(TestCase, TestOptimizationMixin): ...@@ -115,10 +115,12 @@ class TestCGer(TestCase, TestOptimizationMixin):
class TestCGemv(TestCase, TestOptimizationMixin): class TestCGemv(TestCase, TestOptimizationMixin):
# Tests of CGemv specifically. """
# Generic tests of Gemv-compatibility, including both dtypes are Tests of CGemv specifically.
# done below in TestCGemvFloat32 and TestCGemvFloat64
Generic tests of Gemv-compatibility, including both dtypes are
done below in TestCGemvFloat32 and TestCGemvFloat64
"""
def setUp(self, dtype='float64'): def setUp(self, dtype='float64'):
# This tests can run even when theano.config.blas.ldflags is empty. # This tests can run even when theano.config.blas.ldflags is empty.
self.dtype = dtype self.dtype = dtype
......
...@@ -7,19 +7,20 @@ import theano.tensor as tt ...@@ -7,19 +7,20 @@ import theano.tensor as tt
class Test_inc_subtensor(unittest.TestCase): class Test_inc_subtensor(unittest.TestCase):
# Partial testing. """
# Partial testing.
# What could be tested:
# - increment vs set What could be tested:
# - thing incremented: scalar, vector, matrix, - increment vs set
# - increment/set: constant, scalar, vector, matrix - thing incremented: scalar, vector, matrix,
# - indices: scalar vs slice, constant vs variable, out of bound, ... - increment/set: constant, scalar, vector, matrix
# - inplace - indices: scalar vs slice, constant vs variable, out of bound, ...
# - inplace
# NOTE: these are the same tests as test_incsubtensor.py, but using
# the new (read: not deprecated) inc_subtensor, set_subtensor NOTE: these are the same tests as test_incsubtensor.py, but using
# functions. the new (read: not deprecated) inc_subtensor, set_subtensor
functions.
"""
def setUp(self): def setUp(self):
utt.seed_rng() utt.seed_rng()
......
...@@ -276,19 +276,20 @@ def test_det_shape(): ...@@ -276,19 +276,20 @@ def test_det_shape():
class test_diag(unittest.TestCase): class test_diag(unittest.TestCase):
# Test that linalg.diag has the same behavior as numpy.diag. """
# numpy.diag has two behaviors: Test that linalg.diag has the same behavior as numpy.diag.
# (1) when given a vector, it returns a matrix with that vector as the numpy.diag has two behaviors:
# diagonal. (1) when given a vector, it returns a matrix with that vector as the
# (2) when given a matrix, returns a vector which is the diagonal of the diagonal.
# matrix. (2) when given a matrix, returns a vector which is the diagonal of the
# matrix.
# (1) and (2) are tested by test_alloc_diag and test_extract_diag
# respectively. (1) and (2) are tested by test_alloc_diag and test_extract_diag
# respectively.
# test_diag test makes sure that linalg.diag instantiates
# the right op based on the dimension of the input. test_diag test makes sure that linalg.diag instantiates
the right op based on the dimension of the input.
"""
def __init__(self, name, mode=None, shared=tensor._shared, def __init__(self, name, mode=None, shared=tensor._shared,
floatX=None, type=tensor.TensorType): floatX=None, type=tensor.TensorType):
self.mode = mode self.mode = mode
......
...@@ -904,10 +904,11 @@ class test_fusion(unittest.TestCase): ...@@ -904,10 +904,11 @@ class test_fusion(unittest.TestCase):
topo_exclude = () topo_exclude = ()
def do(self, mode, shared_fn, shp, nb_repeat=1, assert_len_topo=True, slice=None): def do(self, mode, shared_fn, shp, nb_repeat=1, assert_len_topo=True, slice=None):
# param shared_fn: if None, will use compile.function """
# verify that the elemwise fusion work param shared_fn: if None, will use compile.function
# Test with and without DimShuffle verify that the elemwise fusion work
Test with and without DimShuffle
"""
# TODO: disable the canonizer? # TODO: disable the canonizer?
def my_init(shp, dtype='float64', num=0): def my_init(shp, dtype='float64', num=0):
ret = np.zeros(shp, dtype=dtype) + num ret = np.zeros(shp, dtype=dtype) + num
...@@ -1217,8 +1218,10 @@ class test_fusion(unittest.TestCase): ...@@ -1217,8 +1218,10 @@ class test_fusion(unittest.TestCase):
dlogp(2, np.random.rand(n)) dlogp(2, np.random.rand(n))
def speed_fusion(self, s=None): def speed_fusion(self, s=None):
# param type s: a slice object """
# param s: a slice to apply to the case to execute. If None, exec all case. param type s: a slice object
param s: a slice to apply to the case to execute. If None, exec all case.
"""
shp = (3000, 3000) shp = (3000, 3000)
shp = (1000, 1000) shp = (1000, 1000)
...@@ -1274,10 +1277,12 @@ class test_fusion(unittest.TestCase): ...@@ -1274,10 +1277,12 @@ class test_fusion(unittest.TestCase):
class TimesN(theano.scalar.basic.UnaryScalarOp): class TimesN(theano.scalar.basic.UnaryScalarOp):
# Used in test TestCompositeCodegen """
# Must be outside of the class, otherwise, the c cache code can't Used in test TestCompositeCodegen
# pickle this class and this cause stuff printing during test.
Must be outside of the class, otherwise, the c cache code can't
pickle this class and this cause stuff printing during test.
"""
def __eq__(self, other): def __eq__(self, other):
return super(TimesN, self).__eq__(other) and self.n == other.n return super(TimesN, self).__eq__(other) and self.n == other.n
...@@ -1304,9 +1309,10 @@ class TimesN(theano.scalar.basic.UnaryScalarOp): ...@@ -1304,9 +1309,10 @@ class TimesN(theano.scalar.basic.UnaryScalarOp):
class TestCompositeCodegen(unittest.TestCase): class TestCompositeCodegen(unittest.TestCase):
# Test The Composite Ops code generation in a case where there is multiple """
# scalar ops with support code. Test The Composite Ops code generation in a case where there is multiple
scalar ops with support code.
"""
def setUp(self): def setUp(self):
upgrade_to_float = theano.scalar.basic.upgrade_to_float upgrade_to_float = theano.scalar.basic.upgrade_to_float
...@@ -3911,12 +3917,13 @@ class test_shapeoptimizer(unittest.TestCase): ...@@ -3911,12 +3917,13 @@ class test_shapeoptimizer(unittest.TestCase):
@staticmethod @staticmethod
def max_pool_c01b(c01b, pool_shp, pool_stride, img_shp): def max_pool_c01b(c01b, pool_shp, pool_stride, img_shp):
# Like max_pool but with input using axes ('c', 0, 1, 'b') """
# (Alex Krizhevsky format) Like max_pool but with input using axes ('c', 0, 1, 'b')
# (Alex Krizhevsky format)
# pool_shp, pool_stride and img_shp are int that represent
# the same shp in x and y.
pool_shp, pool_stride and img_shp are int that represent
the same shp in x and y.
"""
mx = None mx = None
# Compute index in pooled space of last needed pool # Compute index in pooled space of last needed pool
...@@ -4675,11 +4682,12 @@ class T_local_switch_sink(unittest.TestCase): ...@@ -4675,11 +4682,12 @@ class T_local_switch_sink(unittest.TestCase):
self.mode.check_isfinite = False self.mode.check_isfinite = False
def function_remove_nan(self, *args, **kwargs): def function_remove_nan(self, *args, **kwargs):
# Wrapper around theano.function for this test. """
# It disables checking Wrapper around theano.function for this test.
# for NaN removed by optimizations in DebugMode (it has false
# positives in that case).
It disables checking for NaN removed by optimizations in DebugMode
(it has false positives in that case).
"""
f = theano.function(*args, **kwargs) f = theano.function(*args, **kwargs)
def wrapped_f(*args, **kwargs): def wrapped_f(*args, **kwargs):
...@@ -5200,8 +5208,9 @@ class test_local_merge_switch_same_cond(unittest.TestCase): ...@@ -5200,8 +5208,9 @@ class test_local_merge_switch_same_cond(unittest.TestCase):
class T_local_sum_prod(unittest.TestCase): class T_local_sum_prod(unittest.TestCase):
# Test sum/prod opts in opt.py """
Test sum/prod opts in opt.py
"""
def setUp(self): def setUp(self):
self.mode = theano.compile.get_default_mode().including('canonicalize', self.mode = theano.compile.get_default_mode().including('canonicalize',
'specialize') 'specialize')
......
...@@ -29,35 +29,36 @@ def makeSharedTester(shared_constructor_, ...@@ -29,35 +29,36 @@ def makeSharedTester(shared_constructor_,
cast_value_=np.asarray, cast_value_=np.asarray,
expect_fail_fast_shape_inplace=True, expect_fail_fast_shape_inplace=True,
): ):
# This is a generic fct to allow reusing the same test function """
# for many shared variable of many types. This is a generic fct to allow reusing the same test function
# for many shared variable of many types.
# :param shared_constructor_: The shared variable constructor to use
# :param dtype_: The dtype of the data to test :param shared_constructor_: The shared variable constructor to use
# :param get_value_borrow_true_alias_: Should a get_value(borrow=True) return the internal object :param dtype_: The dtype of the data to test
# :param shared_borrow_true_alias_: Should shared(val,borrow=True) reuse the val memory space :param get_value_borrow_true_alias_: Should a get_value(borrow=True) return the internal object
# :param set_value_borrow_true_alias_: Should set_value(val,borrow=True) reuse the val memory space :param shared_borrow_true_alias_: Should shared(val,borrow=True) reuse the val memory space
# :param set_value_inplace_: Should this shared variable overwrite the current :param set_value_borrow_true_alias_: Should set_value(val,borrow=True) reuse the val memory space
# memory when the new value is an ndarray :param set_value_inplace_: Should this shared variable overwrite the current
# :param set_cast_value_inplace_: Should this shared variable overwrite the memory when the new value is an ndarray
# current memory when the new value is of the same :param set_cast_value_inplace_: Should this shared variable overwrite the
# type as the internal type. current memory when the new value is of the same
# :param shared_constructor_accept_ndarray_: Do the shared_constructor accept an ndarray as input? type as the internal type.
# :param internal_type_: The internal type used. :param shared_constructor_accept_ndarray_: Do the shared_constructor accept an ndarray as input?
# :param test_internal_type_: A function that tell if its input is of the same :param internal_type_: The internal type used.
# type as this shared variable internal type. :param test_internal_type_: A function that tell if its input is of the same
# :param theano_fct_: A theano op that will be used to do some computation on the shared variable type as this shared variable internal type.
# :param ref_fct_: A reference function that should return the same value as the theano_fct_ :param theano_fct_: A theano op that will be used to do some computation on the shared variable
# :param cast_value_: A callable that cast an ndarray into the internal shared variable representation :param ref_fct_: A reference function that should return the same value as the theano_fct_
# :param name: This string is used to set the returned class' __name__ :param cast_value_: A callable that cast an ndarray into the internal shared variable representation
# attribute. This is needed for nosetests to properly tag the :param name: This string is used to set the returned class' __name__
# test with its correct name, rather than use the generic attribute. This is needed for nosetests to properly tag the
# SharedTester name. This parameter is mandatory (keeping the test with its correct name, rather than use the generic
# default None value will raise an error), and must be set to SharedTester name. This parameter is mandatory (keeping the
# the name of the variable that will hold the returned class. default None value will raise an error), and must be set to
# :note: the name of the variable that will hold the returned class.
# We must use /= as sparse type don't support other inplace operation. :note:
We must use /= as sparse type don't support other inplace operation.
"""
class m(type): class m(type):
pass pass
......
...@@ -45,9 +45,9 @@ else: ...@@ -45,9 +45,9 @@ else:
class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin): class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
# This is build in a way that allow to reuse it to test the """
# equivalent gpu op. This is build in a way that allow to reuse it to test the equivalent gpu op.
"""
def __init__(self, name, shared=tensor._shared, def __init__(self, name, shared=tensor._shared,
sub=tensor.Subtensor, sub=tensor.Subtensor,
inc_sub=tensor.IncSubtensor, inc_sub=tensor.IncSubtensor,
...@@ -84,12 +84,13 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -84,12 +84,13 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
def function(self, inputs, outputs, accept_inplace=False, def function(self, inputs, outputs, accept_inplace=False,
op=None, mode=None, N=1, N_fast=None): op=None, mode=None, N=1, N_fast=None):
# wrapper around theano.function that also check the output """
# wrapper around theano.function that also check the output
# :param N: the number of op expected in the toposort
# if tuple of length 2, (expected if fast_compile,
# if not fast_compile)
:param N: the number of op expected in the toposort
if tuple of length 2, (expected if fast_compile,
if not fast_compile)
"""
if self.fast_compile and N_fast is not None: if self.fast_compile and N_fast is not None:
N = N_fast N = N_fast
if mode is None: if mode is None:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论