Skip to content

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

Closed

Description

@numpy-gitbot

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)]

Activity

  1. charris commented on Feb 18, 2014

    @charris
    Member

    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.

  2. ahaldane commented on Sep 23, 2015

    @ahaldane
    Member

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

  3. ihormelnyk commented on Oct 30, 2016

    @ihormelnyk

    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

  4. ahaldane commented on Oct 31, 2016

    @ahaldane
    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".

  5. added a commit that references this issue on Apr 18, 2018
    8be088a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions