Passing wrapped julia objects with pyfunction and pyfunctionret
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách lần theo các entry point PyCall.pyfunction và PyCall.pyfunctionret, tập trung vào hành vi của PyAny, PyObject và đối tượng Julia được bọc như mô tả trong ví dụ. Xác định xem việc unwrapping có được hỗ trợ hay không; được coi là hoàn tất khi có either một invocation được documented chấp nhận Vector{Float64} được bọc, hoặc một implementation có phạm vi giới hạn với các test bao phủ call path này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
For performance reasons I would like to wrap Julia functions I am using in Python with the PyCall.pyfunctionret and PyCall.pyfunction wrappers. One of my Julia functions returns an object that is explicitly not converted to a python object using the PyCall.pyfunctionret function. Now I would like to pass this object back into Julia and wrap the function with the PyCall.pyfunction wrapper.
The following example works, but from my understanding it does not actually benefit much from using the pyfunction wrapper, since I have to use the PyAny type and PyCall would still have to infer the type of the object. I would like to specify something more specific than PyAny in my call to pyfunction.
So I have this in julia:
function example(firstnumber, secondnumber)
return Float64[firstnumber, secondnumber]
end
function useobject(obj::Vector{Float64})
println("this is the object:", obj)
end
And in python:
from julia import Main
Main.eval('using PyCall; include("juliafunctions.jl")')
jl_function = Main.eval("pyfunctionret(example, Any, Float64, Float64)")
# These two work as expected - the first returns a converted python object
# (which is a numpy array in this case) and the second returns a simple
# wrapped julia object.
python_object = Main.example(1, 2)
jl_object = jl_function(1, 2)
# Now here is my problem. This works, but I would like to replace
# PyAny here, to avoid the automatic type inference pyjulia has to do in
# this case:
jl_secondfunction = Main.eval("pyfunction(useobject, PyAny)")
jl_secondfunction(jl_object)
I also tried pyfunction(useobject, PyObject) but that just doesn't work at all and I tried pyfunction(useobject, Any), which comes slightly closer to what I want because it passes the wrapped python object into Julia. However, that fails since it doesn't find the correct method for type PyObject.
My questions are the following:
- Is my understanding of pyfunction and the use of the PyAny type correct, as in that PyCall still needs to infer the type of the passed in object before attempting any conversion?
- Is there a way to pass in the object and have PyCall just unwrap the wrapped julia object? If so what do I need to do to use it? I couldn't figure it out from the documentation
I would be happy to help improving the documentation or adding this feature if it isn't available and if someone could point me in the right direction.
- Ngôn ngữ chính
- Julia
- Star
- 1.5k
- Fork
- 186
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JuliaPy/PyCall.jl
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Meta-Issue: Mutli-threading leads to segfaultsCó thể đã có người làm @topolarity đã nhận 213 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
-
Crashes with Julia 1.12 and Revise.jlCó thể đã có người làm @topolarity đã nhận 213 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Tất cả issue của JuliaPy/PyCall.jl
Issue tương tự
-
Add DocStringExtensionsĐang mởdocumentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ohno/Antique.jl#165 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
grame-cncm/faust#1344 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
SciML/DiffEqNoiseProcess.jl#342 ·
-
Broken links in the docsĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100