[Numpy-discussion] A little help please?

Neal Becker ndbecker2@gmail....
Mon Mar 3 05:37:10 CST 2008


Travis E. Oliphant wrote:

> Travis E. Oliphant wrote:
>> Neal Becker wrote:
>>   
>>> Travis E. Oliphant wrote:
>>>
>>>
>>>   
>>>
>>> The code for this is a bit hard to understand.  It does appear that it
>>> only
>>> searches for a conversion on the 2nd argument.  I don't think that's
>>> desirable behavior.
>>>
>>> What I'm wondering is, this works fine for builtin types.  What is
>>> different in the handling of builtin types?
>>>   
>>>     
>>
>> 3) For user-defined types the 1d loops (functions) for a particular
>> user-defined type are stored in a linked-list that itself is stored in a
>> Python dictionary (as a C-object) attached to the ufunc and keyed by the
>> user-defined type (of the first argument).
>>
>> Thus, what is missing is code to search all the linked lists in all the
>> entries of all the user-defined types on input (only the linked-list
>> keyed by the first user-defined type is searched at the moment).    This
>> would allow similar behavior to the built-in types (but a bit more
>> expensive searching).
>>   
> This code is now in place in current SVN.  Could you re-try your example
> with the current code-base to see if it is fixed.
> 
> Thanks,
> 
> -Travis
It seems to have broken 1 test:

FAIL: Test of inplace operations and rich comparisons
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python2.5/site-packages/numpy/ma/tests/test_old_ma.py", line 480, in check_testInplace
    assert id1 == id(x.data)
AssertionError

----------------------------------------------------------------------
Ran 801 tests in 1.229s

FAILED (failures=1)

But looks like my test is working.

BTW, don't forget the patch I sent

diff --git a/numpy/core/src/ufuncobject.c b/numpy/core/src/ufuncobject.c
--- a/numpy/core/src/ufuncobject.c
+++ b/numpy/core/src/ufuncobject.c
@@ -3434,10 +3434,10 @@
 static int
 cmp_arg_types(int *arg1, int *arg2, int n)
 {
-    while (n--) {
-        if (PyArray_EquivTypenums(*arg1, *arg2)) continue;
-        if (PyArray_CanCastSafely(*arg1, *arg2))
-            return -1;
+    for (;n > 0; n--, ++arg1, ++arg2) {
+        if (PyArray_EquivTypenums(*arg1, *arg2) ||
+           PyArray_CanCastSafely(*arg1, *arg2))
+         continue;
         return 1;
     }
     return 0;




More information about the Numpy-discussion mailing list