Passing wrapped julia objects with pyfunction and pyfunctionret
まだ誰も着手していません。
評価
調査の方向性
まず、PyCall.pyfunction と PyCall.pyfunctionret のエントリポイントを追跡し、例で説明されている PyAny、PyObject、およびラップされた Julia オブジェクトの動作に焦点を当てます。アンラッピングがサポートされているかを確認します。完了の条件は、ラップされた Vector{Float64} を受け付ける文書化された呼び出しがあるか、この呼び出し経路をカバーするテストを備えたスコープを限定した実装があることです。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Julia
- スター
- 1.5k
- フォーク
- 186
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaPy/PyCall.jl のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
Meta-Issue: Mutli-threading leads to segfaults対応中かも @topolarity が 213 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
-
Crashes with Julia 1.12 and Revise.jl対応中かも @topolarity が 213 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
JuliaPy/PyCall.jl の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
EnzymeAD/ReactantServer.jl#103 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ClapeyronThermo/Clapeyron.jl#649 ·
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
ohno/Antique.jl#165 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
JuliaLang/LinearAlgebra.jl#1749 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100