wlav / CPyCppyy

Other
23 stars 20 forks source link

feat: modify VectorInit to handle numpy multi dimensional arrays #28

Closed Khushiyant closed 2 months ago

wlav commented 4 months ago

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.

Khushiyant commented 2 months ago

Implemented this PR logic in cppyy (frontend) - cppyy#255 instead