Conversion issue from Py to Float64 using juliacall #469
-
I am currently working on a python wrapper for a julia package called FrankWolfe.jl (https://github.com/ZIB-IOL/FrankWolfe.jl) At line 41 : error :
stacktrace
Here is the python code that calls the julia function : def test_simple_frankwolfe():
def f(x):
return frankwolfe.norm(x)**2
def grad(storage,x):
for i in range(len(x)):
storage[i] = x[i]
lmo_prob = frankwolfe.ProbabilitySimplexOracle(1)
x0 = frankwolfe.compute_extreme_point(lmo_prob,np.zeros(5))
print(frankwolfe.frank_wolfe(f,grad,lmo_prob,x0,max_iteration=1000,line_search=frankwolfe.Agnostic(),verbose=True,)) Is there any way to convert the python function to a julia function before sending it to the frank_wolfe algorithm ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'm assuming the issue is in passing the Python function Here are some ways you can convert the function into a Julia one which returns a # define it as a Julia function in the first place
f = jl.seval("x -> FrankWolfe.norm(x)^2")
# wrap it into a Julia function which converts the result
f = jl.seval("f -> x -> pyconvert(Float64, f(x))")(f)
# wrap it into a Python function which converts the result
f = (lambda f: lambda x: juliacall.convert(jl.Float64, f(x)))(f) |
Beta Was this translation helpful? Give feedback.
I'm assuming the issue is in passing the Python function
f
to the Julia functionfrank_wolfe
? So it becomes aPy
Julia-side, which when called returns aPy
not aFloat64
as desired?Here are some ways you can convert the function into a Julia one which returns a
Float64
: