I’m working on making my functions generic to handle various types of arrays, including PyArray
from PythonCall.jl
. But I’ve encountered a problem with the similar
function on PyArray
types.
Here’s a simple example that highlights the problem:
using PythonCall
a = PyArray([1, 2])
b = similar(a)
function foo(a::V, b::V) where V<:AbstractArray
(a, b)
end
foo(a, b) # fails
This call to foo
generates the following error:
ERROR: MethodError: no method matching foo(::PyArray{Int64, 1, true, true, Int64}, ::Vector{Int64})
I initially discovered this issue while attempting to integrate a Julia package with Python using JuliaCall and calling a function of the form
bar(a::V; b::V=similar(a)) where V<:AbstractArray
My goal is to pass PyArray objects to my functions seamlessly, without needing to convert them to standard Array objects first. I’m glad for any suggestions. Thanks!