I'd like to get the index of the minimal element of a py::array_t variable in pybind11, but I encountered a problem when trying to combine std::distance and std::min_element.
let's say the py::array_t variable is named arr, the following code will get stuck when it's running:
std::distance(arr.begin(), std::min_element(arr.begin(), arr.end()))
initially I was thinking the py::array_t iterator is not compatible with std::distance function, but I did a test and the following code just works fine:
std::distance(arr.begin(), arr.end())
Can someone explain why the first one does not work? Thanks a lot.
py:array_tis contiguous in memory? I never used numpy/pybind. But when I look at numpy/array_t it seems to be a more complicated datastructure than std::array is (and its operations suggest dynamic memory allocation is in play)