Passing wrapped julia objects with pyfunction and pyfunctionret
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne damit, die Einstiegspunkte PyCall.pyfunction und PyCall.pyfunctionret nachzuverfolgen, wobei du dich auf das im Beispiel beschriebene Verhalten von PyAny, PyObject und dem umschlossenen Julia-Objekt konzentrierst. Ermittle, ob das Auflösen der Umschließung unterstützt wird; als abgeschlossen gilt dies entweder bei einem dokumentierten Aufruf, der den umschlossenen Vector{Float64} akzeptiert, oder bei einer abgegrenzten Implementierung mit Tests, die diesen Aufrufpfad abdecken.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Julia
- Sterne
- 1.5k
- Forks
- 186
- Ø Merge
- 7 T. 10 Std.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus JuliaPy/PyCall.jl
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 20/100
Alle Issues in JuliaPy/PyCall.jl
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
documentation invalid
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
JuliaPhysics/BeamletOptics.jl#190 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
mul! with a Symmetric or Hermitian factor throws for a matrix view whose columns are not contiguousEvtl. vergeben @dkarrasch hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
JuliaLang/LinearAlgebra.jl#1829 ·
Maintainer antworten meist innerhalb von 1 Tag
-
`EnsembleSummary` `ci_type = :SEM` ribbon is `sqrt(N)` too wide for scalar statesEvtl. vergeben @isaacsas hat das vor 1 Tag übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
SciML/SciMLBase.jl#1654 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
MagneticResonanceImaging/MRIReco.jl#320 ·
Maintainer antworten meist innerhalb von 1 Tag