Skip to content

Commit

Permalink
Merge f58a491 into eb9f2c6
Browse files Browse the repository at this point in the history
  • Loading branch information
unnonouno committed Aug 17, 2017
2 parents eb9f2c6 + f58a491 commit 088ad59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -59,7 +59,7 @@ script:
- autopep8 -r . --global-config .pep8 --diff | tee check_autopep8
- test ! -s check_autopep8
- cd tests
- PYTHONWARNINGS='ignore::FutureWarning,module::DeprecationWarning' nosetests -a '!gpu,!slow' --with-doctest chainer_tests
- PYTHONWARNINGS='ignore::FutureWarning,error::DeprecationWarning,ignore::DeprecationWarning:nose.importer,ignore::DeprecationWarning:site,ignore::DeprecaitonWarning:inspect' nosetests -a '!gpu,!slow' --with-doctest chainer_tests
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then
cd ..;
READTHEDOCS=True python setup.py develop;
Expand Down
48 changes: 32 additions & 16 deletions tests/chainer_tests/test_link.py
Expand Up @@ -16,8 +16,9 @@ class TestLink(unittest.TestCase):
def setUp(self):
x_shape_0 = 2
x_shape_1 = numpy.int64(3)
self.link = chainer.Link(x=((x_shape_0, x_shape_1), 'd'),
u=(None, 'd'))
with testing.assert_warns(DeprecationWarning):
self.link = chainer.Link(x=((x_shape_0, x_shape_1), 'd'),
u=(None, 'd'))
with self.link.init_scope():
self.link.y = chainer.Parameter(shape=(2,))
self.link.v = chainer.Parameter()
Expand Down Expand Up @@ -78,38 +79,45 @@ def test_assign_var_in_init_scope(self):
self.assertTrue(all(p is not param for param in self.link.params()))

def test_add_param(self):
self.link.add_param('z', (2, 3))
with testing.assert_warns(DeprecationWarning):
self.link.add_param('z', (2, 3))
self.check_param_init('z', (2, 3), 'f')

self.link.add_param('w', (2, 3), dtype='d')
with testing.assert_warns(DeprecationWarning):
self.link.add_param('w', (2, 3), dtype='d')
self.check_param_init('w', (2, 3), 'd')

self.link.add_param('r')
with testing.assert_warns(DeprecationWarning):
self.link.add_param('r')
self.check_param_uninit('r')
self.link.r.initialize((2, 3))
self.check_param_init('r', (2, 3), 'f')

self.link.add_param('s', dtype='d')
with testing.assert_warns(DeprecationWarning):
self.link.add_param('s', dtype='d')
self.check_param_uninit('s')
self.link.s.initialize((2, 3))
self.check_param_init('s', (2, 3), 'd')

initializer = initializers.Zero('d')
self.link.add_param('t', initializer=initializer)
with testing.assert_warns(DeprecationWarning):
self.link.add_param('t', initializer=initializer)
self.check_param_uninit('t', initializer)
self.link.t.initialize((2, 3))
self.check_param_init('t', (2, 3), 'd', 0)

def test_add_param_direct_initialization(self):
z = numpy.random.rand(2, 3).astype('f')
self.link.add_param('z', initializer=z)
with testing.assert_warns(DeprecationWarning):
self.link.add_param('z', initializer=z)
self.assertIsInstance(self.link.z.data, numpy.ndarray)
numpy.testing.assert_array_equal(self.link.z.data, z)

def test_add_param_duplicated_with_persistent(self):
self.link.add_persistent('z', 'abc')
with self.assertRaises(AttributeError):
self.link.add_param('z', (2, 3))
with testing.assert_warns(DeprecationWarning):
self.link.add_param('z', (2, 3))

def test_add_persistent(self):
self.assertTrue(hasattr(self.link, 'p'))
Expand Down Expand Up @@ -434,13 +442,21 @@ def zerograd(self):
class TestChain(unittest.TestCase):

def setUp(self):
self.l1 = chainer.Link(x=(2, 3))
self.l2 = chainer.Link(x=2)
self.l3 = chainer.Link(x=None)
self.l1 = chainer.Link()
with self.l1.init_scope():
self.l1.x = chainer.Parameter(shape=(2, 3))
self.l2 = chainer.Link()
with self.l2.init_scope():
self.l2.x = chainer.Parameter(shape=2)
self.l3 = chainer.Link()
with self.l3.init_scope():
self.l3.x = chainer.Parameter()

self.c1 = chainer.Chain(l1=self.l1)
self.c1.add_link('l2', self.l2)
self.c2 = chainer.Chain(c1=self.c1)
with testing.assert_warns(DeprecationWarning):
self.c1 = chainer.Chain(l1=self.l1)
self.c1.add_link('l2', self.l2)
with testing.assert_warns(DeprecationWarning):
self.c2 = chainer.Chain(c1=self.c1)
with self.c2.init_scope():
self.c2.l3 = self.l3

Expand Down Expand Up @@ -962,7 +978,7 @@ def test_cleargrads(self):

def test_addgrads(self):
l1 = chainer.Link()
with self.l1.init_scope():
with l1.init_scope():
l1.x = chainer.Parameter(shape=(2, 3))
l1.y = chainer.Parameter(shape=(2, 3))
l2 = chainer.Link()
Expand Down

0 comments on commit 088ad59

Please sign in to comment.