提交 3b205e97 authored 作者: AndreiCostinescu's avatar AndreiCostinescu

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

上级 0260d1b6
......@@ -1097,12 +1097,16 @@ class TestBilinearUpsampling(unittest.TestCase):
compile_mode = compile_mode.excluding('AbstractConvCheck')
def numerical_kernel_1D(self, ratio):
# Gets numerical 1D kernel for bilinear upsampling
"""
Gets numerical 1D kernel for bilinear upsampling
"""
return np.array(list(range(1, ratio + 1)) +
list(range(ratio - 1, 0, -1)))
def numerical_kernel_2D(self, ratio):
# Gets numerical 2D kernel for bilinear upsampling
"""
Gets numerical 2D kernel for bilinear upsampling
"""
return np.array([i * j for i in self.numerical_kernel_1D(ratio) for j
in self.numerical_kernel_1D(ratio)]).\
reshape(2 * ratio - 1, 2 * ratio - 1)
......@@ -1157,50 +1161,52 @@ class TestBilinearUpsampling(unittest.TestCase):
utt.assert_allclose(kernel_1D, f_ten_norm(ratio))
def numerical_upsampling_multiplier(self, ratio):
# Compute upsampling multiplier
#
# This method computes the multipliers of an array
# that will be upsampled using bilinear interpolation.
#
# Parameters
# ----------
# ratio: int
# the ratio by which the array will be upsampled.
#
# Returns
# -------
# 1D numpy array
# The multiplers that can be used in bilinear interpolation
# to upsample an array.
#
# int
# The size of the multipliers array
"""
Compute upsampling multiplier
This method computes the multipliers of an array
that will be upsampled using bilinear interpolation.
Parameters
----------
ratio: int
the ratio by which the array will be upsampled.
Returns
-------
1D numpy array
The multiplers that can be used in bilinear interpolation
to upsample an array.
int
The size of the multipliers array
"""
kern = np.arange(ratio + 1)
return kern, kern.shape[0]
def get_upsampled_twobytwo_mat(self, two_by_two, ratio):
# Upsample 4D array with two rows and two columns
#
# This method gets a 4D numpy array with two rows and two columns
# and computes its upsampled array by using bilinear interpolation
#
# Parameters
# ----------
# two_by_two: numpy 4D array
# The array that will be upsampled by bilinear interpolation.
# Array is of shape (batch size, num channels, 2, 2)
#
# ratio: int
# The ratio by which two_by_two's last
# two dimensions (row and col) will be upsampled.
#
# Returns
# -------
# 4D numpy array
# The array upsampled by using bilinear interpolation. Array
# is of shape (batch size, num channels, 2*ratio, 2*ratio).
"""
Upsample 4D array with two rows and two columns
This method gets a 4D numpy array with two rows and two columns
and computes its upsampled array by using bilinear interpolation
Parameters
----------
two_by_two: numpy 4D array
The array that will be upsampled by bilinear interpolation.
Array is of shape (batch size, num channels, 2, 2)
ratio: int
The ratio by which two_by_two's last
two dimensions (row and col) will be upsampled.
Returns
-------
4D numpy array
The array upsampled by using bilinear interpolation. Array
is of shape (batch size, num channels, 2*ratio, 2*ratio).
"""
kern, shp = self.numerical_upsampling_multiplier(ratio)
up_1D = two_by_two[:, :, :, :1] * kern[::-1] + \
two_by_two[:, :, :, 1:] * kern
......
......@@ -87,8 +87,9 @@ class BlockSparse_Gemv_and_Outer(utt.InferShapeTester):
@staticmethod
def gemv_numpy2(o, W, h, iIdx, oIdx):
# Other implementation
"""
Other implementation
"""
from numpy import ix_
for b in range(o.shape[0]):
w = W[ix_(iIdx[b], oIdx[b])].swapaxes(1, 2)
......@@ -98,8 +99,9 @@ class BlockSparse_Gemv_and_Outer(utt.InferShapeTester):
@staticmethod
def gemv_numpy3(o, W, h, iIdx, oIdx):
# Other implementation
"""
Other implementation
"""
from numpy import ix_
for b in range(o.shape[0]):
w = W[ix_(iIdx[b], oIdx[b])]
......
......@@ -36,16 +36,18 @@ class TestConv2D(utt.InferShapeTester):
input=None, filters=None,
unroll_batch=None, unroll_kern=None, unroll_patch=None,
verify_grad=True, should_raise=False):
# :param image_shape: The constant shape info passed to conv2d.
# :param filter_shape: The constant shape info passed to conv2d.
#
# :param N_image_shape: None(default to image_shape) or tuple of
# 4 elements with the shape of the input image
#
# :param N_filter_shape: None(default to filter_shape) or tuple
# of 4 elements with the shape of the
# input filter
"""
:param image_shape: The constant shape info passed to conv2d.
:param filter_shape: The constant shape info passed to conv2d.
:param N_image_shape: None(default to image_shape) or tuple of
4 elements with the shape of the input image
:param N_filter_shape: None(default to filter_shape) or tuple
of 4 elements with the shape of the
input filter
"""
if N_image_shape is None:
N_image_shape = [T.get_scalar_constant_value(
T.as_tensor_variable(x)) for x in image_shape]
......
......@@ -34,9 +34,10 @@ class TestCorr2D(utt.InferShapeTester):
border_mode='valid', subsample=(1, 1),
input=None, filters=None, verify_grad=True,
non_contiguous=False, filter_dilation=(1, 1)):
# :param image_shape: The constant shape info passed to corrMM.
# :param filter_shape: The constant shape info passed to corrMM.
"""
:param image_shape: The constant shape info passed to corrMM.
:param filter_shape: The constant shape info passed to corrMM.
"""
if not theano.config.cxx:
raise SkipTest("Need cxx to test conv2d")
N_image_shape = [T.get_scalar_constant_value(T.as_tensor_variable(x))
......
......@@ -36,9 +36,10 @@ class TestCorr3D(utt.InferShapeTester):
border_mode='valid', subsample=(1, 1, 1),
input=None, filters=None, verify_grad=True,
non_contiguous=False, filter_dilation=(1, 1, 1)):
# :param image_shape: The constant shape info passed to corr3dMM.
# :param filter_shape: The constant shape info passed to corr3dMM.
"""
:param image_shape: The constant shape info passed to corr3dMM.
:param filter_shape: The constant shape info passed to corr3dMM.
"""
if not theano.config.cxx:
raise SkipTest("Need cxx for this test")
......
......@@ -77,9 +77,12 @@ def setup_grad_case():
class TestCTC(unittest.TestCase):
# Test Baidu CTC wrapper implementation.
# Expected values for costs and gradients are obtained through an external
# C implementation, that uses the library directly.
"""
Test Baidu CTC wrapper implementation.
Expected values for costs and gradients are obtained through an external
C implementation, that uses the library directly.
"""
def setUp(self):
if theano.config.mode == "FAST_COMPILE" or theano.config.cxx == "":
......@@ -108,8 +111,9 @@ class TestCTC(unittest.TestCase):
self.check_grads_disabled(t_activations, t_labels, t_activation_times)
def check_grads_disabled(self, activations, labels, input_length):
# Check if optimization to disable gradients is working
"""
Check if optimization to disable gradients is working
"""
ctc_cost = ctc(activations, labels, input_length)
ctc_function = theano.function([], [ctc_cost])
for node in ctc_function.maker.fgraph.apply_nodes:
......
......@@ -87,14 +87,15 @@ class T_softplus(unittest.TestCase):
class T_sigmoid_opts(unittest.TestCase):
def get_mode(self, excluding=None):
# Return appropriate mode for the tests.
#
# :param excluding: List of optimizations to exclude.
#
# :return: The current default mode unless the `config.mode` option is
# set to 'FAST_COMPILE' (in which case it is replaced by the 'FAST_RUN'
# mode), without the optimizations specified in `excluding`.
"""
Return appropriate mode for the tests.
:param excluding: List of optimizations to exclude.
:return: The current default mode unless the `config.mode` option is
set to 'FAST_COMPILE' (in which case it is replaced by the 'FAST_RUN'
mode), without the optimizations specified in `excluding`.
"""
if excluding is None:
excluding = []
m = theano.config.mode
......@@ -447,7 +448,9 @@ class T_softplus_opts(unittest.TestCase):
class T_sigmoid_utils(unittest.TestCase):
# Test utility functions found in 'sigm.py'.
"""
Test utility functions found in 'sigm.py'.
"""
def test_compute_mul(self):
x, y, z = tensor.vectors('x', 'y', 'z')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论