8000 Alignment doesn't work for array of structs (Trac #2211) · Issue #663 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Alignment doesn't work for array of structs (Trac #2211) #663

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
numpy-gitbot opened this issue Oct 19, 2012 · 4 comments
Closed

Alignment doesn't work for array of structs (Trac #2211) #663

numpy-gitbot opened this issue Oct 19, 2012 · 4 comments

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/2211 on 2012-09-05 by trac user Ihor.Melnyk, assigned to unknown.

array of subtype alignment

t = np.dtype([('a', '|i1'), ('b', [('f0', '<i2'), ('f1', '<f4')], 2)], align=True)

actual dtype

[('a', '|i1'), ('b', [('f0', '<i2'), ('f1', '<f4')], (2,))]

expected dtype

[('a', '|i1'), (_, '|V3'), ('b', [('f0', '<i2'), (_, '|V2'), ('f1', '<f4')], 2)]
@ghost ghost assigned cournape Jun 28, 2013
@charris
Copy link
Member
charris commented Feb 18, 2014

It's definitely not aligned, although I'm not sure it needs to be all on 4 byte boundaries.

Still present in 1.9-devel.

@ahaldane
Copy link
Member

same bug as #5224. It is because dtype constructor ignores the align keyword for 'list of tuples' style of specification.

@ihormelnyk
Copy link
ihormelnyk commented Oct 30, 2016

Hi.
I am wondering whether you plan to fix this bug?
This fix is very important for our project because we use c++ python extension for high performance computations,, so numpy arrays allocated in python, should be compatible with usual c++ structs.
And we have to build and patch numpy for every new version.

def test_subtype_alignment(self): 
        t = np.dtype([('a', '|i1'), ('b', [('f0', '<i2'), ('f1', '<f4')])], align=True)
        self.assertEqual(t.descr, [('a', '|i1'), ('', '|V3'), ('b', [('f0', '<i2'), ('', '|V2'), ('f1', '<f4')])])

#PASSED

    def test_array_of_subtype_alignment(self): 
        t = np.dtype([('a', '|i1'), ('b', [('f0', '<i2'), ('f1', '<f4')], 2)], align=True)        
        self.assertEqual(t.descr, [('a', '|i1'), ('', '|V3'), ('b', [('f0', '<i2'), ('', '|V2'), ('f1', '<f4')], (2,))])

#FAILED

@ahaldane
Copy link
Member

Eventually it should be fixed. I'm not going to work on it until some other PRs get through though, so it's currently up for grabs.

By the way, a workaround is to use the "dict" form of specification instead of the "tuple" form, as that respects "align".

rbalint pushed a commit to rbalint/pywt that referenced this issue May 5, 2017
Also use dict for dtype definition because list format
ignores alignment. See numpy/numpy#663
rbalint pushed a commit 997F to rbalint/pywt that referenced this issue May 8, 2017
Also use dict for dtype definition because list format
ignores alignment. See numpy/numpy#663
ihormelnyk pushed a commit to ihormelnyk/numpy that referenced this issue Apr 18, 2018
ahaldane added a commit that referenced this issue Apr 18, 2018
Fixes #663: fixed dtype alignment for array of structs in case of converting from tuple descr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0