提交 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,
class multiple_outputs_numeric_grad:
# WRITEME
"""WRITEME"""
def __init__(self, f, pt, ndarray_mask=None, eps=None):
# Return the gradient of f at pt.
#
# 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
# input dtype-dependent. See `type_eps`.
"""
Return the gradient of f at pt.
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
input dtype-dependent. See `type_eps`.
"""
def prod(inputs):
rval = 1
......@@ -123,13 +125,15 @@ class multiple_outputs_numeric_grad:
@staticmethod
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)
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 = []
for i in xrange(len(_g_pt)):
if self.ndarray_mask[i]:
......@@ -4527,19 +4531,18 @@ class T_Scan(unittest.TestCase):
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
# independant of the GPU backend used. Because of this, a class inheriting
# from ScanGpuTests should define the following attributes and methods to
# make the tests run on a specific backend :
# - self.gpu_backend : Reference to the backend module
# - self.mode_with_opt : Compilation mode to force usage of the gpu backend
# - self.is_scan_on_gpu(node) : Method to determine is a scan node has been
# 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.
"""
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
independant of the GPU backend used. Because of this, a class inheriting
from ScanGpuTests should define the following attributes and methods to
make the tests run on a specific backend :
- self.gpu_backend : Reference to the backend module
- self.mode_with_opt : Compilation mode to force usage of the gpu backend
- self.is_scan_on_gpu(node) : Method to determine is a scan node has been
moved to run on a gpu under the specific
backend. Returns a boolean.
"""
def test_one_sequence_one_output_weights_gpu1(self):
def f_rnn(u_t, x_tm1, W_in, W):
......@@ -4869,8 +4872,10 @@ class 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):
from theano import gpuarray
......
......@@ -12,9 +12,11 @@ mode = theano.compile.mode.get_mode(config.mode)
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):
self.rng = np.random.RandomState(utt.fetch_seed())
......@@ -134,10 +136,12 @@ class GaussNewtonMatrix(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
# on a non-sequence matrix input to scan and a vector that is the result of
# computation in the inner function.
"""
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
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):
# Test the case where the vector input to the dot is not already an
......@@ -264,9 +268,11 @@ class TestPushOutScanOutputDot(object):
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
# elements of two list of matrices.
"""
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
elements of two list of matrices.
"""
def test_machine_translation(self):
# This test case comes from https://github.com/rizar/scan-grad-speed and
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论