I'm extending python code with c++ functions acting on Numpy arrays (very large). Due to legacy i currently have both PyBind and Python API functions, both for Python 3.6 and above. As soon as I access memory via ptr, I would love to be sure that memory layout is exactly corresponding to c++ array under this ptr. I found that transposed array has exactly the same content in ptr in both cases. I also found that subarrays being send via Python API give in c++ exactly the same ptr as if it was the full array. In the course of development and testing i also observed more weird examples I believe, but cannot reproduce them any longer. I cannot find any recipes on the internet so far. My solution is to make copy of all input arrays in Python, like f(a.copy(), b.copy())
It seem to work well. Is this optimal/sufficient solution? I do not have any limitations on how input arrays have been produced. Transpose, subarray, reshape, in any combinations.