[Numpy-discussion] PyArray_DescrConverter - alignment / trailingunused bytes

Martin Wiechert martin.wiechert at gmx.de
Fri Sep 15 13:53:14 EDT 2006


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?


Anyway, thanks again for your help.

Cheers,
Martin

>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion




More information about the NumPy-Discussion mailing list