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