提交 6c5071c9 authored 作者: AndreiCostinescu's avatar AndreiCostinescu

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

上级 3154dc99
...@@ -55,16 +55,18 @@ type_eps = {'float64': 1e-7, ...@@ -55,16 +55,18 @@ type_eps = {'float64': 1e-7,
class multiple_outputs_numeric_grad: class multiple_outputs_numeric_grad:
# WRITEME """WRITEME"""
def __init__(self, f, pt, ndarray_mask=None, eps=None): def __init__(self, f, pt, ndarray_mask=None, eps=None):
# Return the gradient of f at pt. """
# Return the gradient of f at pt.
# This function computes the gradient by a one-sided finite differences
# of a fixed step size (eps). This function computes the gradient by a one-sided finite differences
# of a fixed step size (eps).
# It is assumed that f(...) will return a scalar.
# :param eps: the stepsize for the finite differencing. None means It is assumed that f(...) will return a scalar.
# input dtype-dependent. See `type_eps`. :param eps: the stepsize for the finite differencing. None means
input dtype-dependent. See `type_eps`.
"""
def prod(inputs): def prod(inputs):
rval = 1 rval = 1
...@@ -123,13 +125,15 @@ class multiple_outputs_numeric_grad: ...@@ -123,13 +125,15 @@ class multiple_outputs_numeric_grad:
@staticmethod @staticmethod
def abs_rel_err(a, b, eps=1.0e-10): def abs_rel_err(a, b, eps=1.0e-10):
# Return a small number when a and b are close, relative to how big """
# they are Return a small number when a and b are close, relative to how big they are
"""
return abs(a - b) / (abs(a) + abs(b) + eps) return abs(a - b) / (abs(a) + abs(b) + eps)
def max_err(self, _g_pt): def max_err(self, _g_pt):
# Return the biggest relative error between g_pt and self.gx """
Return the biggest relative error between g_pt and self.gx
"""
g_pt = [] g_pt = []
for i in xrange(len(_g_pt)): for i in xrange(len(_g_pt)):
if self.ndarray_mask[i]: if self.ndarray_mask[i]:
...@@ -4527,19 +4531,18 @@ class T_Scan(unittest.TestCase): ...@@ -4527,19 +4531,18 @@ class T_Scan(unittest.TestCase):
class ScanGpuTests: class ScanGpuTests:
# This class defines a number of tests for Scan on GPU as well as a few """
# helper functions for these tests. The GPU tests defined in this class are This class defines a number of tests for Scan on GPU as well as a few
# independant of the GPU backend used. Because of this, a class inheriting helper functions for these tests. The GPU tests defined in this class are
# from ScanGpuTests should define the following attributes and methods to independant of the GPU backend used. Because of this, a class inheriting
# make the tests run on a specific backend : from ScanGpuTests should define the following attributes and methods to
# - self.gpu_backend : Reference to the backend module make the tests run on a specific backend :
# - self.mode_with_opt : Compilation mode to force usage of the gpu backend - self.gpu_backend : Reference to the backend module
# - self.is_scan_on_gpu(node) : Method to determine is a scan node has been - self.mode_with_opt : Compilation mode to force usage of the gpu backend
# moved to run on a gpu under the specific - self.is_scan_on_gpu(node) : Method to determine is a scan node has been
# backend. Returns a boolean. moved to run on a gpu under the specific
backend. Returns a boolean.
# as test_one_sequence_one_output_weights, but on the gpu """
# This first version test the first case in the optimizer to the gpu.
def test_one_sequence_one_output_weights_gpu1(self): def test_one_sequence_one_output_weights_gpu1(self):
def f_rnn(u_t, x_tm1, W_in, W): def f_rnn(u_t, x_tm1, W_in, W):
...@@ -4869,8 +4872,10 @@ class ScanGpuTests: ...@@ -4869,8 +4872,10 @@ class ScanGpuTests:
class T_Scan_Gpuarray(unittest.TestCase, ScanGpuTests): class T_Scan_Gpuarray(unittest.TestCase, ScanGpuTests):
# This class takes the gpu tests for scan that are defined in """
# class ScanGpuTests and runs them using the gpuarray backend. This class takes the gpu tests for scan that are defined in
class ScanGpuTests and runs them using the gpuarray backend.
"""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
from theano import gpuarray from theano import gpuarray
......
...@@ -12,9 +12,11 @@ mode = theano.compile.mode.get_mode(config.mode) ...@@ -12,9 +12,11 @@ mode = theano.compile.mode.get_mode(config.mode)
class TestGaussNewton(unittest.TestCase): class TestGaussNewton(unittest.TestCase):
# Regression test for code exhibiting various optimization errors. """
# This test case is based on code by Sigurd Spieckermann. Regression test for code exhibiting various optimization errors.
This test case is based on code by Sigurd Spieckermann.
"""
def setUp(self): def setUp(self):
self.rng = np.random.RandomState(utt.fetch_seed()) self.rng = np.random.RandomState(utt.fetch_seed())
...@@ -134,10 +136,12 @@ class GaussNewtonMatrix(object): ...@@ -134,10 +136,12 @@ class GaussNewtonMatrix(object):
class TestPushOutScanOutputDot(object): class TestPushOutScanOutputDot(object):
# Test class for the PushOutScanOutput optimizer in the case where the inner """
# function of a scan op has an output which is the result of a Dot product Test class for the PushOutScanOutput optimizer in the case where the inner
# on a non-sequence matrix input to scan and a vector that is the result of function of a scan op has an output which is the result of a Dot product
# computation in the inner function. on a non-sequence matrix input to scan and a vector that is the result of
computation in the inner function.
"""
def test_dot_not_output(self): def test_dot_not_output(self):
# Test the case where the vector input to the dot is not already an # Test the case where the vector input to the dot is not already an
...@@ -264,9 +268,11 @@ class TestPushOutScanOutputDot(object): ...@@ -264,9 +268,11 @@ class TestPushOutScanOutputDot(object):
class TestPushOutSumOfDot(): class TestPushOutSumOfDot():
# Test case for the PushOutScanOutput optimizer in the case where the scan """
# is used to compute the sum over the dot products between the corresponding Test case for the PushOutScanOutput optimizer in the case where the scan
# elements of two list of matrices. is used to compute the sum over the dot products between the corresponding
elements of two list of matrices.
"""
def test_machine_translation(self): def test_machine_translation(self):
# This test case comes from https://github.com/rizar/scan-grad-speed and # This test case comes from https://github.com/rizar/scan-grad-speed and
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论