I am trying to make some Julia code work with Python, and I am having some trouble understanding why certain kind of Julia arrays are able to translate to NumPy arrays. A regular Julia Array seems to get translated just fine, but if I try to use @view or reinterpret I get a Python list rather than a numpy.ndarray.
I think it is possible to convert more standard Julia array types to NumPy arrays. I’ve created this pull request to try to apply this to types that implement strides:
Thanks. While we are waiting on the PR to be reviewed or merged, is there any possible workarounds that the user can do? If the PR proves impossible, would it be possible to put these features into a separate package?
The easiest way would be to use standard Julia arrays, but this may be problematic if they are GB-sized or in a very hot loop.
Or is it possible to move the whole calculation to Julia, removing the need for PyCall?
I’m moving large images around, so copying data would be quite problematic. Looking at the PR that @mkitti mentioned, it looks possible to override some of the few PyCall methods to achieve similar functionality.
In particular, if one implemented NpyArray(a::AbstractArray{T}, revdims::Bool) where T<:PYARR_TYPES and pyembed(po::PyObject, jo::Any) for SubArray and Base.ReinterpretArray then maybe it will work?
You might like to try my package http://github.com/cjdoris/PythonCall.jl, all mutable objects do non-copying conversion to Python and any strided array is usable as a numpy array.