我正试图编写一个cython接口到腮腺炎求解器(zmumps)的复杂版本。我遇到了一些问题,因为我以前对C或cython都没有经验。{1}下面的示例^能得到UMPI的真实代码。在
我相信我的问题是指向ZMUMPS_复杂结构的指针。为了
到目前为止,我有以下内容(从pymumps中大量提到):
zmumps_.pxd:
from libc.string cimport strncpy
cdef extern from "mumps_c_types.h":
ctypedef struct ZMUMPS_COMPLEX "ZMUMPS_COMPLEX":
double r
double i
cdef extern from "zmumps_c.h":
ctypedef int MUMPS_INT
ctypedef struct c_ZMUMPS_STRUC_C "ZMUMPS_STRUC_C":
MUMPS_INT sym, par, job
MUMPS_INT comm_fortran # Fortran communicator
MUMPS_INT n
# Assembled entry
MUMPS_INT nz
MUMPS_INT *irn
MUMPS_INT *jcn
ZMUMPS_COMPLEX *a
# RHS and statistics
ZMUMPS_COMPLEX *rhs
MUMPS_INT infog[40]
void c_zmumps_c "zmumps_c" (c_ZMUMPS_STRUC_C *)
zmumps_c.pyx
^{pr2}$在python代码中,我可以使用
import zmumps_c
import numpy as np
MUMPS_STRUC_C = staticmethod(zmumps_c.ZMUMPS_STRUC_C)
id = MUMPS_STRUC_C()
x = np.r_[1:10]
id.irn = x.__array_interface__['data'][0]
但是,我不知道如何设置a或rhs的值。任何帮助都将不胜感激。在
实现这一目标的方法不止一种——这里有一种方法。在
下面的代码定义了}方法,允许它接受
ZMUMPS_COMPLEX
的包装器。然后它为ZMUMPS_STRUC_C
定义一个包装器,并为rhs
属性使用__get__
和{ZMUMPS_COMPLEX
包装。在zmumps_c.pyx
^{pr2}$main()
函数演示了这两个对象的行为。输出应如下所示:我没有安装库,所以我使用下面的虚拟定义进行了测试:
zmumps_.pxd
设置.py
这可能有助于:
从here抓取的。在
由于
ZMUMPS_COMPLEX
和内置的Py_complex
结构具有完全相同的结构,因此您应该能够通过在这两种类型之间创建一个桥来实现这一点(使用typedefs和/或cast或一个将Py_复杂结构转换为ZMUMPS_复杂体的函数)。。。在我很乐意帮忙,但我目前还没有安装腮腺炎。。。在
相关问题 更多 >
编程相关推荐