def isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False):
 diff = abs((a - b))
 tolerance = (atol + (rtol * abs(b)))
 close_prelim = le(diff, tolerance)
 a_nan = isnan(a)
 b_nan = isnan(b)
 nans = bitwise_or(a_nan, b_nan)
 a_inf = isinf(a)
 b_inf = isinf(b)
 infs = bitwise_or(a_inf, b_inf)
 nans_or_infs = bitwise_or(nans, infs)
 close = bitwise_and(close_prelim, bitwise_not(nans_or_infs))
 both_infs = bitwise_and(a_inf, b_inf)
 inf_signs_eq = eq((a_inf * sgn(a)), (b_inf * sgn(b)))
 inf_eq = bitwise_and(both_infs, inf_signs_eq)
 close_with_infs = bitwise_or(close, inf_eq)
 if equal_nan:
  both_nans = bitwise_and(a_nan, b_nan)
  return bitwise_or(close_with_infs, both_nans)
 else:
  return close_with_infs

def isclose ( a , b , rtol = 1e-05 , atol = 1e-08 , equal_nan = False ) : diff = abs ( ( a - b ) ) tolerance = ( atol + ( rtol * abs ( b ) ) ) close_prelim = le ( diff , tolerance ) a_nan = isnan ( a ) b_nan = isnan ( b ) nans = bitwise_or ( a_nan , b_nan ) a_inf = isinf ( a ) b_inf = isinf ( b ) infs = bitwise_or ( a_inf , b_inf ) nans_or_infs = bitwise_or ( nans , infs ) close = bitwise_and ( close_prelim , bitwise_not ( nans_or_infs ) ) both_infs = bitwise_and ( a_inf , b_inf ) inf_signs_eq = eq ( ( a_inf * sgn ( a ) ) , ( b_inf * sgn ( b ) ) ) inf_eq = bitwise_and ( both_infs , inf_signs_eq ) close_with_infs = bitwise_or ( close , inf_eq ) if equal_nan : both_nans = bitwise_and ( a_nan , b_nan ) return bitwise_or ( close_with_infs , both_nans ) else : return close_with_infs
implements numpys isclose on tensors .