From: Travis O. <oli...@ie...> - 2006-09-15 18:26:34
|
Martin Wiechert wrote: > On Friday 15 September 2006 19:14, Travis Oliphant wrote: > >> Martin Wiechert wrote: >> >>> Thanks Albert! Do you also know the corresponding C-API function? It >>> cannot be PyArray_DescrConverter (PyObject *, PyArray_Descr **), whose >>> signature has no "align", right? >>> >> The DescrConverter function is meant for "O&"-style conversions. It >> can't accept an align function. We could possibly add something to the >> converter to allow specification of alignment through the object to be >> converted. >> >> > > I begin to see the light.... > > For dictionaries one could maybe just add an optional key "align". > Also an optional key "elsize" or "itemsize" to force the total size of the > record may sometimes be useful. E.g. one may want to faithfully map a given C > struct. (That's why I was asking for trailing unused bytes.) > > But I understand that other things have higher priority. > > >> Or, you can just call the __new__ method of the PyArrayDescr_Type object >> >> res = PyObject_CallMethod((PyObject *)&PyArrayDescr_Type, "__new__", >> "Oi", dict_object, 1)) >> >> or call the tp->new method directly: >> >> args = Py_BuildValue("Oi", dict_object, 1); >> PyArrayDescr_Type->tp_new(&PyArrayDescr_Type, args, NULL); >> Py_DECREF(args); >> >> > > Thank you! I'll try this. > > >> (I think passing in NULL for the keywords is O.K., but I haven't checked >> it). >> >> -Travis >> >> > > One final question. To me the repr of a dtype with gaps is a little bit > puzzling: > > >>>> dtype ({'names': ['a', 'b', 'c'], 'formats': ['<a4', '<f8', '<f4'], >>>> > 'offsets': [0, 16, 24]}) > dtype([('a', '|S4'), ('', '|V12'), ('b', '<f8'), ('', '|V12'), ('c', '<f4')]) > > There should be no gap between "b" and "c" but still the repr has ('', '|V12') > between them. Am I missing something? > There was a bug I just fixed in the representation of these structures with gaps. It should be fixed in SVN, now. -Travis |