Cython's libcpp has wrappers for containers like std::vector
, but still nothing similar for std::array
. As far as I understand, it's because Cython does not have support for non-type template arguments, so there is no nice way to create a .pxd
for arrays of arbitrary size (See here, and here for existing discussion). Since these posts are from several years ago, I am wondering if there has been any progress in preferred ways to handle std::array
types?
For a concrete example, here's something I'm interested in doing. I have a c++ struct that contains an array type:
%% ex.hpp
#include <array>
struct example{
double a;
int b;
std::array<double, 3> c;
};
and I want to make a cdef
class that exposes c
with a getter and setter so I can set it with a python list or numpy
array:
cdef extern from "ex.hpp":
cdef cppclass example:
double a
int b
<???> c # Not sure what the best option is here
cdef class pyExample:
cdef example *_cppExample
def __cinit__(self):
self._cppExample= new example()
def __dealloc(self):
del self._cppExample
@property
def c(self):
return self._cppExample
@c.setter
def c(self, pyArr):
self._cppExample.c = pyArr