gurudesh/pytracebugs huggingface dataset:
# Buggy code
def np_nanmedian(a):
    if not isinstance(a, types.Array):
        return
    isnan = get_isnan(a.dtype)

    def nanmedian_impl(arry):
        # Create a temporary workspace with only non-NaN values
        temp_arry = np.empty(arry.size, arry.dtype)
        n = 0
        for view in np.nditer(arry):
            v = view.item()
            if not isnan(v):
                temp_arry[n] = v
                n += 1
        return _median_inner(temp_arry, n)

    return nanmedian_impl


# Traceback (AssertionError)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-15-cb312ec8285d> in <module>()
8 a = np.array([np.nan])
9 print(np.nanmedian(a))
---> 10 print(f(np.array([np.nan, np.nan])))

AssertionError:

# Fixed code
def np_nanmedian(a):
    if not isinstance(a, types.Array):
        return
    isnan = get_isnan(a.dtype)

    def nanmedian_impl(arry):
        # Create a temporary workspace with only non-NaN values
        temp_arry = np.empty(arry.size, arry.dtype)
        n = 0
        for view in np.nditer(arry):
            v = view.item()
            if not isnan(v):
                temp_arry[n] = v
                n += 1

        # all NaNs
        if n == 0:
            return np.nan

        return _median_inner(temp_arry, n)

    return nanmedian_impl
# Buggy code
def nanmedian_impl(arry):
    # Create a temporary workspace with only non-NaN values
    temp_arry = np.empty(arry.size, arry.dtype)
    n = 0
    for view in np.nditer(arry):
        v = view.item()
        if not isnan(v):
            temp_arry[n] = v
            n += 1
    return _median_inner(temp_arry, n)


# Traceback (AssertionError)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-15-cb312ec8285d> in <module>()
8 a = np.array([np.nan])
9 print(np.nanmedian(a))
---> 10 print(f(np.array([np.nan, np.nan])))

AssertionError:

# Fixed code
def nanmedian_impl(arry):
    # Create a temporary workspace with only non-NaN values
    temp_arry = np.empty(arry.size, arry.dtype)
    n = 0
    for view in np.nditer(arry):
        v = view.item()
        if not isnan(v):
            temp_arry[n] = v
            n += 1

    # all NaNs
    if n == 0:
        return np.nan

    return _median_inner(temp_arry, n)
# Buggy code
def same_exit_point(loop):
    "all exits must point to the same location"
    outedges = set()
    for k in loop.exits:
        outedges |= set(x for x, _ in cfg.successors(k))
    return len(outedges) == 1


# Traceback (ValueError)
Traceback (most recent call last):
File "numbabug.py", line 11, in <module>
numbafunc([])
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/dispatcher.py", line 307, in _compile_for_args
return self.compile(tuple(argtypes))
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/dispatcher.py", line 579, in compile
cres = self._compiler.compile(args, return_type)
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/dispatcher.py", line 80, in compile
flags=flags, locals=self.locals)
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/compiler.py", line 763, in compile_extra
return pipeline.compile_extra(func)
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/compiler.py", line 360, in compile_extra
return self._compile_bytecode()
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/compiler.py", line 722, in _compile_bytecode
return self._compile_core()
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/compiler.py", line 709, in _compile_core
res = pm.run(self.status)
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/compiler.py", line 246, in run
raise patched_exception
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/compiler.py", line 238, in run
stage()
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/compiler.py", line 431, in stage_objectmode_frontend
cres = self.frontend_looplift()
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/compiler.py", line 411, in frontend_looplift
flags=loop_flags)
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/transforms.py", line 191, in loop_lifting
func_ir.variable_lifetime.livemap)
File "/home/tuukka/.local/lib/python3.5/site-packages/numba/transforms.py", line 59, in _loop_lift_get_candidate_infos
[(returnto, _)] = cfg.successors(an_exit)  # requirement checked earlier
ValueError: Failed at object (object mode frontend)
not enough values to unpack (expected 1, got 0)

# Fixed code
def same_exit_point(loop):
    "all exits must point to the same location"
    outedges = set()
    for k in loop.exits:
        succs = set(x for x, _ in cfg.successors(k))
        if not succs:
            # If the exit point has no successor, it contains an return
            # statement, which is not handled by the looplifting code.
            # Thus, this loop is not a candidate.
            return False
        outedges |= succs
    return len(outedges) == 1
# Buggy code
def create_stream(self):
    handle = drvapi.cu_stream()
    driver.cuStreamCreate(byref(handle), 0)
    return Stream(
        weakref.proxy(self), handle, _stream_finalizer(self.allocations, handle)
    )


# Traceback (AttributeError)
test_pinned (numba.cuda.tests.cudadrv.test_pinned.TestPinned) ... Exception ignored in: <finalize object at 0x7f75a9726260; dead>
Traceback (most recent call last):
File "/home/antoine/numba/numba/utils.py", line 593, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 847, in core
deallocs.add_item(driver.cuStreamDestroy, handle)
AttributeError: 'UniqueDict' object has no attribute 'add_item'
ok
test_unpinned (numba.cuda.tests.cudadrv.test_pinned.TestPinned) ... Exception ignored in: <finalize object at 0x7f75a97262a0; dead>
Traceback (most recent call last):
File "/home/antoine/numba/numba/utils.py", line 593, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 847, in core
deallocs.add_item(driver.cuStreamDestroy, handle)
AttributeError: 'UniqueDict' object has no attribute 'add_item'
ok

# Fixed code
def create_stream(self):
    handle = drvapi.cu_stream()
    driver.cuStreamCreate(byref(handle), 0)
    return Stream(
        weakref.proxy(self), handle, _stream_finalizer(self.deallocations, handle)
    )
# Buggy code
def _module_finalizer(context, handle):
    trashing = context.trashing
    modules = context.modules

    def core():
        def cleanup():
            if modules:
                del modules[handle.value]
            driver.cuModuleUnload(handle)

        trashing.add_trash(cleanup)

    return core


# Traceback (KeyError)
======================================================================
ERROR: test_cuda_driver_occupancy (numba.cuda.tests.cudadrv.test_cuda_driver.TestCudaDriver)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/cuda/tests/cudadrv/test_cuda_driver.py", line 117, in test_cuda_driver_occupancy
module = self.context.create_module_ptx(self.ptx)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 646, in create_module_ptx
return self.create_module_image(image)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 649, in create_module_image
self.trashing.service()
File "/home/antoine/numba/numba/servicelib/service.py", line 30, in service
next(self._task)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 321, in process
cb()
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 779, in cleanup
del modules[handle.value]
KeyError: 47652304

# Fixed code
def _module_finalizer(context, handle):
    trashing = context.trashing
    modules = context.modules

    def core():
        def cleanup():
            # All modules are owned by their parent Context.
            # A Module is either released by a call to
            # Context.unload_module, which clear the handle (pointer) mapping
            # (checked by the following assertion), or, by Context.reset().
            # Both releases the sole reference to the Module and trigger the
            # finalizer for the Module instance.  The actual call to
            # cuModuleUnload is deferred to the trashing service to avoid
            # further corruption of the CUDA context if a fatal error has
            # occurred in the CUDA driver.
            assert handle.value not in modules
            driver.cuModuleUnload(handle)

        trashing.add_trash(cleanup)

    return core
# Buggy code
def core():
    def cleanup():
        if modules:
            del modules[handle.value]
        driver.cuModuleUnload(handle)

    trashing.add_trash(cleanup)


# Traceback (KeyError)
======================================================================
ERROR: test_cuda_driver_occupancy (numba.cuda.tests.cudadrv.test_cuda_driver.TestCudaDriver)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/cuda/tests/cudadrv/test_cuda_driver.py", line 117, in test_cuda_driver_occupancy
module = self.context.create_module_ptx(self.ptx)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 646, in create_module_ptx
return self.create_module_image(image)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 649, in create_module_image
self.trashing.service()
File "/home/antoine/numba/numba/servicelib/service.py", line 30, in service
next(self._task)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 321, in process
cb()
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 779, in cleanup
del modules[handle.value]
KeyError: 47652304

# Fixed code
def core():
    def cleanup():
        # All modules are owned by their parent Context.
        # A Module is either released by a call to
        # Context.unload_module, which clear the handle (pointer) mapping
        # (checked by the following assertion), or, by Context.reset().
        # Both releases the sole reference to the Module and trigger the
        # finalizer for the Module instance.  The actual call to
        # cuModuleUnload is deferred to the trashing service to avoid
        # further corruption of the CUDA context if a fatal error has
        # occurred in the CUDA driver.
        assert handle.value not in modules
        driver.cuModuleUnload(handle)

    trashing.add_trash(cleanup)
# Buggy code
def cleanup():
    if modules:
        del modules[handle.value]
    driver.cuModuleUnload(handle)


# Traceback (KeyError)
======================================================================
ERROR: test_cuda_driver_occupancy (numba.cuda.tests.cudadrv.test_cuda_driver.TestCudaDriver)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/cuda/tests/cudadrv/test_cuda_driver.py", line 117, in test_cuda_driver_occupancy
module = self.context.create_module_ptx(self.ptx)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 646, in create_module_ptx
return self.create_module_image(image)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 649, in create_module_image
self.trashing.service()
File "/home/antoine/numba/numba/servicelib/service.py", line 30, in service
next(self._task)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 321, in process
cb()
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 779, in cleanup
del modules[handle.value]
KeyError: 47652304

# Fixed code
def cleanup():
    # All modules are owned by their parent Context.
    # A Module is either released by a call to
    # Context.unload_module, which clear the handle (pointer) mapping
    # (checked by the following assertion), or, by Context.reset().
    # Both releases the sole reference to the Module and trigger the
    # finalizer for the Module instance.  The actual call to
    # cuModuleUnload is deferred to the trashing service to avoid
    # further corruption of the CUDA context if a fatal error has
    # occurred in the CUDA driver.
    assert handle.value not in modules
    driver.cuModuleUnload(handle)
# Buggy code
def __init__(self, context, handle, info_log, finalizer=None):
    self.context = context
    self.handle = handle
    self.info_log = info_log
    self.finalizer = finalizer
    self.is_managed = self.finalizer is not None


# Traceback (KeyError)
======================================================================
ERROR: test_cuda_driver_occupancy (numba.cuda.tests.cudadrv.test_cuda_driver.TestCudaDriver)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/cuda/tests/cudadrv/test_cuda_driver.py", line 117, in test_cuda_driver_occupancy
module = self.context.create_module_ptx(self.ptx)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 646, in create_module_ptx
return self.create_module_image(image)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 649, in create_module_image
self.trashing.service()
File "/home/antoine/numba/numba/servicelib/service.py", line 30, in service
next(self._task)
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 321, in process
cb()
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 779, in cleanup
del modules[handle.value]
KeyError: 47652304

# Fixed code
def __init__(self, context, handle, info_log, finalizer=None):
    self.context = context
    self.handle = handle
    self.info_log = info_log
    self.finalizer = finalizer
    if self.finalizer is not None:
        self._finalizer = utils.finalize(self, finalizer)
# Buggy code
def scalar_angle_impl(val, deg=False):
    if deg:
        scal = 180 / numpy.pi
        return numpy.arctan2(val.imag, val.real) * scal
    else:
        return numpy.arctan2(val.imag, val.real)


# Traceback (TypingError)
from numba import jit
@jit(nopython=True)
...: def angle(x): return np.angle(x)
...:

angle(np.complex128([1+1j]))
Traceback (most recent call last):
File "<ipython-input-6-186e6f934ae3>", line 1, in <module>
angle(np.complex128([1+1j]))
File "/home/antoine/numba/numba/dispatcher.py", line 171, in _compile_for_args
return self.compile(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 349, in compile
flags=flags, locals=self.locals)
File "/home/antoine/numba/numba/compiler.py", line 684, in compile_extra
return pipeline.compile_extra(func)
File "/home/antoine/numba/numba/compiler.py", line 372, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/home/antoine/numba/numba/compiler.py", line 381, in compile_bytecode
return self._compile_bytecode()
File "/home/antoine/numba/numba/compiler.py", line 665, in _compile_bytecode
res = pm.run(self.status)
File "/home/antoine/numba/numba/compiler.py", line 251, in run
raise patched_exception
File "/home/antoine/numba/numba/compiler.py", line 243, in run
stage()
File "/home/antoine/numba/numba/compiler.py", line 469, in stage_nopython_frontend
self.locals)
File "/home/antoine/numba/numba/compiler.py", line 799, in type_inference_stage
infer.propagate()
File "/home/antoine/numba/numba/typeinfer.py", line 565, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x7fa910005470>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "/home/antoine/numba/numba/typeinfer.py", line 284, in __call__
self.resolve(typeinfer, typevars, fnty)
File "/home/antoine/numba/numba/typeinfer.py", line 311, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "/home/antoine/numba/numba/typing/context.py", line 123, in resolve_function_type
return func.get_call_type(self, args, kws)
File "/home/antoine/numba/numba/types.py", line 264, in get_call_type
sig = temp.apply(args, kws)
File "/home/antoine/numba/numba/typing/templates.py", line 229, in apply
sig = typer(*args, **kws)
File "/home/antoine/numba/numba/typing/npydecl.py", line 850, in typer
return ref.copy(dtype=ref.underlying_float)
AttributeError: 'Array' object has no attribute 'underlying_float'
--%<-----------------------------------------------------------------

# Fixed code
def scalar_angle_impl(val, deg):
    if deg:
        return numpy.arctan2(val.imag, val.real) * deg_mult
    else:
        return numpy.arctan2(val.imag, val.real)
# Buggy code
def array_angle_impl(arr, deg=False):
    out = numpy.zeros_like(arr, dtype=retty)
    for index, val in numpy.ndenumerate(arr):
        out[index] = numpy.angle(val, deg)
    return out


# Traceback (TypingError)
from numba import jit
@jit(nopython=True)
...: def angle(x): return np.angle(x)
...:

angle(np.complex128([1+1j]))
Traceback (most recent call last):
File "<ipython-input-6-186e6f934ae3>", line 1, in <module>
angle(np.complex128([1+1j]))
File "/home/antoine/numba/numba/dispatcher.py", line 171, in _compile_for_args
return self.compile(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 349, in compile
flags=flags, locals=self.locals)
File "/home/antoine/numba/numba/compiler.py", line 684, in compile_extra
return pipeline.compile_extra(func)
File "/home/antoine/numba/numba/compiler.py", line 372, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/home/antoine/numba/numba/compiler.py", line 381, in compile_bytecode
return self._compile_bytecode()
File "/home/antoine/numba/numba/compiler.py", line 665, in _compile_bytecode
res = pm.run(self.status)
File "/home/antoine/numba/numba/compiler.py", line 251, in run
raise patched_exception
File "/home/antoine/numba/numba/compiler.py", line 243, in run
stage()
File "/home/antoine/numba/numba/compiler.py", line 469, in stage_nopython_frontend
self.locals)
File "/home/antoine/numba/numba/compiler.py", line 799, in type_inference_stage
infer.propagate()
File "/home/antoine/numba/numba/typeinfer.py", line 565, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x7fa910005470>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "/home/antoine/numba/numba/typeinfer.py", line 284, in __call__
self.resolve(typeinfer, typevars, fnty)
File "/home/antoine/numba/numba/typeinfer.py", line 311, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "/home/antoine/numba/numba/typing/context.py", line 123, in resolve_function_type
return func.get_call_type(self, args, kws)
File "/home/antoine/numba/numba/types.py", line 264, in get_call_type
sig = temp.apply(args, kws)
File "/home/antoine/numba/numba/typing/templates.py", line 229, in apply
sig = typer(*args, **kws)
File "/home/antoine/numba/numba/typing/npydecl.py", line 850, in typer
return ref.copy(dtype=ref.underlying_float)
AttributeError: 'Array' object has no attribute 'underlying_float'
--%<-----------------------------------------------------------------

# Fixed code
def array_angle_impl(arr, deg):
    out = numpy.zeros_like(arr, dtype=ret_dtype)
    for index, val in numpy.ndenumerate(arr):
        out[index] = numpy.angle(val, deg)
    return out
# Buggy code
def generic(self):
    def typer(ref, deg=False):
        if isinstance(ref, types.Array):
            return ref.copy(dtype=ref.underlying_float)
        else:
            return types.float64

    return typer


# Traceback (TypingError)
from numba import jit
@jit(nopython=True)
...: def angle(x): return np.angle(x)
...:

angle(np.complex128([1+1j]))
Traceback (most recent call last):
File "<ipython-input-6-186e6f934ae3>", line 1, in <module>
angle(np.complex128([1+1j]))
File "/home/antoine/numba/numba/dispatcher.py", line 171, in _compile_for_args
return self.compile(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 349, in compile
flags=flags, locals=self.locals)
File "/home/antoine/numba/numba/compiler.py", line 684, in compile_extra
return pipeline.compile_extra(func)
File "/home/antoine/numba/numba/compiler.py", line 372, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/home/antoine/numba/numba/compiler.py", line 381, in compile_bytecode
return self._compile_bytecode()
File "/home/antoine/numba/numba/compiler.py", line 665, in _compile_bytecode
res = pm.run(self.status)
File "/home/antoine/numba/numba/compiler.py", line 251, in run
raise patched_exception
File "/home/antoine/numba/numba/compiler.py", line 243, in run
stage()
File "/home/antoine/numba/numba/compiler.py", line 469, in stage_nopython_frontend
self.locals)
File "/home/antoine/numba/numba/compiler.py", line 799, in type_inference_stage
infer.propagate()
File "/home/antoine/numba/numba/typeinfer.py", line 565, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x7fa910005470>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "/home/antoine/numba/numba/typeinfer.py", line 284, in __call__
self.resolve(typeinfer, typevars, fnty)
File "/home/antoine/numba/numba/typeinfer.py", line 311, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "/home/antoine/numba/numba/typing/context.py", line 123, in resolve_function_type
return func.get_call_type(self, args, kws)
File "/home/antoine/numba/numba/types.py", line 264, in get_call_type
sig = temp.apply(args, kws)
File "/home/antoine/numba/numba/typing/templates.py", line 229, in apply
sig = typer(*args, **kws)
File "/home/antoine/numba/numba/typing/npydecl.py", line 850, in typer
return ref.copy(dtype=ref.underlying_float)
AttributeError: 'Array' object has no attribute 'underlying_float'
--%<-----------------------------------------------------------------

# Fixed code
def generic(self):
    def typer(z, deg=False):
        if isinstance(z, types.Array):
            dtype = z.dtype
        else:
            dtype = z
        if isinstance(dtype, types.Complex):
            ret_dtype = dtype.underlying_float
        elif isinstance(dtype, types.Float):
            ret_dtype = dtype
        else:
            return
        if isinstance(z, types.Array):
            return z.copy(dtype=ret_dtype)
        else:
            return ret_dtype

    return typer
# Buggy code
def typer(ref, deg=False):
    if isinstance(ref, types.Array):
        return ref.copy(dtype=ref.underlying_float)
    else:
        return types.float64


# Traceback (TypingError)
from numba import jit
@jit(nopython=True)
...: def angle(x): return np.angle(x)
...:

angle(np.complex128([1+1j]))
Traceback (most recent call last):
File "<ipython-input-6-186e6f934ae3>", line 1, in <module>
angle(np.complex128([1+1j]))
File "/home/antoine/numba/numba/dispatcher.py", line 171, in _compile_for_args
return self.compile(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 349, in compile
flags=flags, locals=self.locals)
File "/home/antoine/numba/numba/compiler.py", line 684, in compile_extra
return pipeline.compile_extra(func)
File "/home/antoine/numba/numba/compiler.py", line 372, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/home/antoine/numba/numba/compiler.py", line 381, in compile_bytecode
return self._compile_bytecode()
File "/home/antoine/numba/numba/compiler.py", line 665, in _compile_bytecode
res = pm.run(self.status)
File "/home/antoine/numba/numba/compiler.py", line 251, in run
raise patched_exception
File "/home/antoine/numba/numba/compiler.py", line 243, in run
stage()
File "/home/antoine/numba/numba/compiler.py", line 469, in stage_nopython_frontend
self.locals)
File "/home/antoine/numba/numba/compiler.py", line 799, in type_inference_stage
infer.propagate()
File "/home/antoine/numba/numba/typeinfer.py", line 565, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x7fa910005470>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "/home/antoine/numba/numba/typeinfer.py", line 284, in __call__
self.resolve(typeinfer, typevars, fnty)
File "/home/antoine/numba/numba/typeinfer.py", line 311, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "/home/antoine/numba/numba/typing/context.py", line 123, in resolve_function_type
return func.get_call_type(self, args, kws)
File "/home/antoine/numba/numba/types.py", line 264, in get_call_type
sig = temp.apply(args, kws)
File "/home/antoine/numba/numba/typing/templates.py", line 229, in apply
sig = typer(*args, **kws)
File "/home/antoine/numba/numba/typing/npydecl.py", line 850, in typer
return ref.copy(dtype=ref.underlying_float)
AttributeError: 'Array' object has no attribute 'underlying_float'
--%<-----------------------------------------------------------------

# Fixed code
def typer(z, deg=False):
    if isinstance(z, types.Array):
        dtype = z.dtype
    else:
        dtype = z
    if isinstance(dtype, types.Complex):
        ret_dtype = dtype.underlying_float
    elif isinstance(dtype, types.Float):
        ret_dtype = dtype
    else:
        return
    if isinstance(z, types.Array):
        return z.copy(dtype=ret_dtype)
    else:
        return ret_dtype
# Buggy code
def generic(self):
    def typer(ref, k=0):
        if isinstance(ref, types.Array):
            if ref.ndim == 1:
                rdim = 2
            elif ref.ndim == 2:
                rdim = 1
            else:
                return None
            return types.Array(ndim=rdim, dtype=ref.dtype, layout="C")

    return typer


# Traceback (TypingError)
from numba import jit
@jit(nopython=True)
...: def angle(x): return np.angle(x)
...:

angle(np.complex128([1+1j]))
Traceback (most recent call last):
File "<ipython-input-6-186e6f934ae3>", line 1, in <module>
angle(np.complex128([1+1j]))
File "/home/antoine/numba/numba/dispatcher.py", line 171, in _compile_for_args
return self.compile(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 349, in compile
flags=flags, locals=self.locals)
File "/home/antoine/numba/numba/compiler.py", line 684, in compile_extra
return pipeline.compile_extra(func)
File "/home/antoine/numba/numba/compiler.py", line 372, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/home/antoine/numba/numba/compiler.py", line 381, in compile_bytecode
return self._compile_bytecode()
File "/home/antoine/numba/numba/compiler.py", line 665, in _compile_bytecode
res = pm.run(self.status)
File "/home/antoine/numba/numba/compiler.py", line 251, in run
raise patched_exception
File "/home/antoine/numba/numba/compiler.py", line 243, in run
stage()
File "/home/antoine/numba/numba/compiler.py", line 469, in stage_nopython_frontend
self.locals)
File "/home/antoine/numba/numba/compiler.py", line 799, in type_inference_stage
infer.propagate()
File "/home/antoine/numba/numba/typeinfer.py", line 565, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x7fa910005470>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "/home/antoine/numba/numba/typeinfer.py", line 284, in __call__
self.resolve(typeinfer, typevars, fnty)
File "/home/antoine/numba/numba/typeinfer.py", line 311, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "/home/antoine/numba/numba/typing/context.py", line 123, in resolve_function_type
return func.get_call_type(self, args, kws)
File "/home/antoine/numba/numba/types.py", line 264, in get_call_type
sig = temp.apply(args, kws)
File "/home/antoine/numba/numba/typing/templates.py", line 229, in apply
sig = typer(*args, **kws)
File "/home/antoine/numba/numba/typing/npydecl.py", line 850, in typer
return ref.copy(dtype=ref.underlying_float)
AttributeError: 'Array' object has no attribute 'underlying_float'
--%<-----------------------------------------------------------------

# Fixed code
def generic(self):
    def typer(ref, k=0):
        if isinstance(ref, types.Array):
            if ref.ndim == 1:
                rdim = 2
            elif ref.ndim == 2:
                rdim = 1
            else:
                return None
            return types.Array(ndim=rdim, dtype=ref.dtype, layout="C")

    return typer
# Buggy code
def typer(ref, k=0):
    if isinstance(ref, types.Array):
        if ref.ndim == 1:
            rdim = 2
        elif ref.ndim == 2:
            rdim = 1
        else:
            return None
        return types.Array(ndim=rdim, dtype=ref.dtype, layout="C")


# Traceback (TypingError)
from numba import jit
@jit(nopython=True)
...: def angle(x): return np.angle(x)
...:

angle(np.complex128([1+1j]))
Traceback (most recent call last):
File "<ipython-input-6-186e6f934ae3>", line 1, in <module>
angle(np.complex128([1+1j]))
File "/home/antoine/numba/numba/dispatcher.py", line 171, in _compile_for_args
return self.compile(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 349, in compile
flags=flags, locals=self.locals)
File "/home/antoine/numba/numba/compiler.py", line 684, in compile_extra
return pipeline.compile_extra(func)
File "/home/antoine/numba/numba/compiler.py", line 372, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/home/antoine/numba/numba/compiler.py", line 381, in compile_bytecode
return self._compile_bytecode()
File "/home/antoine/numba/numba/compiler.py", line 665, in _compile_bytecode
res = pm.run(self.status)
File "/home/antoine/numba/numba/compiler.py", line 251, in run
raise patched_exception
File "/home/antoine/numba/numba/compiler.py", line 243, in run
stage()
File "/home/antoine/numba/numba/compiler.py", line 469, in stage_nopython_frontend
self.locals)
File "/home/antoine/numba/numba/compiler.py", line 799, in type_inference_stage
infer.propagate()
File "/home/antoine/numba/numba/typeinfer.py", line 565, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x7fa910005470>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "/home/antoine/numba/numba/typeinfer.py", line 284, in __call__
self.resolve(typeinfer, typevars, fnty)
File "/home/antoine/numba/numba/typeinfer.py", line 311, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "/home/antoine/numba/numba/typing/context.py", line 123, in resolve_function_type
return func.get_call_type(self, args, kws)
File "/home/antoine/numba/numba/types.py", line 264, in get_call_type
sig = temp.apply(args, kws)
File "/home/antoine/numba/numba/typing/templates.py", line 229, in apply
sig = typer(*args, **kws)
File "/home/antoine/numba/numba/typing/npydecl.py", line 850, in typer
return ref.copy(dtype=ref.underlying_float)
AttributeError: 'Array' object has no attribute 'underlying_float'
--%<-----------------------------------------------------------------

# Fixed code
def typer(ref, k=0):
    if isinstance(ref, types.Array):
        if ref.ndim == 1:
            rdim = 2
        elif ref.ndim == 2:
            rdim = 1
        else:
            return None
        return types.Array(ndim=rdim, dtype=ref.dtype, layout="C")
# Buggy code
def __init__(self, device, handle, finalizer=None):
    self.device = device
    self.handle = handle
    self.finalizer = finalizer
    self.trashing = TrashService(
        "cuda.device%d.context%x.trash" % (self.device.id, self.handle.value)
    )
    self.is_managed = finalizer is not None
    self.allocations = utils.UniqueDict()
    self.modules = utils.UniqueDict()
    # For storing context specific data
    self.extras = {}


# Traceback (AttributeError)
Exception ignored in: <bound method Context.__del__ of <CUDA context c_void_p(36426160) of device 0>>
Traceback (most recent call last):
File "/home/antoine/numba/numba/cuda/cudadrv/driver.py", line 467, in __del__
AttributeError: 'NoneType' object has no attribute 'print_exc'

# Fixed code
def __init__(self, device, handle, finalizer=None):
    self.device = device
    self.handle = handle
    self.external_finalizer = finalizer
    self.trashing = TrashService(
        "cuda.device%d.context%x.trash" % (self.device.id, self.handle.value)
    )
    self.allocations = utils.UniqueDict()
    self.modules = utils.UniqueDict()
    self.finalizer = utils.finalize(self, self._make_finalizer())
    # For storing context specific data
    self.extras = {}
# Buggy code
def __call__(self, context, typevars):
    oset = typevars[self.target]
    for tp in typevars[self.iterator.name].get():
        if isinstance(tp, types.IterableType):
            oset.add_types(
                types.UniTuple(dtype=tp.iterator_type.yield_type, count=self.count)
            )
        elif isinstance(tp, types.Tuple):
            oset.add_types(tp)


# Traceback (numba.lowering.LoweringError)
ff = jit(f, nopython=True)
ff((4,5,6,7))
(4, 5, 6)
ff((4,5))
Traceback (most recent call last):
[...]
numba.lowering.LoweringError: Failed at nopython (nopython mode backend)
Internal error:
TypeError: Can't index at [2] in [2 x i32]
File "<stdin>", line 2

# Fixed code
def __call__(self, context, typevars):
    oset = typevars[self.target]
    for tp in typevars[self.iterator.name].get():
        if isinstance(tp, types.BaseTuple):
            if len(tp) == self.count:
                oset.add_types(tp)
        elif isinstance(tp, types.IterableType):
            oset.add_types(
                types.UniTuple(dtype=tp.iterator_type.yield_type, count=self.count)
            )
# Buggy code
def __init__(self, arg_count, py_func):
    self.tm = default_type_manager
    _dispatcher.Dispatcher.__init__(self, self.tm.get_pointer(), arg_count)

    # A mapping of signatures to entry points
    self.overloads = {}
    # A mapping of signatures to compile results
    self._compileinfos = {}
    # A list of nopython signatures
    self._npsigs = []

    self.py_func = py_func
    # other parts of Numba assume the old Python 2 name for code object
    self.func_code = get_code_object(py_func)
    # but newer python uses a different name
    self.__code__ = self.func_code

    self.doc = py_func.__doc__
    self._compiling = False

    utils.finalize(self, self._make_finalizer())


# Traceback (RuntimeError)
Exception in thread Thread-14:
Traceback (most recent call last):
File "/home/antoine/34/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/home/antoine/34/lib/python3.4/threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "/home/antoine/numba/numba/dispatcher.py", line 151, in _compile_for_args
return self.jit(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 141, in jit
return self.compile(sig, **kws)
File "/home/antoine/numba/numba/dispatcher.py", line 312, in compile
with self._compile_lock():
File "/home/antoine/34/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/home/antoine/numba/numba/dispatcher.py", line 127, in _compile_lock
raise RuntimeError("Compiler re-entrant")
RuntimeError: Compiler re-entrant

# Fixed code
def __init__(self, arg_count, py_func):
    self.tm = default_type_manager
    _dispatcher.Dispatcher.__init__(self, self.tm.get_pointer(), arg_count)

    # A mapping of signatures to entry points
    self.overloads = {}
    # A mapping of signatures to compile results
    self._compileinfos = {}
    # A list of nopython signatures
    self._npsigs = []

    self.py_func = py_func
    # other parts of Numba assume the old Python 2 name for code object
    self.func_code = get_code_object(py_func)
    # but newer python uses a different name
    self.__code__ = self.func_code

    self.doc = py_func.__doc__
    self._compile_lock = utils.NonReentrantLock()

    utils.finalize(self, self._make_finalizer())
# Buggy code
def is_compiling(self):
    return self._compiling


# Traceback (RuntimeError)
Exception in thread Thread-14:
Traceback (most recent call last):
File "/home/antoine/34/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/home/antoine/34/lib/python3.4/threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "/home/antoine/numba/numba/dispatcher.py", line 151, in _compile_for_args
return self.jit(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 141, in jit
return self.compile(sig, **kws)
File "/home/antoine/numba/numba/dispatcher.py", line 312, in compile
with self._compile_lock():
File "/home/antoine/34/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/home/antoine/numba/numba/dispatcher.py", line 127, in _compile_lock
raise RuntimeError("Compiler re-entrant")
RuntimeError: Compiler re-entrant

# Fixed code
def is_compiling(self):
    """
    Whether a specialization is currently being compiled.
    """
    return self._compile_lock.is_owned()
# Buggy code
def compile(self, sig, locals={}, **targetoptions):
    with self._compile_lock():
        locs = self.locals.copy()
        locs.update(locals)

        topt = self.targetoptions.copy()
        topt.update(targetoptions)

        flags = compiler.Flags()
        self.targetdescr.options.parse_as_flags(flags, topt)

        args, return_type = sigutils.normalize_signature(sig)

        # Don't recompile if signature already exist.
        existing = self.overloads.get(tuple(args))
        if existing is not None:
            return existing

        cres = compiler.compile_extra(
            self.typingctx,
            self.targetctx,
            self.py_func,
            args=args,
            return_type=return_type,
            flags=flags,
            locals=locs,
        )

        # Check typing error if object mode is used
        if cres.typing_error is not None and not flags.enable_pyobject:
            raise cres.typing_error

        self.add_overload(cres)
        return cres.entry_point


# Traceback (RuntimeError)
Exception in thread Thread-14:
Traceback (most recent call last):
File "/home/antoine/34/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/home/antoine/34/lib/python3.4/threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "/home/antoine/numba/numba/dispatcher.py", line 151, in _compile_for_args
return self.jit(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 141, in jit
return self.compile(sig, **kws)
File "/home/antoine/numba/numba/dispatcher.py", line 312, in compile
with self._compile_lock():
File "/home/antoine/34/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/home/antoine/numba/numba/dispatcher.py", line 127, in _compile_lock
raise RuntimeError("Compiler re-entrant")
RuntimeError: Compiler re-entrant

# Fixed code
def compile(self, sig, locals={}, **targetoptions):
    with self._compile_lock:
        locs = self.locals.copy()
        locs.update(locals)

        topt = self.targetoptions.copy()
        topt.update(targetoptions)

        flags = compiler.Flags()
        self.targetdescr.options.parse_as_flags(flags, topt)

        args, return_type = sigutils.normalize_signature(sig)

        # Don't recompile if signature already exist.
        existing = self.overloads.get(tuple(args))
        if existing is not None:
            return existing

        cres = compiler.compile_extra(
            self.typingctx,
            self.targetctx,
            self.py_func,
            args=args,
            return_type=return_type,
            flags=flags,
            locals=locs,
        )

        # Check typing error if object mode is used
        if cres.typing_error is not None and not flags.enable_pyobject:
            raise cres.typing_error

        self.add_overload(cres)
        return cres.entry_point
# Buggy code
def compile(self, sig):
    with self._compile_lock():
        # FIXME this is mostly duplicated from Overloaded
        flags = self.flags
        args, return_type = sigutils.normalize_signature(sig)

        # Don't recompile if signature already exist.
        existing = self.overloads.get(tuple(args))
        if existing is not None:
            return existing.entry_point

        assert not flags.enable_looplift, "Enable looplift flags is on"
        cres = compiler.compile_bytecode(
            typingctx=self.typingctx,
            targetctx=self.targetctx,
            bc=self.bytecode,
            args=args,
            return_type=return_type,
            flags=flags,
            locals=self.locals,
        )

        # Check typing error if object mode is used
        if cres.typing_error is not None and not flags.enable_pyobject:
            raise cres.typing_error

        self.add_overload(cres)
        return cres.entry_point


# Traceback (RuntimeError)
Exception in thread Thread-14:
Traceback (most recent call last):
File "/home/antoine/34/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/home/antoine/34/lib/python3.4/threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "/home/antoine/numba/numba/dispatcher.py", line 151, in _compile_for_args
return self.jit(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 141, in jit
return self.compile(sig, **kws)
File "/home/antoine/numba/numba/dispatcher.py", line 312, in compile
with self._compile_lock():
File "/home/antoine/34/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/home/antoine/numba/numba/dispatcher.py", line 127, in _compile_lock
raise RuntimeError("Compiler re-entrant")
RuntimeError: Compiler re-entrant

# Fixed code
def compile(self, sig):
    with self._compile_lock:
        # FIXME this is mostly duplicated from Overloaded
        flags = self.flags
        args, return_type = sigutils.normalize_signature(sig)

        # Don't recompile if signature already exist.
        existing = self.overloads.get(tuple(args))
        if existing is not None:
            return existing.entry_point

        assert not flags.enable_looplift, "Enable looplift flags is on"
        cres = compiler.compile_bytecode(
            typingctx=self.typingctx,
            targetctx=self.targetctx,
            bc=self.bytecode,
            args=args,
            return_type=return_type,
            flags=flags,
            locals=self.locals,
        )

        # Check typing error if object mode is used
        if cres.typing_error is not None and not flags.enable_pyobject:
            raise cres.typing_error

        self.add_overload(cres)
        return cres.entry_point
# Buggy code
def _compile_for_args(self, *args, **kws):
    """
    For internal use.  Compile a specialized version of the function
    for the given *args* and *kws*, and return the resulting callable.
    """
    assert not kws
    sig = tuple([self.typeof_pyval(a) for a in args])
    return self.jit(sig)


# Traceback (RuntimeError)
Exception in thread Thread-14:
Traceback (most recent call last):
File "/home/antoine/34/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/home/antoine/34/lib/python3.4/threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "/home/antoine/numba/numba/dispatcher.py", line 151, in _compile_for_args
return self.jit(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 141, in jit
return self.compile(sig, **kws)
File "/home/antoine/numba/numba/dispatcher.py", line 312, in compile
with self._compile_lock():
File "/home/antoine/34/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/home/antoine/numba/numba/dispatcher.py", line 127, in _compile_lock
raise RuntimeError("Compiler re-entrant")
RuntimeError: Compiler re-entrant

# Fixed code
def _compile_for_args(self, *args, **kws):
    """
    For internal use.  Compile a specialized version of the function
    for the given *args* and *kws*, and return the resulting callable.
    """
    assert not kws
    sig = tuple([self.typeof_pyval(a) for a in args])
    return self.compile(sig)
# Buggy code
def make_multithread(inner_func, numthreads):
    """
    Run the given function inside *numthreads* threads, splitting its
    arguments into equal-sized chunks.
    """

    def func_mt(*args):
        length = len(args[0])
        result = np.empty(length, dtype=np.float64)
        args = (result,) + args
        chunklen = (length + 1) // numthreads
        # Create argument tuples for each chunk
        chunks = [
            [arg[i * chunklen : (i + 1) * chunklen] for arg in args]
            for i in range(numthreads)
        ]

        # You should make sure inner_func is compiled at this point, because
        # the compilation must happen in a single thread at a time. This is
        # the case in this example because we use an explicit signature in jit().
        threads = [threading.Thread(target=inner_func, args=chunk) for chunk in chunks]
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()
        return result

    return func_mt


# Traceback (RuntimeError)
Exception in thread Thread-14:
Traceback (most recent call last):
File "/home/antoine/34/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/home/antoine/34/lib/python3.4/threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "/home/antoine/numba/numba/dispatcher.py", line 151, in _compile_for_args
return self.jit(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 141, in jit
return self.compile(sig, **kws)
File "/home/antoine/numba/numba/dispatcher.py", line 312, in compile
with self._compile_lock():
File "/home/antoine/34/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/home/antoine/numba/numba/dispatcher.py", line 127, in _compile_lock
raise RuntimeError("Compiler re-entrant")
RuntimeError: Compiler re-entrant

# Fixed code
def make_multithread(inner_func, numthreads):
    """
    Run the given function inside *numthreads* threads, splitting its
    arguments into equal-sized chunks.
    """

    def func_mt(*args):
        length = len(args[0])
        result = np.empty(length, dtype=np.float64)
        args = (result,) + args
        chunklen = (length + 1) // numthreads
        # Create argument tuples for each input chunk
        chunks = [
            [arg[i * chunklen : (i + 1) * chunklen] for arg in args]
            for i in range(numthreads)
        ]
        # Spawn one thread per chunk
        threads = [threading.Thread(target=inner_func, args=chunk) for chunk in chunks]
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()
        return result

    return func_mt