pyjulia needs a little love. I distinctly remember figuring this out a long time ago, but am unable to do so in an easy fashion right now.
The best I could come up with is to take advantage of the fact that, when you include a file in julia, the last “value” in the file is returned. If the last thing in the file, is a function, then you get back an anonymous version of that function:
println("array size: $(size(x))");
println("max element: $(maximum(x))")
println("min element: $(minimum(x))")
In : import julia
In : j = julia.Julia()
In : fn = j.include('test.jl')
In : fn
Out: <PyCall.jlwrap myArrayFn>
In : import numpy as np
In : x = np.array([[1,2,3], [4,5,6]], dtype=np.float64)
In : fn(x)
array size: (2,3)
max element: 6.0
min element: 1.0
array([[ 2., 4., 6.],
[ 8., 10., 12.]])
This only works for the last function in the file.
I tried a number of other things (using
include_string, etc.), and nothing seemed to modify the Julia environment available in the python Julia object. It might be that the internals have changed, and that
pyjulia hasn’t kept up. Or maybe I’m just doing something wrong. I haven’t tried digging into the code to see why.
Anyway, hope this helps, and maybe someone else will respond with better info.