Help with user-defined data type
a,b = testit (256) a
I'm trying out user-defined data type for numpy, but I'm a bit stuck. Maybe someone can spot the problem? I'm creating a descr like this: PyArray_Descr * d = (PyArray_Descr*)(PyObject_New (PyArray_Descr, &PyArrayDescr_Type)); d->typeobj = typeptr; d->kind = 'O'; // ??? d->type = 'z'; d->byteorder = '='; d->hasobject = 0; d->elsize = sizeof (cmplx_int_t); d->alignment = __alignof__ (cmplx_int_t); d->subarray = 0; d->fields = 0; d->names = 0; PyArray_ArrFuncs * f = new PyArray_ArrFuncs; PyArray_InitArrFuncs (f); f->copyswapn = ©swapn<cmplx_int_t>; f->copyswap = ©swap<cmplx_int_t>; f->getitem = &getitem<cmplx_int_t>; f->setitem = &setitem<cmplx_int_t>; d->f = f; incref (typeptr); Then register: PyArray_RegisterDataType (d1); This seems OK, I get a typenum 256. But if I try to use it, bad things happen. This tests creating an array, both from typenum and from descr: PyArray_Descr* descr = PyArray_DescrFromType (typenum); npy_intp dims[] = {10}; PyObject * o1 = PyArray_NewFromDescr (&PyArray_Type, descr, 1, dims, 0, 0, 0, 0); PyObject * o2 = PyArray_New (&PyArray_Type, 1, dims, descr->type_num, 0, 0, 0, 0, 0); If I try this for typenum=1, it's fine. But if I use my typenum=256 I get python: Objects/typeobject.c:1418: extra_ivars: Assertion `t_size >= b_size' failed. Program received signal SIGABRT, Aborted. 0x0000003834c30ec5 in raise () from /lib64/libc.so.6
Are there any examples of user-defined data types that I could get hold of?
On Feb 17, 2008 3:27 PM, Neal Becker <ndbecker2@gmail.com> wrote:
Are there any examples of user-defined data types that I could get hold of?
I think you may be the first. The problems you encounter may well be bugs rather than problems with your code. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Robert Kern wrote:
On Feb 17, 2008 3:27 PM, Neal Becker <ndbecker2@gmail.com> wrote:
Are there any examples of user-defined data types that I could get hold of?
I think you may be the first. The problems you encounter may well be bugs rather than problems with your code.
There is mention in several places about 'inheritance' from existing scalar objects. What is this about? Why would I want my type to inherit from an existing type, and what does this imply about numpy handling of my type?
participants (2)
-
Neal Becker
-
Robert Kern