C++通过PYBIND11读取Numpy阵列时的类型限制
我想知道是否有人知道下面的“类型punning”是否是必要的,还是最有效的技术或方法在最后一行中?
数据是2D numpy阵列的双打阵列引用为函数参数。
侧点:如果此函数无关紧要,则最终将出现内存泄漏 /错误,因为每次在相同的相同内存地址 /位置运行函数时,都会创建PTR_SUM指针,我不会删除指针“ ptr_sum”要在指向的内存位置中删除基础数据?
double* ptr_sum =(double*)buf_summary.ptr;
void Pricing::price_all(py::array_t<double>& in_summary){
if (in_summary.ndim() != 2) {
throw std::runtime_error("Results should be a 2-D Numpy array");
}
py::buffer_info buf_summary = in_summary.request(); // summary
// Pointer definition
double* ptr_sum = (double*)buf_summary.ptr;
I was wondering if anyone knows if the below "type punning" is necessary or if a more efficient technique or approach is best in the last line?
The data is an 2D Numpy array of doubles which is passed by reference as the function argument.
side point: If this function is called indefinetly will a memory leak/ error eventually occur as the ptr_sum pointer is being created each time the function is run on the same identical memory address / location, Im not deleting the pointer "ptr_sum" as it seems to delete the underlying data in the memory location it points to?
double* ptr_sum = (double*)buf_summary.ptr;
void Pricing::price_all(py::array_t<double>& in_summary){
if (in_summary.ndim() != 2) {
throw std::runtime_error("Results should be a 2-D Numpy array");
}
py::buffer_info buf_summary = in_summary.request(); // summary
// Pointer definition
double* ptr_sum = (double*)buf_summary.ptr;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论