[Numpy-discussion] PyArray_DescrConverter - alignment / trailingunused bytes

Travis Oliphant oliphant.travis at ieee.org
Fri Sep 15 12:14:15 CDT 2006


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.

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);

(I think passing in NULL for the keywords is O.K., but I haven't checked 
it).

-Travis





More information about the Numpy-discussion mailing list