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
Support read-only numpy array. #427
Conversation
Support read-only numpy array.
Thx! |
Why does it seem acceptable to change the read status of an argument? At minimum the read status should be changed back once the length computed. There is no guarantee that the read status can safely be changed, read only arrays are often read only for a reason. I would reject (revert at this point) this PR unless it's meant to address a specific use case. |
We definitely want to use those two functions even though numpy arrays are readonly since we only reads from them by using memoryviews. I agree it is cleaner to change back the writeable flag. |
Sorry I don't follow, could you clarify? On Wed, Oct 1, 2014 at 11:43 AM, Marc-Alexandre Côté <
|
Sorry, I meant that because memoryviews accept only writeable numpy array, we have to change the flag in order to use these functions: How should I proceed to include those changes: make a new PR right now or revert this one first than make a new PR? |
PR is reverted until we figure out if the streamlines were read only for a reason. |
Sorry @MarcCote you will have to redo this PR. Let's go with the safe way of returning the input with the same state as it was given. @matthew-brett do you know why they streamlines are coming out from nibabel as readonly and do you think that there would be a problem with changing their status? |
Why are you getting read only streamlines?
|
In NiBabel when reading streamlines from a trk. More specifically, when using import numpy as np
A = np.array([1, 2, 3])
s = A.tostring()
B = np.ndarray(shape=(3,), dtype="int64", buffer=s)
print A.flags, "\n\n", B.flags will produces this:
|
Right now, using Cython version of
length
andset_number_of_points
on read-only numpy arrays (as provided by NiBabel) will fail. The reason is memoryview can only be used with writable numpy array (for more details check https://mail.python.org/pipermail/cython-devel/2013-February/003394.html)This PR makes sure those Cython functions set the writeable flag of numpy arrays to True before processing them.