From: Jonathan W. <jon...@gm...> - 2006-10-26 22:26:52
|
I'm trying to write a Numpy extension that will encapsulate mxDateTime as a native Numpy type. I've decided to use a type inherited from Numpy's scalar double. However, I'm running into all sorts of problems. I'm using numpy 1.0b5; I realize this is somewhat out of date. For all the examples below, assume that I've created a 1x1 array, mxArr, with my custom type. The interface used by Array_FromPyScalar does not conform with the documentation's claim that a negative return value indicates an error. The return code from setitem is not checked. Instead, the code depends on a Python error being set. I seem to be able to load values into the array, but I can't extract anything out of the array, even to print it. In gdb I've verified that loading DateTime.now() correctly puts a float representation of the date into my array. However, if I try to get the value out, I get an error: >>> mxArr[0] = DateTime.now() >>> mxArr[0] Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/numpy/core/numeric.py", line 391, in array_repr ', ', "array(") File "/usr/lib/python2.4/site-packages/numpy/core/arrayprint.py", line 204, in array2string separator, prefix) File "/usr/lib/python2.4/site-packages/numpy/core/arrayprint.py", line 160, in _array2string format = _floatFormat(data, precision, suppress_small) File "/usr/lib/python2.4/site-packages/numpy/core/arrayprint.py", line 281, in _floatFormat non_zero = _uf.absolute(data.compress(_uf.not_equal(data, 0))) TypeError: bad operand type for abs() I'm not sure why it's trying to call abs() on my object to print it. I have a separate PyNumberMethods attached to my object type, copied from the float scalar type, and nb_absolute is set to 0. When I break at the various functions I've registered, the last thing Numpy tries to do is cast my custom data type to an object type (which it does so successfully) via _broadcast_cast. Thanks, Jonathan |