-
Notifications
You must be signed in to change notification settings - Fork 32
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
Q: when the result of d_to_python_numpy_ndarray is passed to Python, is the array also copied by value? i.e Python receive a copy? #165
Comments
It has been quite a while since I have touched that code, but knee jerk answer is it copies by reference, and a quick close read supports that - it is copying pointers in a rather unreadable way to support arbitrary dimension numpy arrays |
My intention is that: since D code and Python code run in the same memory space, is it possible for them to directly share the same raw pointer to the beginning of an array (let's only consider 1D array of float type) without the need to copy array contents? |
yes |
So, how? can you show a small example 😀 ? I tried to pass a D array using d_to_python_numpy_ndarray, and changed the contents on the Python side, but when I print the D side array, it's still the same. |
uh oh, maybe I'm a liar.. let me try |
ya, its doing a value copy. dang.
|
Thanks for the example. Yes, in this way it can share the raw pointer on both sides. |
I'm not sure if this is related, but I'm experiencing a problem: a Python func call hangs somewhere in a multi threaded program
This looks like a Python GIL locking issue. So before I check other things, I want to ask the following question: does this approach work in a multi threaded situation: Specifically: suppose in the D's main thread, at the init() stage, all these If yes, is there any pyd func call to release the lock (on I found these two functions, but did not see how they are used:
Thanks. |
Just an update: play with Python GIL is no fun. I think the best practice to use PyD / Python is to keep it running in the same single D thread, which makes things easier. Even with this setting, I sometimes run into problems with dynamically loaded libraries by Python. |
According to the doc:
My question is: when the result of d_to_python_numpy_ndarray is passed to Python, is the array also copied by value? i.e Python receive a copy?
If yes, is there anyway to avoid the copy?
Thanks.
The text was updated successfully, but these errors were encountered: