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
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to