我想在C/C++中为numpy数组分配数字,并将它们作为numpy数组传递给Python。这可以使用PyArray_SimpleNewFromData完成。
问题在于,我还想注册一个函数,在numpy数组引用计数器达到零时从Python中调用该函数,并在C端调用一些析构语义...这是我所需要的伪代码示例:
问题在于,我还想注册一个函数,在numpy数组引用计数器达到零时从Python中调用该函数,并在C端调用一些析构语义...这是我所需要的伪代码示例:
float* arr; PyObject* np_arr; void (*destructor)(float* arr);
// ... C-allocate array on arr, ...
// ...
// ... initialize destructor with some suitable value, and then:
np_arr = /* ... create the array to wrap arr,
and to use destructor on some meaningful way ... */
有没有简单的方法可以这样做?