Thanks to visit codestin.com
Credit goes to github.com

Skip to content

np.ctypeslib.as_array(struct_array) gives an unstructured void array #10978

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

Closed
eric-wieser opened this issue Apr 26, 2018 · 0 comments
Closed
Labels

Comments

@eric-wieser
Copy link
Member

eric-wieser commented Apr 26, 2018

>>> class Struct(ctypes.Structure):
...     fields = [('a', ctypes.c_int16)]

>>> arr = (Struct*3)()

>>> np.ctypeslib.as_array(arr)
AttributeError: 'Struct' object has no attribute '__array_interface__'
# hmm

>>> pointer = ctypes.pointer(arr[0])
>>> np.ctypeslib.as_array(pointer, shape=(3,))
array([None, None, None], dtype=object)
# wat

>>> pointer_all = ctypes.pointer(arr)
>>> np.ctypeslib.as_array(pointer_all, shape=())
array(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 
      dtype='|V24')
# wat
eric-wieser added a commit to eric-wieser/numpy that referenced this issue Jun 8, 2018
…ype(ctype_obj))

Fixes numpygh-10528
Fixes numpygh-10978
Fixes numpygh-11150

A warning is thrown when ctypes misbehaves, in order to not hide issues that need fixing upstream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant