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

Issue:
Fix unichrseq/unicode_str comparison
Tracker for fixing https://github.com/numba/numba/issues/6136#issuecomment-676478458
Fix unichrseq/unicode_str comparison
Tracker for fixing https://github.com/numba/numba/issues/6136#issuecomment-676478458


Discussion:

Resolving patch:
diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py
--- a/numba/cpython/unicode.py
+++ b/numba/cpython/unicode.py
@@ -456,6 +456,9 @@ def unicode_eq(a, b):
     b_unicode = isinstance(b, accept)
     if a_unicode and b_unicode:
         def eq_impl(a, b):
+            # the str() is for UnicodeCharSeq, it's a nop else
+            a = str(a)
+            b = str(b)
             if len(a) != len(b):
                 return False
             return _cmp_region(a, 0, b, 0, len(a)) == 0
@@ -703,6 +706,7 @@ def unicode_partition(data, sep):
 
     def impl(data, sep):
         # https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/stringlib/partition.h#L7-L60    # noqa: E501
+        sep = str(sep)
         empty_str = _empty_string(data._kind, 0, data._is_ascii)
         sep_length = len(sep)
         if data._kind < sep._kind or len(data) < sep_length:
@@ -775,6 +779,7 @@ def unicode_rpartition(data, sep):
 
     def impl(data, sep):
         # https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/stringlib/partition.h#L62-L115    # noqa: E501
+        sep = str(sep)
         empty_str = _empty_string(data._kind, 0, data._is_ascii)
         sep_length = len(sep)
         if data._kind < sep._kind or len(data) < sep_length:
@@ -1105,6 +1110,7 @@ def rsplit_whitespace_impl(data, sep=None, maxsplit=-1):
         return rsplit_whitespace_impl
 
     def rsplit_impl(data, sep=None, maxsplit=-1):
+        sep = str(sep)
         # https://github.com/python/cpython/blob/1d4b6ba19466aba0eb91c4ba01ba509acf18c723/Objects/stringlib/split.h#L286-L333    # noqa: E501
         if data._kind < sep._kind or len(data) < len(sep):
             return [data]


Test patch:
Repository: numba/numba

Issue:
CUDA get_arch_option TypeError in formatting if CUDA install broken
- [x] I have tried using the latest released version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [x] I have included below a minimal working reproducer (if you are unsure how
 to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

From https://stackoverflow.com/questions/63783129/numba-vectorize-not-working-properly-on-a-simple-example

If a CUDA installation is not working for some reason, e.g. no `cudatoolkit` package (this is actually the easiest way to reproduce), then something like:

```python
from numba import vectorize
import numpy as np

@vectorize(['float64(float64)'], target='cuda')
def foo(x):
    return 1

foo(np.ones(1))
```
produces:
```
  File "<path>/numba/cuda/dispatcher.py", line 41, in __call__
    return CUDAUFuncMechanism.call(self.functions, args, kws)
  File "<path>/numba/np/ufunc/deviceufunc.py", line 300, in call
    cr.launch(func, shape[0], stream, devarys)
  File "<path>/numba/cuda/dispatcher.py", line 152, in launch
    func.forall(count, stream=stream)(*args)
  File "<path>/numba/cuda/compiler.py", line 372, in __call__
    kernel = self.kernel.specialize(*args)
  File "<path>/numba/cuda/compiler.py", line 893, in specialize
    self._bind, targetoptions)
  File "<path>/numba/cuda/compiler.py", line 808, in __init__
    self.compile(sigs[0])
  File "<path>/numba/cuda/compiler.py", line 946, in compile
    kernel.bind()
  File "<path>/numba/cuda/compiler.py", line 576, in bind
    self._func.get()
  File "<path>/numba/cuda/compiler.py", line 446, in get
    ptx = self.ptx.get()
  File "<path>/numba/cuda/compiler.py", line 414, in get
    arch = nvvm.get_arch_option(*cc)
  File "<path>/numba/cuda/cudadrv/nvvm.py", line 345, in get_arch_option
    return 'compute_%d%d' % arch
TypeError: not enough arguments for format string
```
because `find_closest_arch` is returning an empty tuple.


Discussion:

Resolving patch:
diff --git a/numba/cuda/cudadrv/nvvm.py b/numba/cuda/cudadrv/nvvm.py
--- a/numba/cuda/cudadrv/nvvm.py
+++ b/numba/cuda/cudadrv/nvvm.py
@@ -293,7 +293,7 @@ def get_supported_ccs():
 
     # List of supported compute capability in sorted order
     if cudart_version_major == 0:
-        _supported_cc = (),
+        _supported_cc = ()
     elif cudart_version_major < 9:
         # CUDA 8.x
         _supported_cc = (2, 0), (2, 1), (3, 0), (3, 5), (5, 0), (5, 2), (5, 3), (6, 0), (6, 1), (6, 2) # noqa: E501
@@ -320,6 +320,11 @@ def find_closest_arch(mycc):
     """
     supported_cc = get_supported_ccs()
 
+    if not supported_cc:
+        msg = "No supported GPU compute capabilities found. " \
+              "Please check your cudatoolkit version matches your CUDA version."
+        raise NvvmSupportError(msg)
+
     for i, cc in enumerate(supported_cc):
         if cc == mycc:
             # Matches


Test patch:
Repository: numba/numba

Issue:
Reminder to remove the `numba.jitclass` shim
This is a reminder to remove the `numba.jitclass` shim for 0.5x, at the moment x=1. Perhaps x should be 2, so that users have a bit more time. xref schedule: http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#id7


Discussion:

Resolving patch:
diff --git a/numba/__init__.py b/numba/__init__.py
--- a/numba/__init__.py
+++ b/numba/__init__.py
@@ -49,9 +49,6 @@
 # Re-export experimental
 from numba import experimental
 
-# Re-export experimental.jitclass as jitclass, this is deprecated
-from numba.experimental.jitclass.decorators import _warning_jitclass as jitclass
-
 # Initialize withcontexts
 import numba.core.withcontexts
 from numba.core.withcontexts import objmode_context as objmode
diff --git a/numba/experimental/jitclass/decorators.py b/numba/experimental/jitclass/decorators.py
--- a/numba/experimental/jitclass/decorators.py
+++ b/numba/experimental/jitclass/decorators.py
@@ -1,6 +1,4 @@
-import warnings
-
-from numba.core import types, config, errors
+from numba.core import types, config
 from numba.experimental.jitclass.base import register_class_type, ClassBuilder
 
 
@@ -28,23 +26,3 @@ def wrap(cls):
             return register_class_type(cls, spec, types.ClassType, ClassBuilder)
 
     return wrap
-
-
-def _warning_jitclass(spec):
-    """
-    Re-export of numba.experimental.jitclass with a warning.
-    To be used in numba/__init__.py.
-    This endpoint is deprecated.
-    """
-    url = ("https://numba.pydata.org/numba-doc/latest/reference/"
-           "deprecation.html#change-of-jitclass-location")
-
-    msg = ("The 'numba.jitclass' decorator has moved to "
-           "'numba.experimental.jitclass' to better reflect the experimental "
-           "nature of the functionality. Please update your imports to "
-           "accommodate this change and see {} for the time frame.".format(url))
-
-    warnings.warn(msg, category=errors.NumbaDeprecationWarning,
-                  stacklevel=2)
-
-    return jitclass(spec)


Test patch:
diff --git a/numba/tests/test_jitclasses.py b/numba/tests/test_jitclasses.py
--- a/numba/tests/test_jitclasses.py
+++ b/numba/tests/test_jitclasses.py
@@ -2,9 +2,7 @@
 import ctypes
 import random
 import pickle
-import warnings
 
-import numba
 import numpy as np
 
 from numba import (float32, float64, int16, int32, boolean, deferred_type,
@@ -1027,20 +1025,6 @@ def call_static(self):
         self.assertIn("Unknown attribute 'a_static_method'",
                       str(raises.exception))
 
-    def test_import_warnings(self):
-        class Test:
-            def __init__(self):
-                pass
-
-        with warnings.catch_warnings(record=True) as ws:
-            numba.experimental.jitclass([])(Test)
-            self.assertEqual(len(ws), 0)
-
-            numba.jitclass([])(Test)
-            self.assertEqual(len(ws), 1)
-            self.assertIs(ws[0].category, errors.NumbaDeprecationWarning)
-            self.assertIn("numba.experimental.jitclass", ws[0].message.msg)
-
 
 if __name__ == '__main__':
     unittest.main()
Repository: numba/numba

Issue:
`TypeRef` should implement `key`
- [x] I have tried using the latest released version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [x] I have included below a minimal working reproducer (if you are unsure how
 to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

`types.abstract.TypeRef` should implement `key`, otherwise it can happen that `aty != bty` but `TypeRef(aty) == TypeRef(bty)` when `aty.name == bty.name and aty.key != bty.key`.

Self contained example:
```python
from numba import types

class NoUniqueNameType(types.Dummy):
    def __init__(self, param):
        super(NoUniqueNameType, self).__init__('NoUniqueNameType')
        self.param = param

    @property
    def key(self):
        return self.param

no_unique_name_type_1 = NoUniqueNameType(1)
no_unique_name_type_2 = NoUniqueNameType(2)

assert no_unique_name_type_1  != no_unique_name_type_2
assert types.TypeRef(no_unique_name_type_1  ) != types.TypeRef(no_unique_name_type_2) 
```



Discussion:

Resolving patch:
diff --git a/numba/core/types/abstract.py b/numba/core/types/abstract.py
--- a/numba/core/types/abstract.py
+++ b/numba/core/types/abstract.py
@@ -464,6 +464,10 @@ def __init__(self, instance_type):
         self.instance_type = instance_type
         super(TypeRef, self).__init__('typeref[{}]'.format(self.instance_type))
 
+    @property
+    def key(self):
+        return self.instance_type
+
 
 class InitialValue(object):
     """


Test patch:
diff --git a/numba/tests/test_types.py b/numba/tests/test_types.py
--- a/numba/tests/test_types.py
+++ b/numba/tests/test_types.py
@@ -855,6 +855,25 @@ def g():
         self.assertEqual(f(), 2)
         self.assertEqual(g(), 101)
 
+    def test_issue_typeref_key(self):
+        # issue https://github.com/numba/numba/issues/6336
+        class NoUniqueNameType(types.Dummy):
+            def __init__(self, param):
+                super(NoUniqueNameType, self).__init__('NoUniqueNameType')
+                self.param = param
+
+            @property
+            def key(self):
+                return self.param
+
+        no_unique_name_type_1 = NoUniqueNameType(1)
+        no_unique_name_type_2 = NoUniqueNameType(2)
+
+        for ty1 in (no_unique_name_type_1, no_unique_name_type_2):
+            for ty2 in (no_unique_name_type_1, no_unique_name_type_2):
+                self.assertIs(
+                    types.TypeRef(ty1) == types.TypeRef(ty2), ty1 == ty2)
+
 
 if __name__ == '__main__':
     unittest.main()
Repository: numba/numba

Issue:
CUDA: Performance regression launching specialized kernels
Presently launching a specialized kernel on master (9381206a03a3e7231d417f147474577745f6a720) takes around twice as long as it used to once a few arguments are involved. For the test case described in https://github.com/numba/numba/issues/3003#issuecomment-627872661, which looks like:

```python
from numba import cuda
import numpy as np

@cuda.jit('void()')
def some_kernel_1():
    return

@cuda.jit('void(float32[:])')
def some_kernel_2(arr1):
    return

@cuda.jit('void(float32[:],float32[:])')
def some_kernel_3(arr1,arr2):
    return

@cuda.jit('void(float32[:],float32[:],float32[:])')
def some_kernel_4(arr1,arr2,arr3):
    return

@cuda.jit('void(float32[:],float32[:],float32[:],float32[:])')
def some_kernel_5(arr1,arr2,arr3,arr4):
    return

arr = cuda.device_array(10000, dtype=np.float32)

%timeit some_kernel_1[1, 1]()
%timeit some_kernel_2[1, 1](arr)
%timeit some_kernel_3[1, 1](arr,arr)
%timeit some_kernel_4[1, 1](arr,arr,arr)
%timeit some_kernel_5[1, 1](arr,arr,arr,arr)
```

the timings are currently:

```
27.6 µs ± 228 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
62.6 µs ± 278 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
87.9 µs ± 700 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
109 µs ± 405 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
131 µs ± 365 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
```

whereas they were previously much lower - e.g.:

```
26.4 µs ± 78 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
41.4 µs ± 185 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
51.1 µs ± 511 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
59.5 µs ± 193 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
68 µs ± 87 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
```

with #6042 (now merged) when it was first opened.


Discussion:

Resolving patch:
diff --git a/numba/cuda/compiler.py b/numba/cuda/compiler.py
--- a/numba/cuda/compiler.py
+++ b/numba/cuda/compiler.py
@@ -870,9 +870,12 @@ def call(self, args, griddim, blockdim, stream, sharedmem):
         '''
         Compile if necessary and invoke this kernel with *args*.
         '''
-        argtypes = tuple(
-            [self.typingctx.resolve_argument_type(a) for a in args])
-        kernel = self.compile(argtypes)
+        if self.specialized:
+            kernel = self.definition
+        else:
+            argtypes = tuple([self.typingctx.resolve_argument_type(a)
+                              for a in args])
+            kernel = self.compile(argtypes)
         kernel.launch(args, griddim, blockdim, stream, sharedmem)
 
     def specialize(self, *args):


Test patch:
Repository: numba/numba

Issue:
0.52.0rc2 regression: invalid array data if used after print
<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

-->

## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I have tried using the latest released version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [x] I have included below a minimal working reproducer (if you are unsure how
 to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

<!--

Please include details of the bug here, including, if applicable, what you
expected to happen!

-->
Array data looks invalid if used after a print. Looks like a refcount issue:
```python
import numba
import numpy as np

@numba.njit
def f():
    A = np.ones(3)
    print(A)
    return A[0]

print(f())
```
```
[1. 1. 1.]
-9.868309920863368e+148
```


Discussion:
Thanks for the report. Think this is the diamond pruner:
```python
import numba
import numpy as np

@numba.njit
def f():
    A = np.ones(3)
    print(A)
    return A[0]

print(f())
f.inspect_cfg(f.signatures[0]).display(view=True)
cres = f.overloads[f.signatures[0]]
print(cres.metadata['prune_stats'])
```
Output:
```
$ NUMBA_LLVM_REFPRUNE_FLAGS='diamond' python issue6444.py 
[1. 1. 1.]
-9.868309920863368e+148
PruneStats(basicblock=0, diamond=2, fanout=0, fanout_raise=0)
```
This is coming from `NRT_adapt_ndarray_to_python` that is stealing a reference and the pruner did not account for the stealing.

Resolving patch:
diff --git a/numba/core/boxing.py b/numba/core/boxing.py
--- a/numba/core/boxing.py
+++ b/numba/core/boxing.py
@@ -396,8 +396,9 @@ def box_array(typ, val, c):
     if c.context.enable_nrt:
         np_dtype = numpy_support.as_dtype(typ.dtype)
         dtypeptr = c.env_manager.read_const(c.env_manager.add_const(np_dtype))
-        # Steals NRT ref
         newary = c.pyapi.nrt_adapt_ndarray_to_python(typ, val, dtypeptr)
+        # Steals NRT ref
+        c.context.nrt.decref(c.builder, typ, val)
         return newary
     else:
         parent = nativeary.parent
diff --git a/numba/core/pythonapi.py b/numba/core/pythonapi.py
--- a/numba/core/pythonapi.py
+++ b/numba/core/pythonapi.py
@@ -1189,7 +1189,7 @@ def nrt_adapt_ndarray_to_python(self, aryty, ary, dtypeptr):
         intty = ir.IntType(32)
         fnty = Type.function(self.pyobj,
                              [self.voidptr, intty, intty, self.pyobj])
-        fn = self._get_function(fnty, name="NRT_adapt_ndarray_to_python")
+        fn = self._get_function(fnty, name="NRT_adapt_ndarray_to_python_acqref")
         fn.args[0].add_attribute(lc.ATTR_NO_CAPTURE)
 
         ndim = self.context.get_constant(types.int32, aryty.ndim)


Test patch:
Repository: numba/numba

Issue:
typed.List.extend returns self in some cases
```python
from numba.typed import List
  ...: my_list = List([1,2])
  ...: print(my_list.extend(List([1,2])))
  ...: print(my_list.extend(tuple()))
None
[1, 2, 1, 2]
```

It should always return None but in some cases it's returning self. Below is python list's behaviour.

```python
  ...: my_list = list([1,2])
  ...: print(my_list.extend(list([1,2])))
  ...: print(my_list.extend(tuple()))
None
None
```
_Originally posted by @luk-f-a in https://github.com/numba/numba/issues/5958#issuecomment-734750145_


Discussion:

Resolving patch:
diff --git a/numba/typed/typedlist.py b/numba/typed/typedlist.py
--- a/numba/typed/typedlist.py
+++ b/numba/typed/typedlist.py
@@ -357,7 +357,7 @@ def pop(self, i=-1):
     def extend(self, iterable):
         # Empty iterable, do nothing
         if len(iterable) == 0:
-            return self
+            return None
         if not self._typed:
             # Need to get the first element of the iterable to initialise the
             # type of the list. FIXME: this may be a problem if the iterable


Test patch:
diff --git a/numba/tests/test_typedlist.py b/numba/tests/test_typedlist.py
--- a/numba/tests/test_typedlist.py
+++ b/numba/tests/test_typedlist.py
@@ -776,7 +776,8 @@ def test_extend_empty_unrefined(self):
         # Extending an unrefined list with an empty iterable doesn't work in a
         # jit compiled function as the list remains untyped.
         l = List()
-        l.extend(tuple())
+        ret = l.extend(tuple())
+        self.assertIsNone(ret)
         self.assertEqual(len(l), 0)
         self.assertFalse(l._typed)
Repository: numba/numba

Issue:
Update canonical_url configuration in docs
I think we need to fix the canonical_url in our generated docs, especially now that we have moved documentation to RTD.  This should help search engines direct users to the latest documentation even after indexing older versions.    According to the sphinx RTD theme, the URL should be the base path:

https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html#confval-canonical_url

I think we did this incorrectly before (linking to the index file, rather than the base URL), so we will need to fix the path as well as relocate to the new Numba docs domain:

https://github.com/numba/numba/blob/master/docs/source/conf.py#L125


Discussion:
for more info about how canonical URLs are treated by search engines: https://yoast.com/rel-canonical/

(hat tip to Kevin Sheppard on the NumPy mailing list for the link)

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -122,7 +122,7 @@
 # All sphinx_rtd_theme options. Default values commented out; uncomment to
 # change.
 html_theme_options = {
-    'canonical_url': 'https://numba.pydata.org/numba-doc/latest/index.html',
+    'canonical_url': 'https://numba.readthedocs.io/en/stable/',
     # 'logo_only': False,
     # 'display_version': True,
     # 'prev_next_buttons_location': 'bottom',


Test patch:
Repository: numba/numba

Issue:
from numba import * fails due to jitclass still being in __all__
5f7ecf3bbfdf25b55f663f5278e4e31ad6fdde4c removes `jitclass` from the `numba` namespace, but `__init__.py`'s `__all__` still contains `jitclass`, causing `from numba import *` to fail.


Discussion:

Resolving patch:
diff --git a/numba/__init__.py b/numba/__init__.py
--- a/numba/__init__.py
+++ b/numba/__init__.py
@@ -66,7 +66,6 @@
     njit
     stencil
     jit_module
-    jitclass
     typeof
     prange
     gdb


Test patch:
diff --git a/numba/tests/test_import.py b/numba/tests/test_import.py
--- a/numba/tests/test_import.py
+++ b/numba/tests/test_import.py
@@ -61,6 +61,11 @@ def test_no_accidental_warnings(self):
         flags = ["-Werror",]
         self.run_in_subproc(code, flags)
 
+    def test_import_star(self):
+        # checks that "from numba import *" works.
+        code = "from numba import *"
+        self.run_in_subproc(code)
+
 
 if __name__ == '__main__':
     unittest.main()
Repository: numba/numba

Issue:
get_numba_envvar doesn't seem to return the right value
If the env var value is found, Instead of returning the value, the function returns the default value.

https://github.com/numba/numba/blob/42050e4a306e53f332fbaecf45248c54fae752e5/numba/cuda/envvars.py#L32


get_numba_envvar doesn't seem to return the right value
If the env var value is found, Instead of returning the value, the function returns the default value.

https://github.com/numba/numba/blob/42050e4a306e53f332fbaecf45248c54fae752e5/numba/cuda/envvars.py#L32




Discussion:
Looks like it might be an easy fix, simply `return value`?
Looks like it might be an easy fix, simply `return value`?

Resolving patch:
diff --git a/numba/cuda/envvars.py b/numba/cuda/envvars.py
--- a/numba/cuda/envvars.py
+++ b/numba/cuda/envvars.py
@@ -29,4 +29,4 @@ def get_numba_envvar(envvar, default=None):
     if value is None:
         return get_numbapro_envvar('NUMBAPRO_' + envvar, default=default)
     else:
-        return default
+        return value


Test patch:
diff --git a/numba/cuda/tests/nocuda/test_library_lookup.py b/numba/cuda/tests/nocuda/test_library_lookup.py
--- a/numba/cuda/tests/nocuda/test_library_lookup.py
+++ b/numba/cuda/tests/nocuda/test_library_lookup.py
@@ -18,6 +18,8 @@
     _get_cudalib_dir_path_decision,
     get_system_ctk,
 )
+from numba.cuda import envvars
+from numba.tests.support import override_env_config
 
 
 has_cuda = nvvm.is_available()
@@ -282,3 +284,28 @@ def _fake_non_conda_env():
     Monkeypatch sys.prefix to hide the fact we are in a conda-env
     """
     sys.prefix = ''
+
+
+class TestMisc(SerialMixin, unittest.TestCase):
+    """Test basic envvars lookup related functions
+    """
+    def test_get_numba_envvar(self):
+        # Make up an env-var that is not already defined.
+        # This makes a string with the following regex pattern "NUMBA_0+"
+        env = "0"
+        while f"NUMBA_{env}" in os.environ:
+            env += "0"
+        default = "the default"
+
+        # Check that we are getting the default
+        got = envvars.get_numba_envvar(env, default=default)
+        self.assertIs(got, default)
+
+        # Check that we are reading the env-var correctly
+        with override_env_config(f"NUMBA_{env}", "my value"):
+            got = envvars.get_numba_envvar(env, default=default)
+            self.assertEqual(got, "my value")
+
+
+if __name__ == '__main__':
+    unittest.main()