I’ve been trying to figure out a systematic way to call Julia functions from Python. I came across pyjulia library (in python) and PyCall modules (in julia) which seem to be pretty useful. However, most of the examples shown to demonstrate the usefulness of the packages, while extremely valuable and helpful, only consider inputs of type int, float, string, dict and arrays.
How can one call Julia functions that take other data types, say, custom Julia structs, as inputs? I’d really appreciate if somebody on this forum could offer some ideas/help on how I can call Julia functions with custom data structures other than the predefined types. I have provided an example below. The struct “Container” defined below is a simplified struct, and in a more general situation, could hold other custom structs. [I come from C++/Python background, and have heavily used Boost.Python and pybind11 to expose and extend Python to C++ and vice-versa. I am looking for something similar here]
#container.jl file:
export Container
export add_container_items
using LinearAlgebra
mutable struct Container{T<:Real}
x::T
y::T
function Container{T}(x::T, y::T) where {T}
return new(x, y)
end
function Container{T}(y::T) where {T}
return new(2, y)
end
end
function add_container_items(a::Container{T}) where{T}
y = a.x + a.y
return y
end
function add_numbers(x::Float64, y::Float64)
return x + y
end
Calling add_numbers() function from Python is straight forward, but how can I call add_container_items() function from Python, which takes a custom struct “container” as an input?
Thanks for any help in advance!