
    i[z                    |   S SK Jr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SK	r	S SK
Jr  S SKrS SKrS S	KJr  S S
KJr  \(       a  S SKJr                SS jr " S S5      rS r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rSS S jjrS!S jrS"S jrS#S jrg)$    )annotations)
Collection)Mapping)Sequence)Sized)DecimalN)Complex)Any)TYPE_CHECKING)ndarrayc                   [        U5      nUR                  SS5        / SQnU HW  u  pn
[        US   [        U5      5      US'   [        US   [        U	5      5      US'   [        US   [        U
5      5      US'   MY     S[        U5       SU S3S	U 3S
U 3/U VV	V
s/ s H%  u  pn
USUS    3 SU	SUS    3 SU
SUS    3 3PM'     sn
n	n-   nU$ s  sn
n	nf )Nr   )IndexObtainedExpected)r   r   r         z(comparison failed. Mismatched elements: z / :zMax absolute difference: zMax relative difference: <z | )listinsertmaxlen)full_objectmessage_datanumber_of_elementsdifferent_idsmax_abs_diffmax_rel_diffmessage_list	max_sizesindexobtainedexpectedindexesexplanations                Q/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/_pytest/python_api.py_compare_approxr'      s#    %L<=I%1!9Q<U4	!9Q<X7	!9Q<X7	! &2
 33}3E2FcJ\I]]^_
#L>2
#L>2 ,8	+7'Gx 1Yq\N"
#3x)A,/?&@HQyYZ|nL\C]^+7		K 		s   ,C
c                  z    \ rS rSrSrSrSrSSS jjrSS jrSS jr	SS jr
S	 rSrSS
 jrSS jrS rSS jrSrg)
ApproxBase2   zdProvide shared utilities for making approximate comparisons between
numbers or sequences of numbers.Nd   c                X    SnXl         X0l        X l        X@l        U R	                  5         g )NT)r#   absrelnan_ok_check_type)selfr#   r.   r-   r/   __tracebackhide__s         r&   __init__ApproxBase.__init__:   s(          c                    [         eNNotImplementedErrorr1   s    r&   __repr__ApproxBase.__repr__B   s    !!r5   c                    SSU 3SU  3/$ )Nzcomparison failedz
Obtained: z
Expected:  )r1   
other_sides     r&   _repr_compareApproxBase._repr_compareE   s#    %
 	
r5   c                L   ^  [        U 4S jT R                  U5       5       5      $ )Nc              3  P   >#    U  H  u  pUTR                  U5      :H  v   M     g 7fr7   _approx_scalar).0axr1   s      r&   	<genexpr>$ApproxBase.__eq__.<locals>.<genexpr>M   s'      
4SDAA$$Q''4Ss   #&)all_yield_comparisonsr1   actuals   ` r&   __eq__ApproxBase.__eq__L   s(     
484K4KF4S
 
 	
r5   c                    Sn[        S5      e)NTzVapprox() is not supported in a boolean context.
Did you mean: `assert a == approx(b)`?)AssertionError)r1   r2   s     r&   __bool__ApproxBase.__bool__Q   s     e
 	
r5   c                    X:X  + $ r7   r>   rM   s     r&   __ne__ApproxBase.__ne__Z   s    ##r5   c                    [        U[        5      (       a)  [        XR                  U R                  U R
                  S9$ [        XR                  U R                  U R
                  S9$ )N)r.   r-   r/   )
isinstancer   ApproxDecimalr.   r-   r/   ApproxScalar)r1   rH   s     r&   rE   ApproxBase._approx_scalar]   sE    a!! dhht{{SSA88$++NNr5   c                    [         e)z_Yield all the pairs of numbers to be compared.

This is used to implement the `__eq__` method.
r8   rM   s     r&   rL   ApproxBase._yield_comparisonsb   s
    
 "!r5   c                    g)z<Raise a TypeError if the expected value is not a valid type.Nr>   r:   s    r&   r0   ApproxBase._check_typei   s    r5   )r-   r#   r/   r.   NNF)r/   boolreturnNonerc   str)r?   r
   rc   	list[str]rc   rb   )rc   r[   rc   rd   )__name__
__module____qualname____firstlineno____doc____array_ufunc____array_priority__r3   r;   r@   rO   rS   __hash__rV   rE   rL   r0   __static_attributes__r>   r5   r&   r)   r)   2   sJ    ( O"



 H$O
"Kr5   r)   c                   ^  [        U[        [        45      (       a  [        U5      nU" U 4S jU 5       5      $ [	        U5      (       a  U Vs/ s H  n[        T U5      PM     sn$ T " U5      $ s  snf )z=Recursively map a function over a sequence of arbitrary depthc              3  <   >#    U  H  n[        TU5      v   M     g 7fr7   )_recursive_sequence_map)rF   xifs     r&   rI   *_recursive_sequence_map.<locals>.<genexpr>v   s     C2/266s   )rY   r   tupletype_is_sequence_likeru   )rw   rH   seq_typerv   s   `   r&   ru   ru   r   sd    !dE]##7CCCC	1		9:;2'2.;;t <s   A/c                  J   ^  \ rS rSrSrSS jrS	S jrS
U 4S jjrS rSr	U =r
$ )ApproxNumpy}   zHPerform approximate comparisons where the expected value is numpy array.c                l    [        U R                  U R                  R                  5       5      nSU< S3$ Napprox())ru   rE   r#   tolist)r1   list_scalarss     r&   r;   ApproxNumpy.__repr__   s6    .!5!5!7
 (**r5   c                T   SS K nSS Kn      SS jnU R                  R                  n[	        U R
                  U R                  R                  5       5      n[        U5      nUc   eXWR                  :w  a  SSU SUR                   3/$ U R                  R                  nUR                  * n	UR                  * n
/ nUR                  " S U 5       6  Hx  nU" Xl5      nU" X|5      nX:w  d  M  [        UR                  U-
  5      n[        X5      n	US:X  a  UR                  n
O[        X[        U5      -  5      n
UR                  U5        Mz     U Vs/ s H/  n[        U5      [        U" X|5      5      [        U" Xl5      5      4PM1     nn[        U R                  UUUU	U
5      $ s  snf )	Nr   c                $    U nU H  nX#   nM	     U$ )z
Helper function to get the value out of a nested list, given an n-dimensional index.
This mimics numpy's indexing, but for raw nested python lists.
r>   )nested_listnd_indexvalueis       r&   get_value_from_nested_list=ApproxNumpy._repr_compare.<locals>.get_value_from_nested_list   s     %E Lr5   z3Impossible to compare arrays with different shapes.zShapes:  and c              3  8   #    U  H  n[        U5      v   M     g 7fr7   )range)rF   r   s     r&   rI   ,ApproxNumpy._repr_compare.<locals>.<genexpr>   s     (J>aq>s           )r   z	list[Any]r   ztuple[Any, ...]rc   r
   )	itertoolsmathr#   shaperu   rE   r   _as_numpy_arraysizeinfproductr-   r   appendrf   r'   )r1   r?   r   r   r   np_array_shapeapprox_side_as_seqother_side_as_arrayr   r   r   r   r!   approx_valueother_valueabs_diffr   s                    r&   r@   ApproxNumpy._repr_compare   s   
	"
	.=
	
	 ,,4!5!5!7

 .j9"...666E>*%0C0I0I/JK 
 "]]//yy&&(J>(JKE56HPL45HPK*|44{BC"<:#%#'88L#&|K@P5P#QL$$U+ L$ '
 '	 E
./BJK./AIJ
 ' 	 
 MM
 	

s   6F%c                4  > SS K nUR                  U5      (       d   UR                  U5      nUR                  U5      (       d%  UR
                  U R                  R
                  :w  a  g[        TU ]!  U5      $ ! [         a  n[	        SU S35      UeS nAff = f)Nr   zcannot compare 'z' to numpy.ndarrayF)	numpyisscalarasarray	Exception	TypeErrorr   r#   superrO   )r1   rN   npe	__class__s       r&   rO   ApproxNumpy.__eq__   s     {{6""VF+ {{6""v||t}}7J7J'Jw~f%%  V"26(:L MNTUUVs   A8 8
BBBc              #    #    SS K nUR                  U5      (       aM  UR                  U R                  R                  5       H#  nXR                  U   R                  5       4v   M%     g UR                  U R                  R                  5       H4  nX   R                  5       U R                  U   R                  5       4v   M6     g 7f)Nr   )r   r   ndindexr#   r   item)r1   rN   r   r   s       r&   rL   ApproxNumpy._yield_comparisons   s      ;;vZZ 3 34mmA.33555 5 ZZ 3 34inn&a(8(=(=(??? 5s   CCr>   re   )r?   zndarray | list[Any]rc   rg   rh   )rj   rk   rl   rm   rn   r;   r@   rO   rL   rr   __classcell__r   s   @r&   r~   r~   }   s"    R+>
@& @ @r5   r~   c                  T   ^  \ rS rSrSrS	S jrS
S jrSU 4S jjrS rSS jr	Sr
U =r$ )ApproxMapping   zuPerform approximate comparisons where the expected value is a mapping
with numeric values (the keys can be anything).c           	         SU R                   R                  5        VVs0 s H  u  pXR                  U5      _M     snn< S3$ s  snnf r   )r#   itemsrE   )r1   kvs      r&   r;   ApproxMapping.__repr__   sD    $--BUBUBWXBW$!A22155BWX\\]^^Xs   Ac           	     <   SS K nU R                  R                  5        VVs0 s H  u  p4X0R                  U5      _M     nnn[	        U5      nUR
                  * nUR
                  * n/ n	[        UR                  5       UR                  5       5       H  u  u  pnX:w  d  M  UR                  bs  Ubp   [        U[        UR                  U-
  5      5      nUR                  S:X  a  UR
                  nO0[        U[        UR                  U-
  UR                  -  5      5      n U	R                  U
5        M     U	 Vs/ s H'  n[        U5      [        X   5      [        X]   5      4PM)     nn[        U R                  UUU	UU5      $ s  snnf ! [         a     Nuf = fs  snf )Nr   r   )r   r#   r   rE   r   r   zipvaluesr   r-   ZeroDivisionErrorr   rf   r'   )r1   r?   r   r   r   approx_side_as_mapr   r   r   r   
approx_keyr   r   keyr   s                  r&   r@   ApproxMapping._repr_compare   s    37--2E2E2G
2G$!A""1%%2G 	 
 !!34yy7:$$&
(9(9(;8
3&Z *((49P'*(#l.C.Ck.Q*R( (00C7+/88L+. , #%1%:%:[%H&2&;&;%<!",L $$Z0+8
2 %
$ Xs:?+S1C1H-IJ$ 	 

 MM
 	
I
6 - 
s#   F1>F	0/F	9.F	
FFc                   >  [        UR                  5       5      [        U R                  R                  5       5      :w  a  g [        TU ]  U5      $ ! [         a     gf = fNF)setkeysr#   AttributeErrorr   rO   r1   rN   r   s     r&   rO   ApproxMapping.__eq__  sZ    	6;;=!S););)=%>> ?
 w~f%%  		s   >A 
AAc              #  x   #    U R                   R                  5        H  nX   U R                   U   4v   M     g 7fr7   )r#   r   )r1   rN   r   s      r&   rL    ApproxMapping._yield_comparisons%  s2     ##%A)T]]1--- &s   8:c           
        SnU R                   R                  5        Hd  u  p#[        U[        U R                   5      5      (       d  M+  Sn[	        UR                  X#[        R                  " U R                   5      5      5      e   g )NTz[pytest.approx() does not support nested dictionaries: key={!r} value={!r}
  full mapping={})r#   r   rY   rz   r   formatpprintpformat)r1   r2   r   r   msgs        r&   r0   ApproxMapping._check_type)  s_     ----/JC%dmm!455t

3v~~dmm7T UVV 0r5   r>   re   )r?   zMapping[object, float]rc   rg   rh   ri   rj   rk   rl   rm   rn   r;   r@   rO   rL   r0   rr   r   r   s   @r&   r   r      s*    7_.
`&.W Wr5   r   c                  T   ^  \ rS rSrSrS	S jrS
S jrSU 4S jjrS rSS jr	Sr
U =r$ )ApproxSequenceLikei1  zRPerform approximate comparisons where the expected value is a sequence of numbers.c                   ^  [        T R                  5      nU[        [        4;  a  [        nSU" U 4S jT R                   5       5      < S3$ )Nr   c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr7   rD   )rF   rH   r1   s     r&   rI   .ApproxSequenceLike.__repr__.<locals>.<genexpr>8  s     !P-Q$"5"5a"8"8-   !r   )rz   r#   ry   r   )r1   r|   s   ` r&   r;   ApproxSequenceLike.__repr__4  sB    &E4=(H!P$--!PPSSTUUr5   c           	        SS K n[        U R                  5      [        U5      :w  a&  SS[        U R                  5       S[        U5       3/$ [        U R                  U R                  5      n[        U5      nUR
                  * nUR
                  * n/ n[        [        X15      5       Ho  u  nu  pX:w  d  M   [        U	R                  U
-
  5      n[        X[5      nU
S:X  a  UR
                  nO[        Xk[        U
5      -  5      n UR                  U5        Mq     U Vs/ s H'  n[        U5      [        X   5      [        X8   5      4PM)     nn[        U R                  UUUUU5      $ ! [         a     Nof = fs  snf )Nr   z1Impossible to compare lists with different sizes.z	Lengths: r   r   )r   r   r#   ru   rE   r   	enumerater   r-   r   r   r   rf   r'   )r1   r?   r   r   r   r   r   r   r   r   r   r   r   s                r&   r@    ApproxSequenceLike._repr_compare:  s   t}}Z0CC./uS_4EF 
 5T5H5H$--X !34yy.7"//
*A* *
V"<#8#8;#FGH#&|#>L
 #c)'+xx'*<CDT9T'U$$Q'/
$ #
" VS'-?-B)CD" 	 

 MM
 	
 ! 
s   8#E).E9)
E65E6c                   >  [        U5      [        U R                  5      :w  a  g [        TU ]  U5      $ ! [         a     gf = fr   )r   r#   r   r   rO   r   s     r&   rO   ApproxSequenceLike.__eq__g  sJ    	6{c$--00 1 w~f%%  		s   "6 
AAc                ,    [        XR                  5      $ r7   )r   r#   rM   s     r&   rL   %ApproxSequenceLike._yield_comparisonso  s    6==))r5   c           
        Sn[        U R                  5       Hd  u  p#[        U[        U R                  5      5      (       d  M+  Sn[	        UR                  X2[        R                  " U R                  5      5      5      e   g )NTz]pytest.approx() does not support nested data structures: {!r} at index {}
  full sequence: {})r   r#   rY   rz   r   r   r   r   )r1   r2   r!   rH   r   s        r&   r0   ApproxSequenceLike._check_typer  s[     !$--0HE!T$--011v

1V^^DMM5R STT 1r5   r>   re   )r?   zSequence[float]rc   rg   rh   ri   r   r   s   @r&   r   r   1  s(    \V+
Z&*U Ur5   r   c                  ^    \ rS rSr% SrSrS\S'   SrS\S'   SS jrSS	 jr	S
r
\S 5       rSrg
)r[   iz  zLPerform approximate comparisons where the expected value is a single number.g-q=zfloat | DecimalDEFAULT_ABSOLUTE_TOLERANCEgư>DEFAULT_RELATIVE_TOLERANCEc                   [        U R                  [        5      (       dt  [        U R                  [        [        45      (       aO  [
        R                  " [        U R                  5      =(       d    [        U R                  [        5      5      (       a  [        U R                  5      $  SU R                  s=::  a  S:  a  O  OU R                  S nOU R                  S n[        U R                  [        5      (       aE  U R                  R                  (       a*  [
        R                  " U R                  5      (       d  US-  nU R                   SU 3$ ! [         a    Sn Nf = f)u   Return a string communicating both the expected value and the
tolerance for the comparison being made.

For example, ``1.0 ± 1e-6``, ``(3+4j) ± 5e-6 ∠ ±180°``.
gMbP?g     @@n.1eu    ∠ ±180°???    ± )rY   r#   rb   r	   r   r   isinfr-   rf   	toleranceimag
ValueError)r1   vetted_tolerances     r&   r;   ApproxScalar.__repr__  s    t}}d++t}}w.@AAzz#dmm,O
4==$0OPPt}}%%	%t~~++&*nnQ%7 &*nnS%9  4=='22MM&&

4>>22 N2  --%5$677  	%$	%s   *BE E%$E%c                  ^  SS jn[        U5      nUb  [        U 4S jUR                   5       5      $ U" T R                  5      (       a  U" U5      (       d  gUT R                  :X  a  gU" T R                  5      (       d@  [	        T R                  [
        [        45      (       a  [	        U[
        [        45      (       d  g[        R                  " [        T R                  5      5      (       a2  T R                  =(       a    [        R                  " [        U5      5      $ [        R                  " [        T R                  5      5      (       a  g[        T R                  U-
  5      T R                  :*  nU$ )zaReturn whether the given value is equal to the expected value
within the pre-specified tolerance.c                    [        U [        5      (       a  g[        R                  R	                  S5      =n(       a  [        XR
                  5      $ g)NTr   F)rY   rb   sysmodulesgetbool_)valr   s     r&   is_bool$ApproxScalar.__eq__.<locals>.is_bool  s<    #t$$[[__W--r-!#xx00r5   c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr7   )rO   )rF   rG   r1   s     r&   rI   &ApproxScalar.__eq__.<locals>.<genexpr>  s     <|!t{{1~~|r   FT)r   r
   rc   rb   )r   rK   flatr#   rY   r	   r   r   isnanr-   r/   r   r   )r1   rN   r   r   results   `    r&   rO   ApproxScalar.__eq__  s   	 "&) <w||<<< 4==!!'&//t}}$ 4==!!t}}w&8996GW#566
 ::c$--());;:4::c&k#:: ::c$--()) 4==612dnnDr5   Nc                   S nU" U R                   U R                  5      nUS:  a  [        SU 35      e[        R                  " U5      (       a  [        S5      eU R
                  c  U R                   b  U$ U" U R
                  U R                  5      [        U R                  5      -  nUS:  a  [        SU 35      e[        R                  " U5      (       a  [        S5      e[        X25      $ )zReturn the tolerance for the comparison.

This could be either an absolute tolerance or a relative tolerance,
depending on what the user specified or which would be larger.
c                    U b  U $ U$ r7   r>   )rH   defaults     r&   set_default+ApproxScalar.tolerance.<locals>.set_default  s    1272r5   r   z&absolute tolerance can't be negative: z absolute tolerance can't be NaN.z&relative tolerance can't be negative: z relative tolerance can't be NaN.)	r-   r   r   r   r   r.   r   r#   r   )r1   r  absolute_tolerancerelative_tolerances       r&   r   ApproxScalar.tolerance  s    	3
 )43R3RS!89K8LM  ::())?@@ 88xx#)) )HHd55
 !89K8LM  ::())?@@ %::r5   r>   re   rh   )rj   rk   rl   rm   rn   r   __annotations__r   r;   rO   rq   propertyr   rr   r>   r5   r&   r[   r[   z  sB    V 387266!8F3l H,; ,;r5   r[   c                  B    \ rS rSrSr\" S5      r\" S5      rSS jrSr	g)	rZ   i  zFPerform approximate comparisons where the expected value is a Decimal.z1e-12z1e-6c                   [        U R                  [        5      (       a!  [        R                  " U R                  5      nOU R                  n[        U R
                  [        5      (       a!  [        R                  " U R
                  5      nOU R
                  nSnUb'  [        S5      Us=::  a  [        S5      ::  a  O  OUS nOUb  US nU R                   SU 3$ )Nr   z1e-31e3r   r   )rY   r.   floatr   
from_floatr-   r#   )r1   r.   abs_tol_strs       r&   r;   ApproxDecimal.__repr__  s    dhh&&$$TXX.C((Cdhh&&%%dhh/D88D?wv#GGS	Gc
G--WI..r5   r>   Nre   )
rj   rk   rl   rm   rn   r   r   r   r;   rr   r>   r5   r&   rZ   rZ     s    P!(!1!(/r5   rZ   c                   Sn[        U [        5      (       a  [        nO[        U [        5      (       a  [        nO[        U 5      (       a  [        U 5      n [        nO^[        U 5      (       a  [        nOG[        U [        5      (       a,  [        U [        [        45      (       d  SU < 3n[        U5      e[        nU" XX#5      $ )ap  Assert that two numbers (or two ordered sequences of numbers) are equal to each other
within some tolerance.

Due to the :doc:`python:tutorial/floatingpoint`, numbers that we
would intuitively expect to be equal are not always so::

    >>> 0.1 + 0.2 == 0.3
    False

This problem is commonly encountered when writing tests, e.g. when making
sure that floating-point values are what you expect them to be.  One way to
deal with this problem is to assert that two floating-point numbers are
equal to within some appropriate tolerance::

    >>> abs((0.1 + 0.2) - 0.3) < 1e-6
    True

However, comparisons like this are tedious to write and difficult to
understand.  Furthermore, absolute comparisons like the one above are
usually discouraged because there's no tolerance that works well for all
situations.  ``1e-6`` is good for numbers around ``1``, but too small for
very big numbers and too big for very small ones.  It's better to express
the tolerance as a fraction of the expected value, but relative comparisons
like that are even more difficult to write correctly and concisely.

The ``approx`` class performs floating-point comparisons using a syntax
that's as intuitive as possible::

    >>> from pytest import approx
    >>> 0.1 + 0.2 == approx(0.3)
    True

The same syntax also works for ordered sequences of numbers::

    >>> (0.1 + 0.2, 0.2 + 0.4) == approx((0.3, 0.6))
    True

``numpy`` arrays::

    >>> import numpy as np                                                          # doctest: +SKIP
    >>> np.array([0.1, 0.2]) + np.array([0.2, 0.4]) == approx(np.array([0.3, 0.6])) # doctest: +SKIP
    True

And for a ``numpy`` array against a scalar::

    >>> import numpy as np                                         # doctest: +SKIP
    >>> np.array([0.1, 0.2]) + np.array([0.2, 0.1]) == approx(0.3) # doctest: +SKIP
    True

Only ordered sequences are supported, because ``approx`` needs
to infer the relative position of the sequences without ambiguity. This means
``sets`` and other unordered sequences are not supported.

Finally, dictionary *values* can also be compared::

    >>> {'a': 0.1 + 0.2, 'b': 0.2 + 0.4} == approx({'a': 0.3, 'b': 0.6})
    True

The comparison will be true if both mappings have the same keys and their
respective values match the expected tolerances.

**Tolerances**

By default, ``approx`` considers numbers within a relative tolerance of
``1e-6`` (i.e. one part in a million) of its expected value to be equal.
This treatment would lead to surprising results if the expected value was
``0.0``, because nothing but ``0.0`` itself is relatively close to ``0.0``.
To handle this case less surprisingly, ``approx`` also considers numbers
within an absolute tolerance of ``1e-12`` of its expected value to be
equal.  Infinity and NaN are special cases.  Infinity is only considered
equal to itself, regardless of the relative tolerance.  NaN is not
considered equal to anything by default, but you can make it be equal to
itself by setting the ``nan_ok`` argument to True.  (This is meant to
facilitate comparing arrays that use NaN to mean "no data".)

Both the relative and absolute tolerances can be changed by passing
arguments to the ``approx`` constructor::

    >>> 1.0001 == approx(1)
    False
    >>> 1.0001 == approx(1, rel=1e-3)
    True
    >>> 1.0001 == approx(1, abs=1e-3)
    True

If you specify ``abs`` but not ``rel``, the comparison will not consider
the relative tolerance at all.  In other words, two numbers that are within
the default relative tolerance of ``1e-6`` will still be considered unequal
if they exceed the specified absolute tolerance.  If you specify both
``abs`` and ``rel``, the numbers will be considered equal if either
tolerance is met::

    >>> 1 + 1e-8 == approx(1)
    True
    >>> 1 + 1e-8 == approx(1, abs=1e-12)
    False
    >>> 1 + 1e-8 == approx(1, rel=1e-6, abs=1e-12)
    True

**Non-numeric types**

You can also use ``approx`` to compare non-numeric types, or dicts and
sequences containing non-numeric types, in which case it falls back to
strict equality. This can be useful for comparing dicts and sequences that
can contain optional values::

    >>> {"required": 1.0000005, "optional": None} == approx({"required": 1, "optional": None})
    True
    >>> [None, 1.0000005] == approx([None,1])
    True
    >>> ["foo", 1.0000005] == approx([None,1])
    False

If you're thinking about using ``approx``, then you might want to know how
it compares to other good ways of comparing floating-point numbers.  All of
these algorithms are based on relative and absolute tolerances and should
agree for the most part, but they do have meaningful differences:

- ``math.isclose(a, b, rel_tol=1e-9, abs_tol=0.0)``:  True if the relative
  tolerance is met w.r.t. either ``a`` or ``b`` or if the absolute
  tolerance is met.  Because the relative tolerance is calculated w.r.t.
  both ``a`` and ``b``, this test is symmetric (i.e.  neither ``a`` nor
  ``b`` is a "reference value").  You have to specify an absolute tolerance
  if you want to compare to ``0.0`` because there is no tolerance by
  default.  More information: :py:func:`math.isclose`.

- ``numpy.isclose(a, b, rtol=1e-5, atol=1e-8)``: True if the difference
  between ``a`` and ``b`` is less that the sum of the relative tolerance
  w.r.t. ``b`` and the absolute tolerance.  Because the relative tolerance
  is only calculated w.r.t. ``b``, this test is asymmetric and you can
  think of ``b`` as the reference value.  Support for comparing sequences
  is provided by :py:func:`numpy.allclose`.  More information:
  :std:doc:`numpy:reference/generated/numpy.isclose`.

- ``unittest.TestCase.assertAlmostEqual(a, b)``: True if ``a`` and ``b``
  are within an absolute tolerance of ``1e-7``.  No relative tolerance is
  considered , so this function is not appropriate for very large or very
  small numbers.  Also, it's only available in subclasses of ``unittest.TestCase``
  and it's ugly because it doesn't follow PEP8.  More information:
  :py:meth:`unittest.TestCase.assertAlmostEqual`.

- ``a == pytest.approx(b, rel=1e-6, abs=1e-12)``: True if the relative
  tolerance is met w.r.t. ``b`` or if the absolute tolerance is met.
  Because the relative tolerance is only calculated w.r.t. ``b``, this test
  is asymmetric and you can think of ``b`` as the reference value.  In the
  special case that you explicitly specify an absolute tolerance but not a
  relative tolerance, only the absolute tolerance is considered.

.. note::

    ``approx`` can handle numpy arrays, but we recommend the
    specialised test helpers in :std:doc:`numpy:reference/routines.testing`
    if you need support for comparisons, NaNs, or ULP-based tolerances.

    To match strings using regex, you can use
    `Matches <https://github.com/asottile/re-assert#re_assertmatchespattern-str-args-kwargs>`_
    from the
    `re_assert package <https://github.com/asottile/re-assert>`_.


.. note::

    Unlike built-in equality, this function considers
    booleans unequal to numeric zero or one. For example::

       >>> 1 == approx(True)
       False

.. warning::

   .. versionchanged:: 3.2

   In order to avoid inconsistent behavior, :py:exc:`TypeError` is
   raised for ``>``, ``>=``, ``<`` and ``<=`` comparisons.
   The example below illustrates the problem::

       assert approx(0.1) > 0.1 + 1e-10  # calls approx(0.1).__gt__(0.1 + 1e-10)
       assert 0.1 + 1e-10 > approx(0.1)  # calls approx(0.1).__lt__(0.1 + 1e-10)

   In the second example one expects ``approx(0.1).__le__(0.1 + 1e-10)``
   to be called. But instead, ``approx(0.1).__lt__(0.1 + 1e-10)`` is used to
   comparison. This is because the call hierarchy of rich comparisons
   follows a fixed behavior. More information: :py:meth:`object.__ge__`

.. versionchanged:: 3.7.1
   ``approx`` raises ``TypeError`` when it encounters a dict value or
   sequence element of non-numeric type.

.. versionchanged:: 6.1.0
   ``approx`` falls back to strict equality for non-numeric types instead
   of raising ``TypeError``.
Tz:pytest.approx() only supports ordered sequences, but got: )rY   r   rZ   r   r   _is_numpy_arrayr   r~   r{   r   r   rf   bytesr   r[   )r#   r.   r-   r/   r2   clsr   s          r&   approxr  '  s    ` (G$$ -	Hg	&	&		"	""8,	8	$	$ 	Hj	)	)*XU|2T2TJ8,Wnxc**r5   c                    [        U S5      =(       a2    [        U [        5      =(       a    [        U [        [        45      (       + $ )N__getitem__)hasattrrY   r   rf   r  )r#   s    r&   r{   r{     s6    -( 	3x'	38c5\22r5   c                    [        U 5      SL$ )zf
Return true if the given object is implicitly convertible to ndarray,
and numpy is already imported.
N)r   )objs    r&   r  r    s    
 3t++r5   c                   [         R                  R                  S5      nUbf  UR                  U 5      (       a  g[	        XR
                  5      (       a  U $ [        U S5      (       d  [        SS5      (       a  UR                  U 5      $ g)z|
Return an ndarray if the given object is implicitly convertible to ndarray,
and numpy is already imported, otherwise None.
r   N	__array__r  __array_interface__)r   r   r   r   rY   r   r  r   )r  r   s     r&   r   r     sl    
 kkoog&B	~;;sZZ((JS+&&'%9N*O*O::c?"r5   )r   objectr   zSequence[tuple[str, str, str]]r   intr   zSequence[object]r   r  r   r  rc   rg   ra   )r/   rb   rc   r)   )r#   r   rc   rb   )r  r   rc   rb   )r  r   rc   zndarray | None)
__future__r   collections.abcr   r   r   r   decimalr   r   numbersr	   r   r   typingr
   r   r   r   r'   r)   ru   r~   r   r   r[   rZ   r  r{   r  r   r>   r5   r&   <module>r'     s    " & # $ !     
    0  $	
   :8K 8K@e@* e@PIWJ IWXFU FURP;: P;f/L /4a+H,r5   