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

Strided memoryview cast #2563

Open
jakirkham opened this Issue Aug 17, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@jakirkham
Contributor

jakirkham commented Aug 17, 2018

Would be nice if one could cast something to a strided memoryview with non-trivial striding. This is basically an extension of casting a pointer to a memoryview.

cdef np.ndarray[float, ndim=1] a = np.empty((10,), dtype=np.float32)[::2] 
cdef a_v = <floating[:a.shape[0]:a.strides[0]]>&a.data[0]

Note: In reality a may actually be a pointer and not a NumPy array, which is where the value of this approach comes in.

@robertwb

This comment has been minimized.

Show comment
Hide comment
@robertwb

robertwb Aug 17, 2018

Contributor

This would be hard because there are other operations such as "shape" that ndarrays are expected to have, and it can be used in an object-like context. If you have a pointer that you want to use in this manner, use the numpy APIs for wrapping bare (unmanaged) pointers in ndarray objects.

It might be more possible to create a fake memory view of a pointer, but still a bit iffy.

Contributor

robertwb commented Aug 17, 2018

This would be hard because there are other operations such as "shape" that ndarrays are expected to have, and it can be used in an object-like context. If you have a pointer that you want to use in this manner, use the numpy APIs for wrapping bare (unmanaged) pointers in ndarray objects.

It might be more possible to create a fake memory view of a pointer, but still a bit iffy.

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