C++ type-punning when reading Numpy array via Pybind11

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;
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum