Re: [Numpy-discussion] Can't add user defined complex types
Travis E. Oliphant wrote: Neal Becker wrote: In arrayobject.c, various complex functions (e.g., array_imag_get) use: PyArray_ISCOMPLEX - PyTypeNum_ISCOMPLEX, which is hard coded to 2 predefined types :( If PyArray_ISCOMPLEX allowed user-defined types, I'm guessing functions such as array_imag_get would just work? I don't think that it true. There would need to be some kind of idea of complex-ness that is tested. One way this could work is if your corresponding scalar inherited from the generic complex scalar type and then that was tested for. -Travis O. One thing that isn't working (so far) is fill: In [47]: a = array ([cmplx_int32(e) for e in xrange (10)]) In [48]: a Out[48]: array([(0,0), (1,0), (2,0), (3,0), (4,0), (5,0), (6,0), (7,0), (8,0), (9,0)], dtype=cmplx_int32) In [49]: r = get_real (a) In [50]: r Out[50]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32) In [51]: r[:] = 7 In [52]: a Out[52]: array([(7,0), (7,0), (7,0), (7,0), (7,0), (7,0), (7,0), (7,0), (7,0), (7,0)], dtype=cmplx_int32) In [53]: r.fill(8) In [54]: a Out[54]: array([(8,8), (8,8), (8,8), (8,8), (8,8), (7,0), (7,0), (7,0), (7,0), (7,0)], dtype=cmplx_int32) In [55]: r Out[55]: array([8, 8, 8, 8, 8, 7, 7, 7, 7, 7], dtype=int32) As you can see, fill only filled 1/2 of the array. slice [:] worked OK. My get_real is pretty much copied from real: ret = (PyArrayObject *) \ PyArray_NewFromDescr(self-ob_type, ret_type, self-nd, self-dimensions, self-strides, self-data + offset, self-flags, (PyObject *)self); ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Can't add user defined complex types
In arrayobject.c, various complex functions (e.g., array_imag_get) use: PyArray_ISCOMPLEX - PyTypeNum_ISCOMPLEX, which is hard coded to 2 predefined types :( If PyArray_ISCOMPLEX allowed user-defined types, I'm guessing functions such as array_imag_get would just work? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Can't add user defined complex types
Neal Becker wrote: In arrayobject.c, various complex functions (e.g., array_imag_get) use: PyArray_ISCOMPLEX - PyTypeNum_ISCOMPLEX, which is hard coded to 2 predefined types :( If PyArray_ISCOMPLEX allowed user-defined types, I'm guessing functions such as array_imag_get would just work? I don't think that it true. There would need to be some kind of idea of complex-ness that is tested. One way this could work is if your corresponding scalar inherited from the generic complex scalar type and then that was tested for. -Travis O. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Can't add user defined complex types
Travis E. Oliphant wrote: Neal Becker wrote: In arrayobject.c, various complex functions (e.g., array_imag_get) use: PyArray_ISCOMPLEX - PyTypeNum_ISCOMPLEX, which is hard coded to 2 predefined types :( If PyArray_ISCOMPLEX allowed user-defined types, I'm guessing functions such as array_imag_get would just work? I don't think that it true. There would need to be some kind of idea of complex-ness that is tested. One way this could work is if your corresponding scalar inherited from the generic complex scalar type and then that was tested for. -Travis O. You don't think which is true? Suppose along with registering a type, I can mark whether it is complex. Then we change PyArray_ISCOMPLEX to look at that mark for user-defined types. I believe get_part will just work. I more-or-less copied the code, and made my own functions 'get_real, get_imag', and they work just fine on my types. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Can't add user defined complex types
On Wed, Mar 19, 2008 at 10:42 AM, Travis E. Oliphant [EMAIL PROTECTED] wrote: Neal Becker wrote: In arrayobject.c, various complex functions (e.g., array_imag_get) use: PyArray_ISCOMPLEX - PyTypeNum_ISCOMPLEX, which is hard coded to 2 predefined types :( If PyArray_ISCOMPLEX allowed user-defined types, I'm guessing functions such as array_imag_get would just work? I don't think that it true. There would need to be some kind of idea of complex-ness that is tested. One way this could work is if your corresponding scalar inherited from the generic complex scalar type and then that was tested for. That brings up a question I have. In looking to introduce float16, I noted that the typenumbers are tightly packed at the low end. There is space for user defined types =128, IIRC, but float16 and cfloat16 really belongs down with the numbers. There are also several other types in the IEEE pipeline. So I am wondering if we can't spread the type numbers out a bit more. Chuck ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion