-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathjjulia.py
80 lines (64 loc) · 1.46 KB
/
jjulia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
> using PyCall
> pyinitialize("python3")
For reload - jjulia can be changed for appropriate type
> jjulia = pyimport(:jjulia)
# This can be used for import and reload both.
# If @pyimport is used, reload is not workinng since lib names are assigned as constant variales.
> jjulia = pywrap(PyObject(ccall(pysym(:PyImport_ReloadModule), PyPtr, (PyPtr,), pyimport("jjulia"))))
"""
import numpy as np
from sklearn import linear_model
import julia
def hello():
j = julia.Julia()
j.println("Hello")
def py_sumN( N):
zz = 0
for ii in range( N):
for jj in range( N):
for kk in range( N):
zz += ii * jj * kk
return zz
def hello( name):
print("hi {}".format( name))
print("This is James")
print("Julia calls a python function.")
print("Now reload module is working.")
def _regression_r0( X, y):
print X
print X.shape
print y
print y.shape
xM = np.mat( X)
yV = np.mat( y).T
w = np.linalg.pinv( xM) * yV
return np.array(w)
def regression(X, y):
clf = linear_model.LinearRegression()
clf.fit(X, y)
return clf.coef_
"""
The following functions call Julia while them can be used in Python.
"""
jl = julia.Julia()
jl.eval('include("/home/jamessungjinkim/Dropbox/Aspuru-Guzik/julia_lab/jslib.jl")')
mg_to_log_mol = jl.eval( 'mg_to_log_mol')
julia_sum = jl.eval("""
function mysum(a,b)
return a+b
end
""")
julia_sumN = jl.eval("""
function mysum(N)
zz = 0
for ii = 1:N
for jj = 1:N
for kk = 1:N
zz += ii*jj*kk
end
end
end
return zz
end
""")