I have recently started using JuliaCall to use Julia functionality in python, but I am having trouble understanding how type conversions work, and I have the following problem.
- I have a julia function which has an argument whose type is specified as
Vector{Float64}
. - I have a list of floats in python, and I would like to call the julia function on that list
- When I do that, I get a
MethodError
because the types don’t match. - The error also happens when I use a numpy array instead of a list
Here is a minimal working example.
File testing_juliacall.jl
:
function myfunc(a::Vector{Float64})
return
end
File testing_julicall.py
:
from juliacall import Main as jl
pylist = [1.0, 2.0, 3.0]
jl.include("testing_juliacall.jl")
jl.vector_func(pylist)
File testing_juliacall_numpy.py
:
from juliacall import Main as jl
import numpy as np
numpy_array = np.array([1.0, 2.0, 3.0])
jl.include("testing_juliacall.jl")
jl.vector_func(numpy_array)
Results:
$ python testing_juliacall.py
Traceback (most recent call last):
File "testing_juliacall.py", line 5, in <module>
jl.vector_func(pylist)
File "/home/spencer/.julia/packages/PythonCall/DqZCE/src/jlwrap/any.jl", line 201, in __call__
return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
TypeError: Julia: MethodError: no method matching vector_func(::PythonCall.PyList{PythonCall.Py})
Closest candidates are:
vector_func(!Matched::Vector{Float64}) at ~/LLNL/JuqPy/testing_juliacall.jl:1
$ python testing_juliacall_numpy.py
Traceback (most recent call last):
File "testing_juliacall_numpy.py", line 6, in <module>
jl.vector_func(numpy_array)
File "/home/spencer/.julia/packages/PythonCall/DqZCE/src/jlwrap/any.jl", line 201, in __call__
return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
TypeError: Julia: MethodError: no method matching vector_func(::PythonCall.PyArray{Float64, 1, true, true, Float64})
Closest candidates are:
vector_func(!Matched::Vector{Float64}) at ~/LLNL/JuqPy/testing_juliacall.jl:1
Any advice on how to get this working? Does JuliaCall just not play very well with specified types? Would I have to write another method of vector_func
which accepts objects of type PythonCall.PyList{PythonCall.Py}
or PythonCall.PyArray{Float64, 1, true, true, Float64}
? That would not be as convenient as I hoped.