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
Array changes unexpectedly when used with numpy.linalg functions #4519
Comments
I can replicate this bug. This is definitely jitclass related because the problem doesn't occur if Here's a smaller reproducer: import numpy as np
import numba as nb
from numba import njit, jitclass
from collections import OrderedDict
spec = OrderedDict(G=nb.float64[:,:])
@jitclass(spec)
class cls_jit(object):
def __init__(self):
pass
@njit
def test0(self, M, x):
_, G = np.linalg.eig(M)
self.G = G
for i in range(4):
A = self.G
print('--', np.linalg.norm(A)) # norm of A should not change
np.linalg.solve(A, x)
CJ = cls_jit()
print('running test0')
x = np.ones(2)
M = np.array([[1.,2.],[2.,1.]])
test0(CJ, M, x) |
Pretty sure this is a bug in linalg that I've seen before, not import numpy as np
from numba import njit, float64
@njit(locals={'G': float64[:,:]})
def foo(A):
_, G = np.linalg.eig(A)
for i in range(3):
np.linalg.solve(G, G[:, 0])
print('--', np.linalg.norm(G))
M = np.array([[1.,2.],[2.,1.]])
foo(M) I think the problem is that if an array is determined to be 'A' order at typing time but at runtime it is discovered as 'F', then no copy is made: Lines 1721 to 1725 in 60d2bdd
|
xref #3368 |
Fixed by #5879. Closing. |
I have a jitclass where I want to save an eigenvector matrix. Later, I use that eigenvector matrix to solve some linear systems. However, when passed to numpy's linalg.solve function, the original eigenvector matrix is changed in place. Here's a minimal example:
I'm using python 3.6, numba version 0.45.1 and numpy version 1.16.4. In the above code, test1 and test2 work as expected. However, in test0, the value of G changes after every call to np.linalg.solve.
I'm guessing this has something to do with the fact that np.linalg.eig returns the eigenvectors as a view, and this somehow interacts with being assigned to the jitclass.
The text was updated successfully, but these errors were encountered: