@@ -86,6 +86,11 @@ def prod(values: Iterable[SupportsFloatOrInt]) -> SupportsFloatOrInt:
8686################################
8787# General math
8888################################
89+ def _math_isclose (a , b , rel_tol = 1e-9 , abs_tol = 0.0 ):
90+ """Test if values are close."""
91+
92+ return abs (a - b ) <= max (rel_tol * max (abs (a ), abs (b )), abs_tol )
93+
8994@deprecated ("Please use math.isnan or alg.isnan for a generic approach for vectors and matrices" )
9095def is_nan (obj : float ) -> bool :
9196 """Check if "not a number"."""
@@ -550,20 +555,20 @@ def monotone(p0: float, p1: float, p2: float, p3: float, t: float) -> float:
550555 m2 = (s1 + s2 ) * 0.5
551556
552557 # Center segment should be horizontal as there is no increase/decrease between the two points
553- if math . isclose (p1 , p2 ):
558+ if _math_isclose (p1 , p2 ):
554559 m1 = m2 = 0.0
555560 else :
556561
557562 # Gradient is zero if segment is horizontal or if the left hand secant differs in sign from current.
558- if math . isclose (p0 , p1 ) or (math .copysign (1.0 , s0 ) != math .copysign (1.0 , s1 )):
563+ if _math_isclose (p0 , p1 ) or (math .copysign (1.0 , s0 ) != math .copysign (1.0 , s1 )):
559564 m1 = 0.0
560565
561566 # Ensure gradient magnitude is either 3 times the left or current secant (smaller being preferred).
562567 else :
563568 m1 *= min (3.0 * s0 / m1 , min (3.0 * s1 / m1 , 1.0 ))
564569
565570 # Gradient is zero if segment is horizontal or if the right hand secant differs in sign from current.
566- if math . isclose (p2 , p3 ) or (math .copysign (1.0 , s1 ) != math .copysign (1.0 , s2 )):
571+ if _math_isclose (p2 , p3 ) or (math .copysign (1.0 , s1 ) != math .copysign (1.0 , s2 )):
567572 m2 = 0.0
568573
569574 # Ensure gradient magnitude is either 3 times the current or right secant (smaller being preferred).
@@ -1773,7 +1778,7 @@ def linspace(start: Union[ArrayLike, float], stop: Union[ArrayLike, float], num:
17731778def _isclose (a : float , b : float , * , equal_nan : bool = False , ** kwargs : Any ) -> bool :
17741779 """Check if values are close."""
17751780
1776- close = math . isclose (a , b , ** kwargs )
1781+ close = _math_isclose (a , b , ** kwargs )
17771782 return (math .isnan (a ) and math .isnan (b )) if not close and equal_nan else close
17781783
17791784
0 commit comments