internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: cupy/cupy

Issue:
`import cupy` causes `ImportWarning`
Reported [here](https://github.com/chainer/chainer/pull/8131#issuecomment-532521654).

(by running with `python -W error`)
> ```
> >>> import cupy
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "******/python3.7/site-packages/cupy/__init__.py", line 12, in <module>
>     from cupy import core  # NOQA
>   File "******/python3.7/site-packages/cupy/core/__init__.py", line 1, in <module>
>     from cupy.core import core  # NOQA
>   File "cupy/core/core.pyx", line 1, in init cupy.core.core
>   File "******/python3.7/site-packages/cupy/cuda/__init__.py", line 4, in <module>
>     from cupy.cuda import compiler  # NOQA
>   File "******/python3.7/site-packages/cupy/cuda/compiler.py", line 12, in <module>
>     from cupy.cuda import function
>   File "cupy/cuda/memory.pxd", line 11, in init cupy.cuda.function
>   File "cupy/cuda/memory.pyx", line 1, in init cupy.cuda.memory
>   File "fastrlock/_lock.pxi", line 4, in init fastrlock.rlock
> ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
> ```

It is actually `fastrlock` that is causing `ImportWarning`:
```
$ python -W error -c 'import fastrlock.rlock'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "fastrlock/_lock.pxi", line 4, in init fastrlock.rlock
ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
```


Discussion:
Seems to be a Cython issue
https://github.com/cython/cython/issues/1720
Installing `fastrlock==0.3` makes this error dissapear, however now theres a new one
```
    import pytest
  File "/home/ecastill/anaconda3/lib/python3.7/site-packages/pytest.py", line 7, in <module>
    from _pytest.assertion import register_assert_rewrite
  File "/home/ecastill/anaconda3/lib/python3.7/site-packages/_pytest/assertion/__init__.py", line 12, in <module>
    from _pytest.assertion import rewrite
  File "/home/ecastill/anaconda3/lib/python3.7/site-packages/_pytest/assertion/rewrite.py", line 8, in <module>
    import imp
  File "/home/ecastill/anaconda3/lib/python3.7/imp.py", line 33, in <module>
    DeprecationWarning, stacklevel=2)
DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
```

This one dissapears by upgrading pytest to 5.1.2

No other warnings after this
Should we force fastrlock to be 0.3 in the requirements?
pytest is restricted to 4.1 only in our infra

Resolving patch:
diff --git a/cupy/__init__.py b/cupy/__init__.py
--- a/cupy/__init__.py
+++ b/cupy/__init__.py
@@ -9,7 +9,10 @@
 
 
 try:
-    from cupy import core  # NOQA
+    with warnings.catch_warnings():
+        warnings.filterwarnings('ignore', category=ImportWarning,
+                                message='can\'t resolve package from __spec__')
+        from cupy import core  # NOQA
 except ImportError:
     # core is a c-extension module.
     # When a user cannot import core, it represents that CuPy is not correctly


Test patch:
Repository: cupy/cupy

Issue:
cupy.where fails for complex arrays
The function cupy.where does not work for complex arrays (numpy.where does):

```
import cupy as cp
a = cp.arange(5).astype(cp.complex128)
b = cp.arange(5).astype(cp.complex128)
c = cp.where(a==b,a,b)
```

fails with the error message

> TypeError: Wrong type ((<class 'numpy.bool_'>, <class 'numpy.complex128'>, <class 'numpy.complex128'>)) of arguments for cupy_where

For `cp.float64`, everything works fine.

CuPy Version          : 6.4.0
CUDA Root             : /usr
CUDA Build Version    : 8000
CUDA Driver Version   : 10020
CUDA Runtime Version  : 8000
cuDNN Build Version   : 7102
cuDNN Version         : 7102
NCCL Build Version    : 2213
NCCL Runtime Version  : (unknown)


Discussion:

Resolving patch:
diff --git a/cupy/sorting/search.py b/cupy/sorting/search.py
--- a/cupy/sorting/search.py
+++ b/cupy/sorting/search.py
@@ -100,7 +100,7 @@ def flatnonzero(a):
      # works).
      # See issue #551.
      '?hd->d', '?Hd->d',
-     '?dd->d'),
+     '?dd->d', '?FF->F', '?DD->D'),
     'out0 = in0 ? in1 : in2')
 
 


Test patch:
diff --git a/tests/cupy_tests/sorting_tests/test_search.py b/tests/cupy_tests/sorting_tests/test_search.py
--- a/tests/cupy_tests/sorting_tests/test_search.py
+++ b/tests/cupy_tests/sorting_tests/test_search.py
@@ -163,7 +163,7 @@ def test_argmin_zero_size_axis1(self, xp, dtype):
 class TestWhereTwoArrays(unittest.TestCase):
 
     @testing.for_all_dtypes_combination(
-        names=['cond_type', 'x_type', 'y_type'], no_complex=True)
+        names=['cond_type', 'x_type', 'y_type'])
     @testing.numpy_cupy_allclose()
     def test_where_two_arrays(self, xp, cond_type, x_type, y_type):
         m = testing.shaped_random(self.cond_shape, xp, xp.bool_)
@@ -184,7 +184,7 @@ def test_where_two_arrays(self, xp, cond_type, x_type, y_type):
 @testing.gpu
 class TestWhereCond(unittest.TestCase):
 
-    @testing.for_all_dtypes(no_complex=True)
+    @testing.for_all_dtypes()
     @testing.numpy_cupy_array_list_equal()
     def test_where_cond(self, xp, dtype):
         m = testing.shaped_random(self.cond_shape, xp, xp.bool_)
Repository: cupy/cupy

Issue:
cp.sinc fails for complex input
Unlike the numpy version, `cupy.sinc` fails on complex inputs:

```python
>>> np.sinc(1j)
(3.676077910374978+0j)
>>> cp.sinc(1j)
TypeError                                 Traceback (most recent call last)
----> 1 cp.sinc(1j)
cupy/core/_kernel.pyx in cupy.core._kernel.ufunc.__call__()
cupy/core/_kernel.pyx in cupy.core._kernel._guess_routine()
TypeError: Wrong type ((<class 'numpy.complex128'>,)) of arguments for cupy_sinc
```

Either the docs should be updated or the underlying implementation should be fixed.

```python
>>> cp.show_config()
CuPy Version          : 6.0.0
CUDA Root             : /usr/local/cuda
CUDA Build Version    : 10000
CUDA Driver Version   : 10010
CUDA Runtime Version  : 10000
cuDNN Build Version   : 7301
cuDNN Version         : 7604
NCCL Build Version    : 1000
NCCL Runtime Version  : (unknown)
```


Discussion:

Resolving patch:
diff --git a/cupy/math/special.py b/cupy/math/special.py
--- a/cupy/math/special.py
+++ b/cupy/math/special.py
@@ -12,7 +12,12 @@
 
 
 sinc = core.create_ufunc(
-    'cupy_sinc', ('e->e', 'f->f', 'd->d'),
+    'cupy_sinc',
+    ('e->e', 'f->f', 'd->d',
+     ('F->F', 'in0_type pi_in0 = (in0_type) M_PI * in0;'
+              'out0 = abs(in0) > 1e-9 ? sin(pi_in0) / (pi_in0) : 1'),
+     ('D->D', 'in0_type pi_in0 = (in0_type) M_PI * in0;'
+              'out0 = abs(in0) > 1e-9 ? sin(pi_in0) / (pi_in0) : 1')),
     'out0 = abs(in0) > 1e-9 ? sinpi(in0) / (M_PI * in0) : 1',
     doc='''Elementwise sinc function.
 


Test patch:
diff --git a/tests/cupy_tests/math_tests/test_special.py b/tests/cupy_tests/math_tests/test_special.py
--- a/tests/cupy_tests/math_tests/test_special.py
+++ b/tests/cupy_tests/math_tests/test_special.py
@@ -13,13 +13,13 @@ def test_i0(self, xp, dtype):
         a = testing.shaped_random((2, 3), xp, dtype)
         return xp.i0(a)
 
-    @testing.for_dtypes(['e', 'f', 'd'])
+    @testing.for_dtypes(['e', 'f', 'd', 'F', 'D'])
     @testing.numpy_cupy_allclose(atol=1e-3)
     def test_sinc(self, xp, dtype):
-        a = testing.shaped_random((2, 3), xp, dtype)
+        a = testing.shaped_random((2, 3), xp, dtype, scale=1)
         return xp.sinc(a)
 
-    @testing.for_dtypes(['e', 'f', 'd'])
+    @testing.for_dtypes(['e', 'f', 'd', 'F', 'D'])
     def test_sinc_zero(self, dtype):
         a = cupy.sinc(cupy.zeros(1, dtype=dtype))
         testing.assert_array_equal(a, cupy.ones(1, dtype=dtype))
Repository: cupy/cupy

Issue:
problem in calculating inverse of complex matrix with cupy.linalg.pinv
Hello, 
I am using cupy.linalg.pinv to calculate inverse of complex matrix. And the result is different from numpy.linalg.pinv, only imaginary part.

I know that if
![render](https://user-images.githubusercontent.com/57126850/67747083-5110a200-fa6b-11e9-9350-690f9c0666df.png) is the SVD of A, then pseudoinverse is ![render2](https://user-images.githubusercontent.com/57126850/67747134-78676f00-fa6b-11e9-87b7-fbdda3a76fe7.png).

And there is no code in the cupy source to consider the conjugate transpose U * or V*.

I think you need to add 
`a = a.conj()` 
before calculating svd of A or
`return core.dot(vt.T.conj(), s1[:, None] * u.T.conj())`


Thank you. 


Discussion:
@YoujinShin Thank you for raising an issue, do you have interest in sending a PR?
Ok, I will send PR.
Thanks!

Resolving patch:
diff --git a/cupy/linalg/solve.py b/cupy/linalg/solve.py
--- a/cupy/linalg/solve.py
+++ b/cupy/linalg/solve.py
@@ -418,7 +418,7 @@ def pinv(a, rcond=1e-15):
 
     .. seealso:: :func:`numpy.linalg.pinv`
     """
-    u, s, vt = decomposition.svd(a, full_matrices=False)
+    u, s, vt = decomposition.svd(a.conj(), full_matrices=False)
     cutoff = rcond * s.max()
     s1 = 1 / s
     s1[s <= cutoff] = 0


Test patch:
diff --git a/tests/cupy_tests/linalg_tests/test_solve.py b/tests/cupy_tests/linalg_tests/test_solve.py
--- a/tests/cupy_tests/linalg_tests/test_solve.py
+++ b/tests/cupy_tests/linalg_tests/test_solve.py
@@ -130,11 +130,11 @@ def test_batched_inv(self, dtype, xp):
 @testing.gpu
 class TestPinv(unittest.TestCase):
 
-    @testing.for_float_dtypes(no_float16=True)
+    @testing.for_dtypes('fdFD')
     @condition.retry(10)
     def check_x(self, a_shape, rcond, dtype):
-        a_cpu = numpy.random.randint(0, 10, size=a_shape).astype(dtype)
-        a_gpu = cupy.asarray(a_cpu)
+        a_gpu = testing.shaped_random(a_shape, dtype=dtype)
+        a_cpu = cupy.asnumpy(a_gpu)
         a_gpu_copy = a_gpu.copy()
         result_cpu = numpy.linalg.pinv(a_cpu, rcond=rcond)
         result_gpu = cupy.linalg.pinv(a_gpu, rcond=rcond)
Repository: cupy/cupy

Issue:
CUPY 7.0 fails with Python 2.7
* Conditions (you can just paste the output of `python -c 'import cupy; cupy.show_config()'`)
 - Python version 2.7.15+
  - CuPy version 7.0.0
  - Ubuntu 18.04
  - CUDA version NA
  - cuDNN/NCCL version (if applicable) NA
* Code to reproduce
```
Run python, issue `import cupy`.
```
* Error messages, stack traces, or logs
```
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/cupy/__init__.py", line 47, in <module>
    import cupyx as _cupyx
  File "/usr/local/lib/python2.7/dist-packages/cupyx/__init__.py", line 11, in <module>
    from cupyx._ufunc_config import errstate  # NOQA
  File "/usr/local/lib/python2.7/dist-packages/cupyx/_ufunc_config.py", line 17
    def errstate(*, divide=None, over=None, under=None, invalid=None, linalg=None):
                  ^
SyntaxError: invalid syntax
```



Discussion:
Hi Janusz.
7.0 only supports Python 3.5-3.8. I think you will have to stay on the 6.x releases for python 2 support.
Hi Gregory,
Thank you for the response. I just noticed that prebuild packages are not available for Python 2.7, and the reason why it installs in my case is that source distribution cannot be limited to a particular python version.
Maybe source distribution installation could fail with python 2.7 with an appropriate message?

Resolving patch:
diff --git a/cupy/__init__.py b/cupy/__init__.py
--- a/cupy/__init__.py
+++ b/cupy/__init__.py
@@ -811,18 +811,3 @@ def show_config():
     """Prints the current runtime configuration to standard output."""
     sys.stdout.write(str(_cupyx.get_runtime_info()))
     sys.stdout.flush()
-
-
-# -----------------------------------------------------------------------------
-# Warning for Python 2 users
-# -----------------------------------------------------------------------------
-if sys.version_info[:1] == (2,):
-    warnings.warn('''
---------------------------------------------------------------------------------
-CuPy is going to stop supporting Python 2 in v7.x releases.
-
-Future releases of CuPy v7.x will not run on Python 2.
-If you need to continue using Python 2, consider using CuPy v6.x, which
-will be the last version that runs on Python 2.
---------------------------------------------------------------------------------
-''')  # NOQA
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -208,6 +208,7 @@ def reduce_requirements(key):
     ],
     package_data=package_data,
     zip_safe=False,
+    python_requires='>=3.5.0',
     setup_requires=setup_requires,
     install_requires=install_requires,
     tests_require=tests_require,


Test patch:
Repository: cupy/cupy

Issue:
Remove dtype argument from min/max?
It looks to me there's no point for these functions to have `dtype` argument.
They should be keyword-only at the very least, for numpy compatibility.


Discussion:
Related: #2595

Resolving patch:
diff --git a/cupy/statistics/order.py b/cupy/statistics/order.py
--- a/cupy/statistics/order.py
+++ b/cupy/statistics/order.py
@@ -7,7 +7,7 @@
 from cupy.logic import content
 
 
-def amin(a, axis=None, out=None, keepdims=False, dtype=None):
+def amin(a, axis=None, out=None, keepdims=False):
     """Returns the minimum of an array or the minimum along an axis.
 
     .. note::
@@ -22,7 +22,6 @@ def amin(a, axis=None, out=None, keepdims=False, dtype=None):
         out (cupy.ndarray): Output array.
         keepdims (bool): If ``True``, the axis is remained as an axis of
             size one.
-        dtype: Data type specifier.
 
     Returns:
         cupy.ndarray: The minimum of ``a``, along the axis if specified.
@@ -35,13 +34,13 @@ def amin(a, axis=None, out=None, keepdims=False, dtype=None):
             raise NotImplementedError(
                 'cupy.amin does not support `keepdims` in fusion yet.')
         return fusion._call_reduction(_statistics.amin,
-                                      a, axis=axis, dtype=dtype, out=out)
+                                      a, axis=axis, out=out)
 
     # TODO(okuta): check type
-    return a.min(axis=axis, dtype=dtype, out=out, keepdims=keepdims)
+    return a.min(axis=axis, out=out, keepdims=keepdims)
 
 
-def amax(a, axis=None, out=None, keepdims=False, dtype=None):
+def amax(a, axis=None, out=None, keepdims=False):
     """Returns the maximum of an array or the maximum along an axis.
 
     .. note::
@@ -56,7 +55,6 @@ def amax(a, axis=None, out=None, keepdims=False, dtype=None):
         out (cupy.ndarray): Output array.
         keepdims (bool): If ``True``, the axis is remained as an axis of
             size one.
-        dtype: Data type specifier.
 
     Returns:
         cupy.ndarray: The maximum of ``a``, along the axis if specified.
@@ -69,10 +67,10 @@ def amax(a, axis=None, out=None, keepdims=False, dtype=None):
             raise NotImplementedError(
                 'cupy.amax does not support `keepdims` in fusion yet.')
         return fusion._call_reduction(_statistics.amax,
-                                      a, axis=axis, dtype=dtype, out=out)
+                                      a, axis=axis, out=out)
 
     # TODO(okuta): check type
-    return a.max(axis=axis, dtype=dtype, out=out, keepdims=keepdims)
+    return a.max(axis=axis, out=out, keepdims=keepdims)
 
 
 def nanmin(a, axis=None, out=None, keepdims=False):


Test patch:
Repository: cupy/cupy

Issue:
Windows: module 'numpy' has no attribute 'complex256'
In file: [cupy/cupyx/scipy/ndimage/filters.py] (https://github.com/cupy/cupy/blob/master/cupyx/scipy/ndimage/filters.py)

Line 83:  ` if input.dtype in (numpy.complex64, numpy.complex128, numpy.complex256):`

There is a check for numpy.complex256. On Windows there is no numpy.complex256, so this line leads to the following error:

module 'numpy' has no attribute 'complex256'

a simple solution could be to use the function [numpy.iscomplexobj
](https://docs.scipy.org/doc/numpy/reference/generated/numpy.iscomplexobj.html#numpy.iscomplexobj) or (maybe faster) to stringify the dtype of the array and check for substring "complex"


Discussion:

Resolving patch:
diff --git a/cupyx/scipy/ndimage/filters.py b/cupyx/scipy/ndimage/filters.py
--- a/cupyx/scipy/ndimage/filters.py
+++ b/cupyx/scipy/ndimage/filters.py
@@ -1,5 +1,3 @@
-import numpy
-
 import cupy
 from cupy import util
 
@@ -80,7 +78,7 @@ def _get_output(output, input, shape=None):
 
 def _correlate_or_convolve(input, weights, output, mode, cval, origin,
                            convolution):
-    if input.dtype in (numpy.complex64, numpy.complex128, numpy.complex256):
+    if input.dtype.kind == 'c':
         raise TypeError('Complex type not supported.')
     if not hasattr(origin, '__getitem__'):
         origin = [origin, ] * input.ndim


Test patch:
Repository: cupy/cupy

Issue:
time.clock was removed in Python 3.8
https://github.com/python/cpython/pull/13270 . Given that the project is Python 3 only it will be better to use the alternatives. There is https://github.com/cupy/cupy/issues/2599 for Python 3.8 but not sure why it didn't error out.

https://github.com/cupy/cupy/blob/8d923719ced31fdff4a42702d395ec87a7e98045/cupy/random/generator.py#L681


Discussion:
This is not relevant to this issue, but `try... except NotImplementedError` should only enclose `os.urandom`.

https://github.com/cupy/cupy/blob/8d923719ced31fdff4a42702d395ec87a7e98045/cupy/random/generator.py#L677-L681
I would like to make this change.

will be raising a PR soon.

Resolving patch:
diff --git a/cupy/random/generator.py b/cupy/random/generator.py
--- a/cupy/random/generator.py
+++ b/cupy/random/generator.py
@@ -685,7 +685,7 @@ def seed(self, seed=None):
                 seed_str = binascii.hexlify(os.urandom(8))
                 seed = int(seed_str, 16)
             except NotImplementedError:
-                seed = (time.clock() * 1000000) % _UINT64_MAX
+                seed = (time.time() * 1000000) % _UINT64_MAX
         else:
             if isinstance(seed, numpy.ndarray):
                 seed = int(hashlib.md5(seed).hexdigest()[:16], 16)
@@ -1193,9 +1193,9 @@ def seed(seed=None):
 
     Args:
         seed (None or int): Seed for the random number generator. If ``None``,
-            it uses :func:`os.urandom` if available or :func:`time.clock`
-            otherwise. Note that this function does not support seeding by an
-            integer array.
+            it uses :func:`os.urandom` if available or :func:`time.time`
+            otherwise. Note that this function does not support seeding by
+            an integer array.
 
     """
     get_random_state().seed(seed)


Test patch:
Repository: cupy/cupy

Issue:
Incorrect behavior with empty arrays for `linalg.qr` and `linalg.svd`
`qr` and `svd` routines raise `CUSOLVERError: CUSOLVER_STATUS_INVALID_VALUE` for zero-sized input arrays.
NumPy supports this kind of input for `qr`, `svd` since 1.16
https://github.com/numpy/numpy/blob/master/doc/release/1.16.0-notes.rst#linalglstsq-linalgqr-and-linalgsvd-now-work-with-empty-arrays
The problem is that when calling cuSOLVER routines leading dimension is passed as `input.shape[0]` but it should be `max(1, input.shape[0])`.



Discussion:

Resolving patch:
diff --git a/cupy/linalg/decomposition.py b/cupy/linalg/decomposition.py
--- a/cupy/linalg/decomposition.py
+++ b/cupy/linalg/decomposition.py
@@ -357,7 +357,16 @@ def svd(a, full_matrices=True, compute_uv=True):
         m, n = a.shape
         x = a.transpose().astype(a_dtype, order='C', copy=True)
         trans_flag = True
+
     mn = min(m, n)
+    if mn == 0:
+        if compute_uv:
+            if full_matrices:
+                return cupy.eye(m, m), cupy.empty((0,)), cupy.empty((0, 0))
+            else:
+                return cupy.empty((m, 0)), cupy.empty((0,)), cupy.empty((0, 0))
+        else:
+            return cupy.empty((0,))
 
     if compute_uv:
         if full_matrices:


Test patch:
diff --git a/tests/cupy_tests/linalg_tests/test_decomposition.py b/tests/cupy_tests/linalg_tests/test_decomposition.py
--- a/tests/cupy_tests/linalg_tests/test_decomposition.py
+++ b/tests/cupy_tests/linalg_tests/test_decomposition.py
@@ -203,3 +203,16 @@ def test_svd_no_uv(self):
     def test_rank2(self):
         self.check_rank2(cupy.random.randn(2, 3, 4).astype(numpy.float32))
         self.check_rank2(cupy.random.randn(1, 2, 3, 4).astype(numpy.float64))
+
+    @testing.with_requires('numpy>=1.16')
+    def test_empty_array(self):
+        self.check_usv((0, 3))
+        self.check_usv((3, 0))
+        self.check_usv((1, 0))
+
+    @testing.with_requires('numpy>=1.16')
+    @testing.numpy_cupy_array_equal()
+    def test_empty_array_compute_uv_false(self, xp):
+        array = xp.empty((3, 0))
+        return xp.linalg.svd(
+            array, full_matrices=self.full_matrices, compute_uv=False)
Repository: cupy/cupy

Issue:
feature request:  add ability to pass multiple arches using CUPY_NVCC_GENERATE_CODE
It would be very helpful to change this line
https://github.com/cupy/cupy/blob/2804af926cead8d2e80665283473a71212e824b0/cupy_setup_build.py#L765
to use list comprehension in order to pass multiple architectures on the command line.  This is useful for building the list of not included architectures from Jetson such as 53,62,and 72.

Something like this with + sign delimited works great
`return ['--generate-code={}'.format(val) for val in envcfg.split('+')]`

and allows me to build with CUPY_NVCC_GENERATE_CODE="arch=compute_62,code=sm_62+arch=compute_72,code=sm_72" and everything builds great.




Discussion:
I guess for style consistency with CuPy's companioning project Chainer, we better use semicolon as the delimiter, see https://github.com/chainer/chainer/pull/8370.

Resolving patch:
diff --git a/cupy_setup_build.py b/cupy_setup_build.py
--- a/cupy_setup_build.py
+++ b/cupy_setup_build.py
@@ -762,7 +762,8 @@ def _nvcc_gencode_options(cuda_version):
 
     envcfg = os.getenv('CUPY_NVCC_GENERATE_CODE', None)
     if envcfg:
-        return ['--generate-code={}'.format(envcfg)]
+        return ['--generate-code={}'.format(arch)
+                for arch in envcfg.split(';') if len(arch) > 0]
 
     # The arch_list specifies virtual architectures, such as 'compute_61', and
     # real architectures, such as 'sm_61', for which the CUDA input files are


Test patch: