[Numpy-discussion] cmp_arg_types bug?

Neal Becker ndbecker2@gmail....
Fri Feb 22 12:45:48 CST 2008


Neal Becker wrote:

> cmp_arg_types(int *arg1, int *arg2, int n)
> {
>     while (n--) {
>         if (PyArray_EquivTypenums(*arg1, *arg2)) continue;
>         if (PyArray_CanCastSafely(*arg1, *arg2))
>             return -1;
>         return 1;
>     }
>     return 0;
> }
> 
> IIUC, if can cast (arg1, arg2), we never compare other args, just return
> -1.
> 
> Shouldn't this be:
> cmp_arg_types(int *arg1, int *arg2, int n)
> {
>     while (n--) {
>         if (PyArray_EquivTypenums(*arg1, *arg2) or
>            (PyArray_CanCastSafely(*arg1, *arg2))
>             continue;
>         return 1;
>     }
>     return 0;
> }

Oh, better make that:
static int
cmp_arg_types(int *arg1, int *arg2, int n)
{
    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