Skip to content

Conversion issue from Py to Float64 using juliacall #469

Answered by cjdoris
victorthouvenot asked this question in Q&A
Discussion options

You must be logged in to vote

I'm assuming the issue is in passing the Python function f to the Julia function frank_wolfe? So it becomes a Py Julia-side, which when called returns a Py not a Float64 as desired?

Here are some ways you can convert the function into a Julia one which returns a Float64:

# 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)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by victorthouvenot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants