-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Typed memoryview doesn't work with read-only buffers #1605
Comments
Hi, I also ran into this issue today. |
I really liked the const keyword approach. What are the show stoppers? |
Currently, adding const to a fused type memory view gives a compiler crash in 0.25.2. Thus it appears to need some work on the parser to get this working. Is a pull request welcomed? @robertwb @scoder
|
It appears this bug is keeping people away from the memoryview to use the older ndarray interface. for example, see this workaround in pandas pandas-dev/pandas#12013 |
Yes we've also avoided typed memoryviews in python for this reason, land up using pointers, resulting in hard-to-find bugs that could have easily been caught with a boundscheck were we using memoryviews. |
I have been surprised that this has not been addressed since I knew of the RFC patch two years ago. But perhaps the Cython team isn't aware that it should be a priority because the non-support deters users from Cython best practices, particularly where read only memory maps are a key feature of parallelism as in @joblib |
This also caused to use sub-optimal hacks in pandas and scikit-learn for instance:
Another related open bug in pandas: |
From a quick glance, the patch seems to lack support for Given that there is general support for I understand that this is a problem for users, so we should try to find a solution that fixes the problem without waiting another two years. |
I have an initial implementation up at https://github.com/scoder/cython/tree/readonly_buffers that automatically determines the need for a writable buffer, and otherwise sticks to a read-only one. It has some bugs and fails to detect some "read-only" vs. "needs writable" cases at compile time, but it mostly works. It also implements explicit Feedback welcome. |
Compare at master...scoder:readonly_buffers |
Now that an initial implementation is there, I'd be happy if someone else could take over. I don't think I'll keep working on this. |
There is a bug with the memoryview where it is unable to handle read-only buffers cython/cython#1605 Because of this I have reverted back to using the numpy arrays.
Came here via #1682 because of "BufferError: Object is not writable." when trying to pass a |
yes, it's an unfortunate workaround: it works, but it leaves more room for
bugs to crawl in
|
Right, thanks for the reminder. |
Copy grayscale images due to cython/cython#1605.
Typed memoryviews don't work with read-only buffers. A banal example:
Example session:
There is no evident reason why above simple function wouldn't work with a read-only buffer. About two years ago, this issue was raised on the mailing list along with a RFC patch:
https://mail.python.org/pipermail/cython-devel/2015-February/004316.html
Some discussion about a possible use for a
const
keyword:https://groups.google.com/forum/#!topic/cython-users/32CMgaLrNhc
The text was updated successfully, but these errors were encountered: