MCPcopy Create free account
hub / github.com/numpy/numpy / compare

Function compare

numpy/testing/_private/utils.py:1008–1032  ·  view source on GitHub ↗
(x, y)

Source from the content-addressed store, hash-verified

1006 from numpy.core.fromnumeric import any as npany
1007
1008 def compare(x, y):
1009 try:
1010 if npany(isinf(x)) or npany(isinf(y)):
1011 xinfid = isinf(x)
1012 yinfid = isinf(y)
1013 if not (xinfid == yinfid).all():
1014 return False
1015 # if one item, x and y is +- inf
1016 if x.size == y.size == 1:
1017 return x == y
1018 x = x[~xinfid]
1019 y = y[~yinfid]
1020 except (TypeError, NotImplementedError):
1021 pass
1022
1023 # make sure y is an inexact type to avoid abs(MIN_INT); will cause
1024 # casting of x later.
1025 dtype = result_type(y, 1.)
1026 y = np.asanyarray(y, dtype)
1027 z = abs(x - y)
1028
1029 if not issubdtype(z.dtype, number):
1030 z = z.astype(float_) # handle object arrays
1031
1032 return z < 1.5 * 10.0**(-decimal)
1033
1034 assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
1035 header=('Arrays are not almost equal to %d decimals' % decimal),

Callers

nothing calls this directly

Calls 6

isinfFunction · 0.90
result_typeFunction · 0.90
issubdtypeFunction · 0.90
absFunction · 0.85
astypeMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected