提交 0260d1b6 authored 作者: AndreiCostinescu's avatar AndreiCostinescu

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

上级 6c5071c9
...@@ -98,31 +98,30 @@ def random_lil(shape, dtype, nnz): ...@@ -98,31 +98,30 @@ def random_lil(shape, dtype, nnz):
def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None, def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None,
explicit_zero=False, unsorted_indices=False): explicit_zero=False, unsorted_indices=False):
# Return a tuple containing everything needed to """
# perform a test. Return a tuple containing everything needed to perform a test.
#
# If `out_dtype` is `None`, theano.config.floatX is If `out_dtype` is `None`, theano.config.floatX is used.
# used.
# :param format: Sparse format.
# :param format: Sparse format. :param shape: Shape of data.
# :param shape: Shape of data. :param n: Number of variable.
# :param n: Number of variable. :param out_dtype: dtype of output.
# :param out_dtype: dtype of output. :param p: Sparsity proportion.
# :param p: Sparsity proportion. :param gap: Tuple for the range of the random sample. When
# :param gap: Tuple for the range of the random sample. When length is 1, it is assumed to be the exclusive
# length is 1, it is assumed to be the exclusive max, when `gap` = (`a`, `b`) it provide a sample
# max, when `gap` = (`a`, `b`) it provide a sample from [a, b[. If `None` is used, it provide [0, 1]
# from [a, b[. If `None` is used, it provide [0, 1] for float dtypes and [0, 50[ for integer dtypes.
# for float dtypes and [0, 50[ for integer dtypes. :param explicit_zero: When True, we add explicit zero in the
# :param explicit_zero: When True, we add explicit zero in the returned sparse matrix
# returned sparse matrix :param unsorted_indices: when True, we make sure there is
# :param unsorted_indices: when True, we make sure there is unsorted indices in the returned
# unsorted indices in the returned sparse matrix.
# sparse matrix. :return: (variable, data) where both `variable` and `data` are list.
# :return: (variable, data) where both `variable`
# and `data` are list. :note: explicit_zero and unsorted_indices was added in Theano 0.6rc4
# """
# :note: explicit_zero and unsorted_indices was added in Theano 0.6rc4
if out_dtype is None: if out_dtype is None:
out_dtype = theano.config.floatX out_dtype = theano.config.floatX
...@@ -182,25 +181,27 @@ def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None, ...@@ -182,25 +181,27 @@ def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None,
def verify_grad_sparse(op, pt, structured=False, *args, **kwargs): def verify_grad_sparse(op, pt, structured=False, *args, **kwargs):
# Wrapper for theano.test.unittest_tools.py:verify_grad wich """
# converts sparse variables back and forth. Wrapper for theano.test.unittest_tools.py:verify_grad wich
# converts sparse variables back and forth.
# Parameters
# ---------- Parameters
# op ----------
# Op to check. op
# pt Op to check.
# List of inputs to realize the tests. pt
# structured List of inputs to realize the tests.
# True to tests with a structured grad, False otherwise. structured
# args True to tests with a structured grad, False otherwise.
# Other `verify_grad` parameters if any. args
# kwargs Other `verify_grad` parameters if any.
# Other `verify_grad` keywords if any. kwargs
# Other `verify_grad` keywords if any.
# Returns
# ------- Returns
# None -------
None
"""
def conv_none(x): def conv_none(x):
return x return x
...@@ -1427,7 +1428,9 @@ class DotTests(utt.InferShapeTester): ...@@ -1427,7 +1428,9 @@ class DotTests(utt.InferShapeTester):
class UsmmTests(unittest.TestCase): class UsmmTests(unittest.TestCase):
# Test the Usmm and UsmmCscDense class and related optimization """
Test the Usmm and UsmmCscDense class and related optimization
"""
def setUp(self): def setUp(self):
x_size = (10, 100) x_size = (10, 100)
y_size = (100, 200) y_size = (100, 200)
...@@ -2470,8 +2473,9 @@ def _format_info(nb): ...@@ -2470,8 +2473,9 @@ def _format_info(nb):
class _HVStackTester(utt.InferShapeTester): class _HVStackTester(utt.InferShapeTester):
# Test for both HStack and VStack. """
Test for both HStack and VStack.
"""
nb = 3 # Number of sparse matrix to stack nb = 3 # Number of sparse matrix to stack
x, mat = _format_info(nb) x, mat = _format_info(nb)
...@@ -2517,11 +2521,13 @@ class _HVStackTester(utt.InferShapeTester): ...@@ -2517,11 +2521,13 @@ class _HVStackTester(utt.InferShapeTester):
def _hv_switch(op, expected_function): def _hv_switch(op, expected_function):
# Return the right test class for HStack or VStack. """
# Return the right test class for HStack or VStack.
# :Parameters:
# - `op`: HStack or VStack class. :Parameters:
# - `expected_function`: function from scipy for comparaison. - `op`: HStack or VStack class.
- `expected_function`: function from scipy for comparaison.
"""
class XStackTester(_HVStackTester): class XStackTester(_HVStackTester):
op_class = op op_class = op
...@@ -2585,28 +2591,30 @@ class AddSSDataTester(utt.InferShapeTester): ...@@ -2585,28 +2591,30 @@ class AddSSDataTester(utt.InferShapeTester):
def elemwise_checker(op, expected_f, gap=None, test_dtypes=None, def elemwise_checker(op, expected_f, gap=None, test_dtypes=None,
grad_test=True, name=None, gap_grad=None): grad_test=True, name=None, gap_grad=None):
# Return the appropriate test class for the elemwise on sparse. """
# Return the appropriate test class for the elemwise on sparse.
# :param op: Op to test.
# :expected_f: Function use to compare. This function must act :param op: Op to test.
# on dense matrix. If the op is structured :expected_f: Function use to compare. This function must act
# see the `structure_function` decorator to make on dense matrix. If the op is structured
# this function structured. see the `structure_function` decorator to make
# :param gap: Tuple for the range of the random sample. When this function structured.
# length is 1, it is assumed to be the exclusive :param gap: Tuple for the range of the random sample. When
# max, when `gap` = (`a`, `b`) it provide a sample length is 1, it is assumed to be the exclusive
# from [a, b[. If `None` is used, it provide [0, 1] max, when `gap` = (`a`, `b`) it provide a sample
# for float dtypes and [0, 50[ for integer dtypes. from [a, b[. If `None` is used, it provide [0, 1]
# :param test_dtypes: Particular dtypes for testing the op. for float dtypes and [0, 50[ for integer dtypes.
# If `None`, this is set to the most common :param test_dtypes: Particular dtypes for testing the op.
# dtypes. If `None`, this is set to the most common
# :param grad_test: True for testing the grad. False will dtypes.
# skip this test. :param grad_test: True for testing the grad. False will
# :param gap_grad: If None, we reuse gap. Otherwise it is the same as gap skip this test.
# but for testing the gradiant of the op. :param gap_grad: If None, we reuse gap. Otherwise it is the same as gap
# but for testing the gradiant of the op.
# :return: The class that perform the tests, not an instance
# of the class. :return: The class that perform the tests, not an instance
of the class.
"""
if test_dtypes is None: if test_dtypes is None:
test_dtypes = sparse.all_dtypes test_dtypes = sparse.all_dtypes
...@@ -2782,19 +2790,21 @@ def test_hstack_vstack(): ...@@ -2782,19 +2790,21 @@ def test_hstack_vstack():
def structure_function(f, index=0): def structure_function(f, index=0):
# Decorator to structure a function wich """
# apply on dense matrix. Decorator to structure a function wich
# apply on dense matrix.
# Here, the inputs of the function must be
# dense matrix. The sparse pattern is Here, the inputs of the function must be
# determined by finding the zeros. dense matrix. The sparse pattern is
# determined by finding the zeros.
# :param index: The index of the parameter
# from wich the function must :param index: The index of the parameter
# be structured. from wich the function must
# be structured.
# :return: The structured function for its
# `index` parameter. :return: The structured function for its
`index` parameter.
"""
def structured_function(*args): def structured_function(*args):
pattern = args[index] pattern = args[index]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论