用python.net调用dotnet函数失败时如何调试python函数签名

2024-04-28 23:26:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题

我试图从python调用一个c#函数f()。函数f()有一个包含许多输入和输出参数的复杂签名。实际签名如下所示:

Void f(MathNet.Numerics.LinearAlgebra.Matrix`1[System.Double],
       MathNet.Numerics.LinearAlgebra.Matrix`1[System.Double],
       MathNet.Numerics.LinearAlgebra.Matrix`1[System.Double],
       Double[,], Double[,], Double, Double, Double,
       Double ByRef, Double ByRef, Double ByRef, Double ByRef,
       Double ByRef, Double ByRef, Double ByRef, Double ByRef,
       Double ByRef, Double ByRef, Double ByRef, Double ByRef)

我试图使用python.net包调用这个函数。我的呼叫失败,出现错误:

No method matches given arguments for f

我试过的

我知道适当的dotnet函数是通过其签名从python.net中选择的。我可以通过访问导入的dotnet类来读取函数f的预期签名:

mydotnetclass.f.Overloads

我的问题是,我不知道当前函数调用正在创建什么签名,因此我看不到哪个参数导致签名匹配失败。不幸的是,python.net不可能显式调用特定的重载来覆盖签名匹配

我尽力匹配输入参数的签名。我使用

matrixArgument = LinearAlgebra.Double.Matrix.Build.DenseOfRowArrays(list(numpy_ndMatrix))
arrayArg = clr.System.Array.CreateInstance(clr.System.Double,numpyArray.shape[0],numpyArray.shape[1])

对于双参数,我使用了普通的python双类型变量以及clr.System.Double()类型

返回未初始化的变量

问题

我可以显示由对dotnet函数的函数/方法调用创建的签名吗?例如在这种情况下

a=1.0
b=1
c="abc"
x,y = mydotnetclass.g(a,b,c)

我想看看下面的签名

Void mydotnetclass.g(Double, int, String, Double byref, String byref)

很明显,返回参数签名部分不能从调用本身派生,而只能从函数g()的实现派生

至少我需要知道哪些参数导致签名不匹配


Tags: 函数参数netsystemmatrixdoublenumericsvoid