47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
run("CPython/wrapper")
|
|
|
|
x=[0,1,2,3,4,5,6,7,8,9]
|
|
y=[1,2,3,6,9,6,3,2,1,0]
|
|
#(p, x_fit, y_fit, R2) = linfit(x,y)
|
|
#plot((y,y_fit), name=("data", "fit"),xdata=(x,x_fit))
|
|
|
|
|
|
#x=to_array(x,'f')
|
|
#y=to_array(y,'f')
|
|
|
|
def _from_npa(obj):
|
|
if isinstance(obj, jep.NDArray):
|
|
ret = obj.data
|
|
if len(obj.dimensions)>1:
|
|
ret=Convert.reshape(ret, obj.dimensions)
|
|
return ret
|
|
if isinstance(obj, java.util.List) or isinstance(obj,tuple) or isinstance(obj,list):
|
|
ret=[]
|
|
for i in range(len(obj)):
|
|
ret.append(_from_npa(obj[i]))
|
|
if isinstance(obj,tuple):
|
|
return type(ret)
|
|
return ret
|
|
return obj
|
|
|
|
def _to_npa(obj):
|
|
if isinstance(obj, PyArray):
|
|
return to_npa(obj, dimensions = Arr.getShape(obj))
|
|
if isinstance(obj, java.util.List) or isinstance(obj,tuple) or isinstance(obj,list):
|
|
ret=[]
|
|
for i in range(len(obj)):
|
|
ret.append(_to_npa(obj[i]))
|
|
if isinstance(obj,tuple):
|
|
return tuple(ret)
|
|
return ret
|
|
return obj
|
|
|
|
def call_py(module, function, *args):
|
|
print _to_npa(args)
|
|
ret = call_jep(module, function, _to_npa(args))
|
|
return _from_npa(ret)
|
|
|
|
#ret = call_py("CPython/linfit", "linfit",x,y)
|
|
(p, x_fit, y_fit, R2) = call_py("CPython/linfit", "linfit",x,y)
|
|
#(p, x_fit, y_fit, R2) = linfit(x,y)
|
|
plot((y,y_fit), name=("data", "fit"),xdata=(x,x_fit)) |