Hi everybody,
since Julia is able to connect with Python using PyCall i was trying to apply that on a python code on julia for a smith decomposition but i can’t run it even tho everything seem fine to me, here’s the code that i’m trying to run:
using PyCall
export smith_normal_form
py"""
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 =py"np.array"([[1,2,3],[-3,2,0],[1,0,0]])
U, P, V =py"smith_normal_form"(A)
and after i run it, it shows me this error:
ERROR: PyError ($(Expr(:escape, :(ccall(#= /Users/midow/.julia/packages/PyCall/0jMpb/src/pyeval.jl:23 =# @pysym(:PyEval_EvalCode), PyPtr, (PyPtr, PyPtr, PyPtr), o, globals, locals))))) <class 'NameError'>
NameError("name 'np' is not defined")
File "/Users/midow/.julia/packages/PyCall/0jMpb/src/pyeval.jl", line 1, in <module>
const Py_single_input = 256 # from Python.h
i’m using Julia 1.0.1