numba
numba copied to clipboard
Assignment of jitclass-owned array fails when list comprehension is used in the calling function
With numba 0.55.1.
Consider the following code:
import numpy as np
from numba import njit
from numba.experimental import jitclass
from numba import float64 # import the types
spec = [
('var', float64[:]),
]
@jitclass(spec)
class varClass():
def __init__(self, a):
self.var = np.array([a])
@njit
def printVar():
vinst = varClass(1.)
print(vinst.var)
vinst.var[0] = 0.0
print(vinst.var)
# Uncommenting this line breaks the var update
# positionsPartGroups = [i for i in range(10)]
printVar()
If I run the script, the output is:
[1.]
[0.]
which is correct.
If I uncomment the last line of the printVar function, which should have no effect, the output is
[1.]
[1.]
which is not correct.
Note that building the list with a loop works:
positionPartGroups= []
for i in range(10):
positionPartGroups.append(i)
I can confirm that uncommenting the last line changes the printed output before it
I believe the problem is coming from InlineClosureCallPass
debug output contains this:
InlineClosureCallPass: start inline arraycall
fix_array_assign: found SetItem: $24load_attr.9[$const26.10] = $const20.7
find_array_def: $24load_attr.9getattr(value=vinst, attr=var)
No reason for the closure in [i for i in range(10)] affects the setitem.
It still fails with numba 0.57.0
Still affecting numba-0.60.0