numba/numba
在 GitHub 查看[Docs?] Numba creates multiple Python objects for an object returned more than once
Open
#3,639 建立於 2019年1月2日
doceasygood first issue
描述
If an object created in nopython is returned more than once from a function (in a tuple, say), Numba creates separate instances each time, ie the code below fails on the assertions.
from numba import int64, jit, jitclass
from numpy import array
@jit(nopython=True)
def return_list_twice():
the_list = [1, 2, 3]
return the_list, the_list
@jit(nopython=True)
def return_array_twice():
the_array = array([1, 2, 3])
return the_array, the_array
@jitclass([('value', int64)])
class MyJitClass:
def __init__(self):
self.value = 42
@jit(nopython=True)
def return_jitclass_twice():
the_class = MyJitClass()
return the_class, the_class
list1, list2 = return_list_twice()
array1, array2 = return_array_twice()
class1, class2 = return_jitclass_twice()
assert list1 is list2
assert array1 is array2
assert class1 is class2
Not sure there is a use-case that really requires this, hence probably more of a documentation issue.
- I am using the latest released version of Numba (most recent is visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- 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).