This may be the problem. Simple diffs are pleasant. I'm guessing this code doesn't get a lot of testing. Glad it's there, though!
Geoffrey diff --git a/numpy/core/src/umath/ufunc_type_resolution.c b/numpy/core/src/umath/ufunc_type_resolution.c index 0d6cf19..a93eda1 100644 --- a/numpy/core/src/umath/ufunc_type_resolution.c +++ b/numpy/core/src/umath/ufunc_type_resolution.c @@ -1866,7 +1866,7 @@ linear_search_type_resolver(PyUFuncObject *self, case -1: return -1; /* A loop was found */ - case 1: + case 0: return 0; } } On Sun, Dec 4, 2011 at 9:29 AM, Charles R Harris <charlesr.har...@gmail.com> wrote: > > > On Sat, Dec 3, 2011 at 8:14 PM, Geoffrey Irving <irv...@naml.us> wrote: >> >> Hello, >> >> I'm trying to add a fixed precision rational number dtype to numpy, >> and am running into an issue trying to register ufunc loops. The code >> in question looks like >> >> int npy_rational = PyArray_RegisterDataType(&rational_descr); >> PyObject* equal = ... // extract equal object from the imported numpy >> module >> int types[3] = {npy_rational,npy_rational,NPY_BOOL}; >> if >> (PyUFunc_RegisterLoopForType((PyUFuncObject*)ufunc,npy_rational,rational_ufunc_##name,_types,0)<0) >> return 0; >> >> In Python 2.6.7 with the latest numpy from git, I get >> >> >>> from rational import * >> >>> i = array([rational(5,3)]) >> >>> i >> array([5/3], dtype=rational) >> >>> equal(i,i) >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> TypeError: ufunc 'equal' not supported for the input types, and >> the inputs could not be safely coerced to any supported types >> according to the casting rule ''safe'' >> >> The same thing happens with (rational,rational)->rational ufuncs like >> multiply. >> >> The full extension module code is here: >> >> https://github.com/girving/poker/blob/rational/rational.cpp >> >> I realize this isn't much information to go on, but let me know if >> anything comes to mind in terms of possible reasons or further tests >> to run. Unfortunately it looks like the ufunc ntypes and types >> properties aren't updated based on user-defined loops, so I'm not yet >> sure if the problem is in registry or resolution. >> >> It's also possible someone else hit this before: >> http://projects.scipy.org/numpy/ticket/1913. >> > > I haven't tried adding a new type and can't offer any suggestions. But there > was a recent implementation of a quaternion type that might be worth looking > at for comparison. You can find it here. > > Chuck > > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion