[Numpy-discussion] Creating a descr with aligned=1 using the C API
Travis Oliphant
oliphant.travis at ieee.org
Sun Apr 30 21:45:05 EDT 2006
Albert Strasheim wrote:
> Hello all
>
> I was wondering what the best way would be to create the following descr
> using the C API:
>
You can use the "new" method.
PyArray_Descr *dtype
PyObject *dict;
dtype = PyArrayDescr_Type.ob_type->tp_new(dtype->ob_type,
Py_BuildValue("Oi", dict, 1));
where the dict is the one you give.
Yes, this could be an easier-to use API.
> descr = dtype({'names' : ['index', 'value'], 'formats' : [intc, 'f8']},
> align=1)
>
> One could use PyArray_DescrConverter in multiarraymodule.c, but there
> doesn't seem to be a way to specify aligned=1 and one would have to build
> the dict object before being able to pass it on for conversion.
>
> Unless there's another easy way I'm missing, the API could possibly do with
> a function like PyArray_DescrFromCommaString(const char*, int align) which
> calls _convert_from_commastring. By the way, what is the general format of
> these commastrings?
>
It's in the NumPy book and it's also documented by numarray...
-Travis
More information about the NumPy-Discussion
mailing list