Skip to content

dtype(..., align=True) does not insert trailing padding (Trac #1790) #2383

Closed

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1790 on 2011-04-02 by @pv, assigned to @mwiebe.

Note the following:

>>> dt = np.dtype([('a', 'b'), ('b', 'i'), ('c', 'b')], align=True)
>>> dt.itemsize
9

whereas

#include <stdio.h>

typedef struct {
    char a;
    int b;
    char c;
} xxx_t;

int main()
{
    printf("%d\n", sizeof(xxx_t));
    return 0;
}

/* -> sizeof(xxx_t) == 12 */

Changing this might cause problems in third-party code. On the other hand, align=True is probably not that often used.

Activity

  1. numpy-gitbot commented on Oct 23, 2012

    @numpy-gitbot
    Author

    @charris wrote on 2011-04-02

    See also ticket #2215.

  2. numpy-gitbot commented on Oct 23, 2012

    @numpy-gitbot
    Author

    @mwiebe wrote on 2011-06-21

    The truth is actually worse, the different parsing methods are inconsistent. From ticket #2215:

    >>> t = np.dtype('i4, i1', align=True)
    >>> t.itemsize
    8
    >>> t = np.dtype([('f0','i4'), ('f1','i1')], align=True)
    >>> t.itemsize
    5
    

    I'm going to change it to always put in the trailing padding.

  3. numpy-gitbot commented on Oct 23, 2012

    @numpy-gitbot
    Author

    @mwiebe wrote on 2011-06-23

    Fixed in f57f1ef.

  4. numpy-gitbot commented on Oct 23, 2012

    @numpy-gitbot
    Author

    Milestone changed to NumPy 1.7 by @charris on 2012-04-26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions