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

numpy.lib.stride_tricks.as_strided() does not preserve some structured dtypes #26

Open
fjarri opened this issue Dec 14, 2016 · 0 comments

Comments

@fjarri
Copy link

fjarri commented Dec 14, 2016

In the commit 2293b43 a test for numpy.lib.stride_tricks.as_strided() was added in array.py checking that it preserves a structured dtype. It works for the rather simple type there, but stops working for types with padding set through offsets parameter:

import numpy
from numpy.lib.stride_tricks import as_strided

dtype = numpy.dtype({
    'names':['i1','nested','i2'],
    'formats':['<u4',[('v', '<u8')],'<u4'],
    'offsets':[0,8,16], 'itemsize':24})

arr = numpy.zeros((128,), dtype)

print(dtype)
print(new_arr.dtype)

Output:

{'names':['i1','nested','i2'], 'formats':['<u4',[('v', '<u8')],'<u4'], 'offsets':[0,8,16], 'itemsize':24}
[('i1', '<u4'), ('f1', 'V4'), ('nested', [('v', '<u8')]), ('i2', '<u4'), ('f4', 'V4')]

Apparently, as_strided() adds some dummy fields in this case and removes offsets. The alternative version of as_strided() in array.py does preserve them, but since the numpy one passes the test, it does not get invoked.

Is it the planned behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant