Two points: first, don't change comment indentation (I know the style is a bit unusual, but the reason for it is that it makes super-easy to read either the code or the comments, instead of having both in the same flow) and don't remove white lines if it changes the style.
Second, as discussed, the NumPy folks designed the "new-style" buffer protocol: https://docs.python.org/3/c-api/buffer.html . There are examples of its use in Utilities.cxx and LowLevelViews.cxx. The former is more convoluted b/c it also supports the "old-style" protocol (really old at this point); the latter shows how multi-dim arrays are handled.
As for the use of creating the std::vector on the Python side, I think that's fine. In LowLevelViews.cxx, the code is a single template that is instantiated for every builtin type. If performance becomes an issue, or if any of this code has to be lowered for Numba, then that's still an option. Can even pre-instantiate the common types (double, float, int) and let the rest go through Python, to get the best of both worlds.
Two points: first, don't change comment indentation (I know the style is a bit unusual, but the reason for it is that it makes super-easy to read either the code or the comments, instead of having both in the same flow) and don't remove white lines if it changes the style.
Second, as discussed, the NumPy folks designed the "new-style" buffer protocol: https://docs.python.org/3/c-api/buffer.html . There are examples of its use in
Utilities.cxx
andLowLevelViews.cxx
. The former is more convoluted b/c it also supports the "old-style" protocol (really old at this point); the latter shows how multi-dim arrays are handled.As for the use of creating the
std::vector
on the Python side, I think that's fine. InLowLevelViews.cxx
, the code is a single template that is instantiated for every builtin type. If performance becomes an issue, or if any of this code has to be lowered for Numba, then that's still an option. Can even pre-instantiate the common types (double
,float
,int
) and let the rest go through Python, to get the best of both worlds.