numba/numba

[Docs?] Numba creates multiple Python objects for an object returned more than once

Open

#3,639 建立於 2019年1月2日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)Python (9,177 star) (1,132 fork)batch import
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.

貢獻者指南