提交 fd33e468 authored 作者: abergeron's avatar abergeron 提交者: GitHub

Merge pull request #6262 from yikangshen/convert_docstrings_to_comments

Convert the docstrings to comments in compile/tests
...@@ -338,10 +338,8 @@ class T_function(unittest.TestCase): ...@@ -338,10 +338,8 @@ class T_function(unittest.TestCase):
second_time = True second_time = True
def test_swap_SharedVariable_with_given(self): def test_swap_SharedVariable_with_given(self):
""" # A special testcase for logistic_sgd.py in Deep Learning Tutorial
A special testcase for logistic_sgd.py in Deep Learning Tutorial # This test assert that SharedVariable in different function have same storage
This test assert that SharedVariable in different function have same storage
"""
train_x = theano.shared(value=np.random.rand(10, 10).astype(config.floatX)) train_x = theano.shared(value=np.random.rand(10, 10).astype(config.floatX))
test_x = theano.shared(value=np.random.rand(10, 10).astype(config.floatX)) test_x = theano.shared(value=np.random.rand(10, 10).astype(config.floatX))
...@@ -492,12 +490,10 @@ class T_function(unittest.TestCase): ...@@ -492,12 +490,10 @@ class T_function(unittest.TestCase):
assert (out2 == 3).all() assert (out2 == 3).all()
def test_borrow_input(self): def test_borrow_input(self):
""" # Tests that the contract for io.In is respected. When borrow=False, it should be
Tests that the contract for io.In is respected. When borrow=False, it should be # impossible for outputs to be aliased to the input variables provided by the user,
impossible for outputs to be aliased to the input variables provided by the user, # either through a view-map or a destroy map. New tests should be added in the future
either through a view-map or a destroy map. New tests should be added in the future # when borrow=True is implemented.
when borrow=True is implemented.
"""
a = T.dmatrix() a = T.dmatrix()
aval = np.random.rand(3, 3) aval = np.random.rand(3, 3)
...@@ -550,17 +546,13 @@ class T_function(unittest.TestCase): ...@@ -550,17 +546,13 @@ class T_function(unittest.TestCase):
function([m, mt], mt * 2, on_unused_input='ignore') function([m, mt], mt * 2, on_unused_input='ignore')
def test_givens_input_var(self): def test_givens_input_var(self):
""" # Ensure error is raised when trying to replace an input variable.
Ensure error is raised when trying to replace an input variable.
"""
x = T.scalar('x') x = T.scalar('x')
y = x * 2 y = x * 2
self.assertRaises(RuntimeError, function, [x], y, givens={x: x + 1}) self.assertRaises(RuntimeError, function, [x], y, givens={x: x + 1})
def test_free(self): def test_free(self):
""" # Make test on free() function
Make test on free() function
"""
x = T.vector('x') x = T.vector('x')
func = function([x], x + 1) func = function([x], x + 1)
func.fn.allow_gc = False func.fn.allow_gc = False
...@@ -579,10 +571,8 @@ class T_function(unittest.TestCase): ...@@ -579,10 +571,8 @@ class T_function(unittest.TestCase):
assert (val[0] is None) assert (val[0] is None)
def test_default_values(self): def test_default_values(self):
""" # Check that default values are restored
Check that default values are restored # when an exception occurs in interactive mode.
when an exception occurs in interactive mode.
"""
a, b = T.dscalars('a', 'b') a, b = T.dscalars('a', 'b')
c = a + b c = a + b
func = theano.function([theano.In(a, name='first'), theano.In(b, value=1, name='second')], c) func = theano.function([theano.In(a, name='first'), theano.In(b, value=1, name='second')], c)
...@@ -897,9 +887,7 @@ class SomethingToPickle(object): ...@@ -897,9 +887,7 @@ class SomethingToPickle(object):
def test_empty_givens_updates(): def test_empty_givens_updates():
""" # Regression test for bug fixed in 8625e03.
Regression test for bug fixed in 8625e03.
"""
# Empty givens / updates dictionaries were not properly detected before, # Empty givens / updates dictionaries were not properly detected before,
# triggering useless crashes at compile time. # triggering useless crashes at compile time.
x = T.scalar() x = T.scalar()
......
...@@ -5,9 +5,7 @@ import theano ...@@ -5,9 +5,7 @@ import theano
def test_detect_nan(): def test_detect_nan():
""" # Test the code snippet example that detects NaN values.
Test the code snippet example that detects NaN values.
"""
nan_detected = [False] nan_detected = [False]
def detect_nan(i, node, fn): def detect_nan(i, node, fn):
...@@ -29,9 +27,7 @@ def test_detect_nan(): ...@@ -29,9 +27,7 @@ def test_detect_nan():
def test_optimizer(): def test_optimizer():
""" # Test that we can remove optimizer
Test that we can remove optimizer
"""
nan_detected = [False] nan_detected = [False]
def detect_nan(i, node, fn): def detect_nan(i, node, fn):
...@@ -58,9 +54,7 @@ def test_optimizer(): ...@@ -58,9 +54,7 @@ def test_optimizer():
def test_not_inplace(): def test_not_inplace():
""" # Test that we can remove optimizers including inplace optimizers
Test that we can remove optimizers including inplace optimizers
"""
nan_detected = [False] nan_detected = [False]
def detect_nan(i, node, fn): def detect_nan(i, node, fn):
......
...@@ -15,14 +15,14 @@ from theano.compile import config ...@@ -15,14 +15,14 @@ from theano.compile import config
def data_of(s): def data_of(s):
"""Return the raw value of a shared variable""" # Return the raw value of a shared variable
return s.container.storage[0] return s.container.storage[0]
class Test_pfunc(unittest.TestCase): class Test_pfunc(unittest.TestCase):
def test_doc(self): def test_doc(self):
"""Ensure the code given in pfunc.txt works as expected""" # Ensure the code given in pfunc.txt works as expected
# Example #1. # Example #1.
a = lscalar() a = lscalar()
...@@ -74,7 +74,7 @@ class Test_pfunc(unittest.TestCase): ...@@ -74,7 +74,7 @@ class Test_pfunc(unittest.TestCase):
assert np.all(f1(xval) == xval + w.get_value(borrow=True)) assert np.all(f1(xval) == xval + w.get_value(borrow=True))
def test_no_shared_as_input(self): def test_no_shared_as_input(self):
"""Test that shared variables cannot be used as function inputs.""" # Test that shared variables cannot be used as function inputs.
w_init = np.random.rand(2, 2) w_init = np.random.rand(2, 2)
w = shared(w_init.copy(), 'w') w = shared(w_init.copy(), 'w')
try: try:
...@@ -317,7 +317,7 @@ class Test_pfunc(unittest.TestCase): ...@@ -317,7 +317,7 @@ class Test_pfunc(unittest.TestCase):
self.assertRaises(TypeError, h, 0.1, [0]) self.assertRaises(TypeError, h, 0.1, [0])
def test_update(self): def test_update(self):
"""Test update mechanism in different settings.""" # Test update mechanism in different settings.
# Simple value assignment. # Simple value assignment.
x = shared(0) x = shared(0)
...@@ -666,28 +666,26 @@ class Test_pfunc(unittest.TestCase): ...@@ -666,28 +666,26 @@ class Test_pfunc(unittest.TestCase):
class Test_aliasing_rules(unittest.TestCase): class Test_aliasing_rules(unittest.TestCase):
""" # 1. Theano manages its own memory space, which typically does not overlap
1. Theano manages its own memory space, which typically does not overlap # with the memory of normal python variables that the user uses.
with the memory of normal python variables that the user uses.
2. shared variables are allocated in this memory space, as are the # 2. shared variables are allocated in this memory space, as are the
temporaries used for Function evalution. # temporaries used for Function evalution.
3. Physically, this managed memory space may be spread across the host, # 3. Physically, this managed memory space may be spread across the host,
on a GPU device(s), or even on a remote machine. # on a GPU device(s), or even on a remote machine.
4. Theano assumes that shared variables are never aliased to one another, # 4. Theano assumes that shared variables are never aliased to one another,
and tries to make it impossible to accidentally alias them. # and tries to make it impossible to accidentally alias them.
5. Theano's managed data is constant while Theano Functions are not running # 5. Theano's managed data is constant while Theano Functions are not running
and theano library code is not running. # and theano library code is not running.
6. The default behaviour of Function is to return user-space values for # 6. The default behaviour of Function is to return user-space values for
outputs, but this can be overridden (borrow=True) for better performance, # outputs, but this can be overridden (borrow=True) for better performance,
in which case the returned value may be aliased to managed memory, and # in which case the returned value may be aliased to managed memory, and
potentially invalidated by the next Theano Function call or call to theano # potentially invalidated by the next Theano Function call or call to theano
library code. # library code.
"""
def shared(self, x): def shared(self, x):
return tensor._shared(x) return tensor._shared(x)
......
""" # Test of memory profiling
Test of memory profiling
"""
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
import unittest import unittest
...@@ -15,9 +13,7 @@ from theano.ifelse import ifelse ...@@ -15,9 +13,7 @@ from theano.ifelse import ifelse
class Test_profiling(unittest.TestCase): class Test_profiling(unittest.TestCase):
""" # Test of Theano profiling with min_peak_memory=True
Test of Theano profiling with min_peak_memory=True
"""
def test_profiling(self): def test_profiling(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论