Repository: chainer/chainer

Issue:
Theano test failure with NumPy 1.16.0
Travis CI is failing with NumPy 1.16.0 and we need https://github.com/Theano/Theano/pull/6671 to fix this failure.


```
E     File "/Users/travis/.pyenv/versions/3.5.1/lib/python3.5/site-packages/theano/gof/cc.py", line 1379, in cmodule_key_
E       np.core.multiarray._get_ndarray_c_version())
E   AttributeError: ('The following error happened while compiling the node', Elemwise{add,no_inplace}(x, y), '\n', "module 'numpy.core.multiarray' has no attribute '_get_ndarray_c_version'")
```


Discussion:

Resolving patch:
diff --git a/chainer/links/theano/theano_function.py b/chainer/links/theano/theano_function.py
--- a/chainer/links/theano/theano_function.py
+++ b/chainer/links/theano/theano_function.py
@@ -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()
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -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
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -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': [


Test patch:
diff --git a/chainer/testing/__init__.py b/chainer/testing/__init__.py
--- a/chainer/testing/__init__.py
+++ b/chainer/testing/__init__.py
@@ -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
diff --git a/chainer/testing/helper.py b/chainer/testing/helper.py
--- a/chainer/testing/helper.py
+++ b/chainer/testing/helper.py
@@ -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:
diff --git a/tests/chainer_tests/links_tests/theano_tests/test_theano_function.py b/tests/chainer_tests/links_tests/theano_tests/test_theano_function.py
--- a/tests/chainer_tests/links_tests/theano_tests/test_theano_function.py
+++ b/tests/chainer_tests/links_tests/theano_tests/test_theano_function.py
@@ -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 = {}