Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace calls of POINTER() by byref() in Python interface to pass data arrays #4298

Closed
StrikerRUS opened this issue May 18, 2021 · 2 comments

Comments

@StrikerRUS
Copy link
Collaborator

It was proposed by @jameslamb in #4297 (comment) that byref calls will be faster according to ctypes official docs.

@jameslamb
Copy link
Collaborator

I asked @tara-jawahar about this, as I know she has some past experience with numpy's ctypes library. Some quotes from our conversation:

Based on what I know about ctypes and how Python works at the lower level, byref() sounds like a good option! In my projects, I've used NumPy's ctypes library which works a little differently since NumPy objects are created and stored at a lower level than Python objects, so I just passed in pointers to the NumPy arrays without explicitly calling a pointer() function.

If you're using NumPy or pandas objects, it might make sense to use NumPy's ctypes library

...it makes sense that byref() is faster because it looks like the Python version of ctypes uses Python objects that are stored as references to values in memory, whereas C objects such as NumPy arrays are stored as references to pointers.

So at some point I think it is worth investigating this further and doing some benchmarking. But I think that's efficiency work that can be done any time in a non-breaking way, so I personally am going to resist the urge to try it right now, in favor of some of the other items mentioned in #4310

@StrikerRUS StrikerRUS changed the title [RFC] Replace calls of POINTER() by byref() in Python interface to pass data arrays Replace calls of POINTER() by byref() in Python interface to pass data arrays Jun 9, 2021
@StrikerRUS
Copy link
Collaborator Author

Closed in favor of being in #2302. We decided to keep all feature requests in one place.

Welcome to contribute this feature! Please re-open this issue (or post a comment if you are not a topic starter) if you are actively working on implementing this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants