Skip to content

Commit

Permalink
Merge pull request #6001 from niboshi/fix-theano-numpy-incompat
Browse files Browse the repository at this point in the history
Skip test on Theano<=1.0.3 and NumPy>=1.16.0
  • Loading branch information
toslunar committed Jan 16, 2019
2 parents eccd037 + a598024 commit 0861d4a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
8 changes: 7 additions & 1 deletion chainer/links/theano/theano_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ class TheanoFunction(link.Link):
and backward calculation from inputs and ouptuts. And then, it sends data
in :class:`chainer.Variable` to the function and gets results from Theano.
.. admonition:: Example
.. rubric:: Example
.. doctest::
# See chainer/chainer#5997
:skipif: os.environ.get('READTHEDOCS') != 'True' \
and chainer.testing.is_requires_satisfied( \
'Theano<=1.0.3', 'numpy>=1.16.0')
>>> import theano
>>> x = theano.tensor.fvector()
Expand Down
1 change: 1 addition & 0 deletions chainer/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from chainer.testing.backend import inject_backend_tests # NOQA
from chainer.testing.distribution_test import distribution_unittest # NOQA
from chainer.testing.helper import assert_warns # NOQA
from chainer.testing.helper import is_requires_satisfied # NOQA
from chainer.testing.helper import patch # NOQA
from chainer.testing.helper import with_requires # NOQA
from chainer.testing.helper import without_requires # NOQA
Expand Down
18 changes: 18 additions & 0 deletions chainer/testing/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ def without_requires(*requirements):
return unittest.skipIf(skip, msg)


def is_requires_satisfied(*requirements):
"""Returns whether the given requirments are satisfied.
Args:
requirements: A list of string representing the requirements.
Returns:
bool: A boolean indicating whether the given requirements are
satisfied.
"""
ws = pkg_resources.WorkingSet()
try:
ws.require(*requirements)
except pkg_resources.ResolutionError:
return False
return True


@contextlib.contextmanager
def assert_warns(expected):
with warnings.catch_warnings(record=True) as w:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@
}

doctest_global_setup = '''
import os
import numpy as np
import cupy
import chainer
from chainer.backends import cuda
from chainer import Function, gradient_check, training, utils, Variable
Expand Down
4 changes: 4 additions & 0 deletions docs/source/guides/gpu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ After reading this section, you will be able to:
* Write model-parallel computing in Chainer
* Write data-parallel computing in Chainer

.. testsetup::

import cupy

.. testcode::
:hide:

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
'mock',
],
'doctest': [
'sphinx==1.7.9',
'sphinx==1.8.2',
'matplotlib',
'theano',
],
'docs': [
'sphinx==1.7.9',
'sphinx==1.8.2',
'sphinx_rtd_theme',
],
'appveyor': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


@testing.with_requires('theano')
# chainer/chainer#5997
@testing.without_requires('Theano<=1.0.3', 'numpy>=1.16.0')
class TheanoFunctionTestBase(object):

forward_test_options = {}
Expand Down

0 comments on commit 0861d4a

Please sign in to comment.