Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment of jitclass-owned array fails when list comprehension is used in the calling function #7811

Open
sebbelese opened this issue Feb 3, 2022 · 4 comments
Labels

Comments

@sebbelese
Copy link

sebbelese commented Feb 3, 2022

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)
@sebbelese sebbelese changed the title Assignment of jitclass-owned array fails when list of arrays is declared in the calling function Assignment of jitclass-owned array fails when list is declared in the calling function Feb 3, 2022
@sebbelese sebbelese changed the title Assignment of jitclass-owned array fails when list is declared in the calling function Assignment of jitclass-owned array fails when list comprehension is used in the calling function Feb 3, 2022
@sklam
Copy link
Member

sklam commented Feb 3, 2022

I can confirm that uncommenting the last line changes the printed output before it

@sklam
Copy link
Member

sklam commented Feb 3, 2022

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.

@sklam sklam added the bug - miscompile Bugs: miscompile label Feb 3, 2022
@sebbelese
Copy link
Author

It still fails with numba 0.57.0

@sebbelese
Copy link
Author

Still affecting numba-0.60.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants