У меня есть python
код, который я хочу использовать в julia
, вызывая его с помощью PyCall
, но когда я запускаю этот код в anaconda (блокнот Spyder или Jupyter), он показывает мне The kernel appears to have died. It will restart automatically.
Вы найдете код ниже.
Я попытался удалить несколько строк, чтобы узнать, в чем проблема, но у меня ничего нет.
python
from ctypes import *
import numpy as np
polylib = cdll.LoadLibrary("libpolylib64.so")
class Matrix(Structure):
_fields_ = [
("NbRows", c_uint32),
("NbColumns", c_uint32),
("p", POINTER(POINTER(c_int64))),
("p_Init", POINTER(c_int64)),
("p_Init_size", c_int32)
]
def smith_normal_form(A):
pM0 = polylib.Matrix_Alloc(3, 3)
M0 = Matrix.from_address(pM0);
pM = pointer(M0)
pU = POINTER(Matrix)()
pV = POINTER(Matrix)()
pP = POINTER(Matrix)()
M = np.ctypeslib.as_array(M0.p_Init, shape=(3,3))
M[:] = A
polylib.Smith.argtypes=[POINTER(Matrix), POINTER(POINTER(Matrix)), POINTER(POINTER(Matrix)), POINTER(POINTER(Matrix))]
polylib.Smith(pM, pointer(pU), pointer(pV), pointer(pP))
U = np.ctypeslib.as_array(pU.contents.p_Init, shape=(3,3))
V = np.ctypeslib.as_array(pV.contents.p_Init, shape=(3,3))
P = np.ctypeslib.as_array(pP.contents.p_Init, shape=(3,3))
return U, P, V
A = np.array([[1,2,3],[-3,2,0],[1,0,0]])
U, P, V = smith_normal_form(A)
print(U.dot(P).dot(V)-A)
но когда я запускаю его в pycharm, он работает, и он показывает мне этот вывод, который является инициализацией матрицы 3x3:
[[0 0 0]
[0 0 0]
[0 0 0]]