We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
compatibility issue of `erfinv` and `erfcinv` 
For `erfinv`, the valid domain is [-1, 1], and at the boundary -1 and +1 the values are -Inf and +Inf, respectively. But outside the boundary, the values are NaN in SciPy: see [here](https://github.com/scipy/scipy/blob/59347ae8b86bcc92c339efe213128f64ab6df98c/scipy/special/cephes/ndtri.c#L146-L149) (the `ndtri` function is the underlying workhorse).

Reproducer:
```python
>>> from cupyx.scipy.special import erfinv
>>> import  cupy as cp
>>> 
>>> a  = (cp.arange(6) + 1).reshape(2,3)
>>> a
array([[1, 2, 3],
       [4, 5, 6]])
>>> erfinv(a)
array([[inf, inf, inf],
       [inf, inf, inf]])
>>>
>>> import scipy.special as scp
>>> scp.erfinv(cp.asnumpy(a))
array([[inf, nan, nan],
       [nan, nan, nan]])
```

Reproducer 2:
```bash
$ pytest -v tests/cupyx_tests/scipy_tests/special_tests/test_erf.py
========================================================================= test session starts =========================================================================
platform linux -- Python 3.7.6, pytest-5.3.5, py-1.8.1, pluggy-0.12.0 -- /home/leofang/miniconda3/envs/cupy_dev/bin/python
cachedir: .pytest_cache
rootdir: /home/leofang/cupy, inifile: setup.cfg
collected 10 items                                                                                                                                                    

tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erf PASSED                                                                           [ 10%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erfc PASSED                                                                          [ 20%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erfcinv FAILED                                                                       [ 30%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erfcx PASSED                                                                         [ 40%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erfinv FAILED                                                                        [ 50%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erf PASSED                                                                     [ 60%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erfc PASSED                                                                    [ 70%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erfcinv FAILED                                                                 [ 80%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erfcx PASSED                                                                   [ 90%]
tests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erfinv FAILED                                                                  [100%]

=============================================================== 4 failed, 6 passed, 1 warning in 0.74s ================================================================
```

I am a bit surprised to learn this, as the CI doesn't seem to complain at all, so it is likely the behavior is changed in recent SciPy? (I'm using v1.4.1 btw.) 

The fix should be simple: just add another `else if` branch handling the out of boundary behavior to the ufunc here : https://github.com/cupy/cupy/blob/84343ce8a87d34928abef65d8930ba590189f43f/cupyx/scipy/special/erf.py#L37-L43

I have not dug into `erfcinv` but presumably the source of error is similar. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cupyx/scipy/special/erf.py`
Content:
```
1 from cupy import core
2 
3 
4 erf = core.create_ufunc(
5     'cupyx_scipy_erf', ('f->f', 'd->d'),
6     'out0 = erf(in0)',
7     doc='''Error function.
8 
9     .. seealso:: :meth:`scipy.special.erf`
10 
11     ''')
12 
13 
14 erfc = core.create_ufunc(
15     'cupyx_scipy_erfc', ('f->f', 'd->d'),
16     'out0 = erfc(in0)',
17     doc='''Complementary error function.
18 
19     .. seealso:: :meth:`scipy.special.erfc`
20 
21     ''')
22 
23 
24 erfcx = core.create_ufunc(
25     'cupyx_scipy_erfcx', ('f->f', 'd->d'),
26     'out0 = erfcx(in0)',
27     doc='''Scaled complementary error function.
28 
29     .. seealso:: :meth:`scipy.special.erfcx`
30 
31     ''')
32 
33 
34 erfinv = core.create_ufunc(
35     'cupyx_scipy_erfinv', ('f->f', 'd->d'),
36     '''
37     if (in0 < -1) {
38         out0 = -1.0 / 0.0;
39     } else if (in0 > 1) {
40         out0 = 1.0 / 0.0;
41     } else {
42         out0 = erfinv(in0);
43     }
44     ''',
45     doc='''Inverse function of error function.
46 
47     .. seealso:: :meth:`scipy.special.erfinv`
48 
49     ''')
50 
51 
52 erfcinv = core.create_ufunc(
53     'cupyx_scipy_erfcinv', ('f->f', 'd->d'),
54     '''
55     if (in0 < 0) {
56         out0 = 1.0 / 0.0;
57     } else if (in0 > 2) {
58         out0 = -1.0 / 0.0;
59     } else {
60         out0 = erfcinv(in0);
61     }
62     ''',
63     doc='''Inverse function of complementary error function.
64 
65     .. seealso:: :meth:`scipy.special.erfcinv`
66 
67     ''')
68
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cupyx/scipy/special/erf.py b/cupyx/scipy/special/erf.py
--- a/cupyx/scipy/special/erf.py
+++ b/cupyx/scipy/special/erf.py
@@ -33,35 +33,27 @@
 
 erfinv = core.create_ufunc(
     'cupyx_scipy_erfinv', ('f->f', 'd->d'),
-    '''
-    if (in0 < -1) {
-        out0 = -1.0 / 0.0;
-    } else if (in0 > 1) {
-        out0 = 1.0 / 0.0;
-    } else {
-        out0 = erfinv(in0);
-    }
-    ''',
+    'out0 = erfinv(in0);',
     doc='''Inverse function of error function.
 
     .. seealso:: :meth:`scipy.special.erfinv`
 
+    .. note::
+        The behavior close to (and outside) the domain follows that of
+        SciPy v1.4.0+.
+
     ''')
 
 
 erfcinv = core.create_ufunc(
     'cupyx_scipy_erfcinv', ('f->f', 'd->d'),
-    '''
-    if (in0 < 0) {
-        out0 = 1.0 / 0.0;
-    } else if (in0 > 2) {
-        out0 = -1.0 / 0.0;
-    } else {
-        out0 = erfcinv(in0);
-    }
-    ''',
+    'out0 = erfcinv(in0);',
     doc='''Inverse function of complementary error function.
 
     .. seealso:: :meth:`scipy.special.erfcinv`
 
+    .. note::
+        The behavior close to (and outside) the domain follows that of
+        SciPy v1.4.0+.
+
     ''')

{"golden_diff": "diff --git a/cupyx/scipy/special/erf.py b/cupyx/scipy/special/erf.py\n--- a/cupyx/scipy/special/erf.py\n+++ b/cupyx/scipy/special/erf.py\n@@ -33,35 +33,27 @@\n \n erfinv = core.create_ufunc(\n     'cupyx_scipy_erfinv', ('f->f', 'd->d'),\n-    '''\n-    if (in0 < -1) {\n-        out0 = -1.0 / 0.0;\n-    } else if (in0 > 1) {\n-        out0 = 1.0 / 0.0;\n-    } else {\n-        out0 = erfinv(in0);\n-    }\n-    ''',\n+    'out0 = erfinv(in0);',\n     doc='''Inverse function of error function.\n \n     .. seealso:: :meth:`scipy.special.erfinv`\n \n+    .. note::\n+        The behavior close to (and outside) the domain follows that of\n+        SciPy v1.4.0+.\n+\n     ''')\n \n \n erfcinv = core.create_ufunc(\n     'cupyx_scipy_erfcinv', ('f->f', 'd->d'),\n-    '''\n-    if (in0 < 0) {\n-        out0 = 1.0 / 0.0;\n-    } else if (in0 > 2) {\n-        out0 = -1.0 / 0.0;\n-    } else {\n-        out0 = erfcinv(in0);\n-    }\n-    ''',\n+    'out0 = erfcinv(in0);',\n     doc='''Inverse function of complementary error function.\n \n     .. seealso:: :meth:`scipy.special.erfcinv`\n \n+    .. note::\n+        The behavior close to (and outside) the domain follows that of\n+        SciPy v1.4.0+.\n+\n     ''')\n", "issue": "compatibility issue of `erfinv` and `erfcinv` \nFor `erfinv`, the valid domain is [-1, 1], and at the boundary -1 and +1 the values are -Inf and +Inf, respectively. But outside the boundary, the values are NaN in SciPy: see [here](https://github.com/scipy/scipy/blob/59347ae8b86bcc92c339efe213128f64ab6df98c/scipy/special/cephes/ndtri.c#L146-L149) (the `ndtri` function is the underlying workhorse).\r\n\r\nReproducer:\r\n```python\r\n>>> from cupyx.scipy.special import erfinv\r\n>>> import  cupy as cp\r\n>>> \r\n>>> a  = (cp.arange(6) + 1).reshape(2,3)\r\n>>> a\r\narray([[1, 2, 3],\r\n       [4, 5, 6]])\r\n>>> erfinv(a)\r\narray([[inf, inf, inf],\r\n       [inf, inf, inf]])\r\n>>>\r\n>>> import scipy.special as scp\r\n>>> scp.erfinv(cp.asnumpy(a))\r\narray([[inf, nan, nan],\r\n       [nan, nan, nan]])\r\n```\r\n\r\nReproducer 2:\r\n```bash\r\n$ pytest -v tests/cupyx_tests/scipy_tests/special_tests/test_erf.py\r\n========================================================================= test session starts =========================================================================\r\nplatform linux -- Python 3.7.6, pytest-5.3.5, py-1.8.1, pluggy-0.12.0 -- /home/leofang/miniconda3/envs/cupy_dev/bin/python\r\ncachedir: .pytest_cache\r\nrootdir: /home/leofang/cupy, inifile: setup.cfg\r\ncollected 10 items                                                                                                                                                    \r\n\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erf PASSED                                                                           [ 10%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erfc PASSED                                                                          [ 20%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erfcinv FAILED                                                                       [ 30%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erfcx PASSED                                                                         [ 40%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestSpecial::test_erfinv FAILED                                                                        [ 50%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erf PASSED                                                                     [ 60%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erfc PASSED                                                                    [ 70%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erfcinv FAILED                                                                 [ 80%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erfcx PASSED                                                                   [ 90%]\r\ntests/cupyx_tests/scipy_tests/special_tests/test_erf.py::TestFusionSpecial::test_erfinv FAILED                                                                  [100%]\r\n\r\n=============================================================== 4 failed, 6 passed, 1 warning in 0.74s ================================================================\r\n```\r\n\r\nI am a bit surprised to learn this, as the CI doesn't seem to complain at all, so it is likely the behavior is changed in recent SciPy? (I'm using v1.4.1 btw.) \r\n\r\nThe fix should be simple: just add another `else if` branch handling the out of boundary behavior to the ufunc here : https://github.com/cupy/cupy/blob/84343ce8a87d34928abef65d8930ba590189f43f/cupyx/scipy/special/erf.py#L37-L43\r\n\r\nI have not dug into `erfcinv` but presumably the source of error is similar. \n", "before_files": [{"content": "from cupy import core\n\n\nerf = core.create_ufunc(\n    'cupyx_scipy_erf', ('f->f', 'd->d'),\n    'out0 = erf(in0)',\n    doc='''Error function.\n\n    .. seealso:: :meth:`scipy.special.erf`\n\n    ''')\n\n\nerfc = core.create_ufunc(\n    'cupyx_scipy_erfc', ('f->f', 'd->d'),\n    'out0 = erfc(in0)',\n    doc='''Complementary error function.\n\n    .. seealso:: :meth:`scipy.special.erfc`\n\n    ''')\n\n\nerfcx = core.create_ufunc(\n    'cupyx_scipy_erfcx', ('f->f', 'd->d'),\n    'out0 = erfcx(in0)',\n    doc='''Scaled complementary error function.\n\n    .. seealso:: :meth:`scipy.special.erfcx`\n\n    ''')\n\n\nerfinv = core.create_ufunc(\n    'cupyx_scipy_erfinv', ('f->f', 'd->d'),\n    '''\n    if (in0 < -1) {\n        out0 = -1.0 / 0.0;\n    } else if (in0 > 1) {\n        out0 = 1.0 / 0.0;\n    } else {\n        out0 = erfinv(in0);\n    }\n    ''',\n    doc='''Inverse function of error function.\n\n    .. seealso:: :meth:`scipy.special.erfinv`\n\n    ''')\n\n\nerfcinv = core.create_ufunc(\n    'cupyx_scipy_erfcinv', ('f->f', 'd->d'),\n    '''\n    if (in0 < 0) {\n        out0 = 1.0 / 0.0;\n    } else if (in0 > 2) {\n        out0 = -1.0 / 0.0;\n    } else {\n        out0 = erfcinv(in0);\n    }\n    ''',\n    doc='''Inverse function of complementary error function.\n\n    .. seealso:: :meth:`scipy.special.erfcinv`\n\n    ''')\n", "path": "cupyx/scipy/special/erf.py"}], "after_files": [{"content": "from cupy import core\n\n\nerf = core.create_ufunc(\n    'cupyx_scipy_erf', ('f->f', 'd->d'),\n    'out0 = erf(in0)',\n    doc='''Error function.\n\n    .. seealso:: :meth:`scipy.special.erf`\n\n    ''')\n\n\nerfc = core.create_ufunc(\n    'cupyx_scipy_erfc', ('f->f', 'd->d'),\n    'out0 = erfc(in0)',\n    doc='''Complementary error function.\n\n    .. seealso:: :meth:`scipy.special.erfc`\n\n    ''')\n\n\nerfcx = core.create_ufunc(\n    'cupyx_scipy_erfcx', ('f->f', 'd->d'),\n    'out0 = erfcx(in0)',\n    doc='''Scaled complementary error function.\n\n    .. seealso:: :meth:`scipy.special.erfcx`\n\n    ''')\n\n\nerfinv = core.create_ufunc(\n    'cupyx_scipy_erfinv', ('f->f', 'd->d'),\n    'out0 = erfinv(in0);',\n    doc='''Inverse function of error function.\n\n    .. seealso:: :meth:`scipy.special.erfinv`\n\n    .. note::\n        The behavior close to (and outside) the domain follows that of\n        SciPy v1.4.0+.\n\n    ''')\n\n\nerfcinv = core.create_ufunc(\n    'cupyx_scipy_erfcinv', ('f->f', 'd->d'),\n    'out0 = erfcinv(in0);',\n    doc='''Inverse function of complementary error function.\n\n    .. seealso:: :meth:`scipy.special.erfcinv`\n\n    .. note::\n        The behavior close to (and outside) the domain follows that of\n        SciPy v1.4.0+.\n\n    ''')\n", "path": "cupyx/scipy/special/erf.py"}]}