Wrap C struct with array member for access in python: SWIG? cython? ctypes?

后端 未结 5 1114
囚心锁ツ
囚心锁ツ 2021-02-03 10:19

I want to access a C function that returns a struct containing double arrays (where the lengths of these arrays is given by other int members of the struct) from python. The dec

5条回答
  •  孤独总比滥情好
    2021-02-03 10:55

    Cython rules:

    cdef extern from "the header.h":
    
    ctypedef struct element:
      int dim
      int vertices
      int quadrature_degree
      int polynomial_degree
      int ngi
      int quadrature_familiy
      double *weight
      double *l
      double *n
      double *dn
    
    void get_element(int dim, int vertices, int quad_degree, int poly_degree, element* e)
    

    and then you can interface it, from python space

提交回复
热议问题