[NumPy-Tickets] [NumPy] #1619: Loading aligned dtype error

NumPy Trac numpy-tickets@scipy....
Wed Mar 16 01:58:58 CDT 2011


#1619: Loading aligned dtype error
-----------------------------+----------------------------------------------
 Reporter:  Ihor.Melnyk      |       Owner:  somebody  
     Type:  defect           |      Status:  needs_work
 Priority:  highest          |   Milestone:  2.0.0     
Component:  numpy.core       |     Version:  devel     
 Keywords:  dtype alignment  |  
-----------------------------+----------------------------------------------
Changes (by mwiebe):

  * status:  needs_review => needs_work


Comment:

 I think the bug here is in __repr__ not producing a good string to
 reconstruct the data type. Rather than coming up with an awkward
 workaround, I would suggest __repr__ print the following when the exact
 type would not be reconstructed with the normal repr:

 {{{
 dtype({'names': ['f0', 'f1', 'f2'], 'formats': [dtype('int8'),
 dtype('int32'), dtype('int8')], 'offsets': [0, 4, 8]})
 }}}

 Unfortunately, however, this is still not good enough! It produces a type
 with itemsize 9 instead of 12. I think it's also necessary to extend the
 dtype construction syntax to something like:

 {{{
 dtype({'names': ['f0', 'f1', 'f2'], 'formats': [dtype('int8'),
 dtype('int32'), dtype('int8')], 'offsets': [0, 4, 8]}, itemsize=12)
 }}}

 Also, to see why the proposed patch doesn't work, consider the following
 example.

 {{{
 >>> t = np.dtype('i4, i1', align=True)
 >>> s = eval(repr(t))
 >>> t
 dtype([('f0', '<i4'), ('f1', '|i1')])
 >>> s
 dtype([('f0', '<i4'), ('f1', '|i1')])
 >>> t.itemsize
 8
 >>> s.itemsize
 5
 }}}

 Here there is no clue provided to get the correct itemsize, extending the
 dtype constructor to have an itemsize parameter is the only reasonable way
 I can think of to make this work in general.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1619#comment:3>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list