Ejemplo n.º 1
0
    def compare(x, y):
        from numpy.core import number, float_, result_type, array
        from numpy.core.numerictypes import issubdtype
        from numpy.core.fromnumeric import any as npany

        try:
            if npany(gisinf(x)) or npany(gisinf(y)):
                xinfid = gisinf(x)
                yinfid = gisinf(y)
                if not (xinfid == yinfid).all():
                    return False
                # if one item, x and y is +- inf
                if x.size == y.size == 1:
                    return x == y
                x = x[~xinfid]
                y = y[~yinfid]
        except (TypeError, NotImplementedError):
            pass

        # make sure y is an inexact type to avoid abs(MIN_INT); will cause
        # casting of x later.
        dtype = result_type(y, 1.)
        y = array(y, dtype=dtype, copy=False, subok=True)
        z = abs(x - y)

        if not issubdtype(z.dtype, number):
            z = z.astype(float_)  # handle object arrays

        return z < 1.5 * 10.0**(-decimal)
Ejemplo n.º 2
0
 def compare(x, y):
     try:
         if npany(gisinf(x)) or npany( gisinf(y)):
             xinfid = gisinf(x)
             yinfid = gisinf(y)
             if not xinfid == yinfid:
                 return False
             # if one item, x and y is +- inf
             if x.size == y.size == 1:
                 return x == y
             x = x[~xinfid]
             y = y[~yinfid]
     except (TypeError, NotImplementedError):
         pass
     z = abs(x-y)
     if not issubdtype(z.dtype, number):
         z = z.astype(float_) # handle object arrays
     return around(z, decimal) <= 10.0**(-decimal)
Ejemplo n.º 3
0
 def compare(x, y):
     try:
         if npany(gisinf(x)) or npany( gisinf(y)):
             xinfid = gisinf(x)
             yinfid = gisinf(y)
             if not xinfid == yinfid:
                 return False
             # if one item, x and y is +- inf
             if x.size == y.size == 1:
                 return x == y
             x = x[~xinfid]
             y = y[~yinfid]
     except TypeError:
         pass
     z = abs(x-y)
     if not issubdtype(z.dtype, number):
         z = z.astype(float_) # handle object arrays
     return around(z, decimal) <= 10.0**(-decimal)