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

Static array cannot generate memory view #3162

Open
jakirkham opened this issue Oct 1, 2019 · 2 comments

Comments

@jakirkham
Copy link
Contributor

commented Oct 1, 2019

Attempting to generate a memoryview from a static array fails with the error message below. Am a little confused as to why a static array would be treated as a Python list.

cpdef void func(): 
    cdef int[2] a 
    m = memoryview(a)
TypeError: memoryview: a bytes-like object is required, not 'list'

Edit: For clarity, the cdef int[2] a line turns into int __pyx_v_a[2];.

@jakirkham

This comment has been minimized.

Copy link
Contributor Author

commented Oct 1, 2019

Also related to issue ( #3161 ).

@jakirkham

This comment has been minimized.

Copy link
Contributor Author

commented Oct 2, 2019

Another way to accomplish this would be the following; where, the code in memoryview(...) constructs a Cython memoryview onto a, which does support the buffer protocol.

cpdef void func():
    cdef int[2] a
    m = memoryview(<int[:2:1]>(&a[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.