Hello, I have some questions about how ``align=True`` and the corresponding ``isalignedstruct`` attribute work. Suppose we create the following dtype:
>>> dt1 = numpy.dtype(dict(names=['i1','i2'], formats=[numpy.int32, >>> numpy.int32], offsets=[0,4], itemsize=12, aligned=True)) >>> dt1.alignment 4 >>> dt1.isalignedstruct True The problem here is that the itemsize ``12`` is not actually achievable in C code for these particular fields without an explicit padding. But the ``isalignedstruct`` field reports that the struct is aligned, which is a bit misleading. There is no way to know which is true: 1) ``itemsize`` is consistent with the fields (that is, in C code you would not need any explicit modifiers) 2) ``itemsize`` requires an explicit alignment attribute in C code (e.g, ``itemsize=16`` would be achievable with an explicit alignment=16 applied to the whole struct). 3) ``itemsize`` is not achievable in C code and requires padding. Based on this, I would expect the following behavior: >>> dt1 = numpy.dtype(dict(names=['i1','i2'], formats=[numpy.int32, >>> numpy.int32], offsets=[0,4], itemsize=8, aligned=True)) >>> dt1.base_alignment 4 >>> dt1.alignment 4 >>> dt1.isalignedstruct True >>> dt1 = numpy.dtype(dict(names=['i1','i2'], formats=[numpy.int32, >>> numpy.int32], offsets=[0,4], itemsize=12, aligned=True)) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: itemsize 12 for this dtype is not achievable without an explicit padding >>> dt1 = numpy.dtype(dict(names=['i1','i2'], formats=[numpy.int32, >>> numpy.int32], offsets=[0,4], itemsize=16, aligned=True)) >>> dt1.base_alignment 4 >>> dt1.alignment 16 >>> dt1.isalignedstruct True It would be also convenient to have a keyword for the total alignment of the struct (which will affect how it is placed in an encompassing struct): >>> dt1 = numpy.dtype(dict(names=['i1','i2'], formats=[numpy.int32, >>> numpy.int32], offsets=[0,4], itemsize=8, alignment=8, aligned=True)) >>> dt1.base_alignment 4 >>> dt1.alignment 8 >>> dt1.isalignedstruct True So, is the current numpy behavior an intended one, or is it a bug? Best regards, Bogdan _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
