
    H/Ph (                        d Z ddlZddlZddlmZ ddlmc mZ ddlZddlm	Z	m
Z
mZmZmZ ddlmZmZmZmZmZmZ g dZddlmZ g d	Zeez   ZddZddZd dZd Zd dZd dZeZ d!dZ!e!Z"	 	 d"dZ#d#dZ$d#dZ%d$dZ&d$dZ'd#dZ(d dZ)dS )%zMiscellaneous functions for testing masked arrays and subclasses

:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu
:version: $Id: testutils.py 3529 2007-11-13 08:01:14Z jarrod.millman $

    N)ndarray)assert_assert_allcloseassert_array_almost_equal_nulpassert_raisesbuild_err_msg   )mask_orgetmaskmasked_arraynomaskmaskedfilled)almostapproxassert_almost_equalassert_array_almost_equalassert_array_approx_equalassert_array_compareassert_array_equalassert_array_lessassert_closeassert_equalassert_equal_recordsassert_mask_equalassert_not_equalfail_if_array_equal)TestCase)r   r   r   r   r   Th㈵>:0yE>c                    t          t          |           t          |                    }t          |           }t          |          }|j        j        dk    s|j        j        dk    r't          j        ||                                          S t          t          |d|          |          	                    t
          j
                  }t          t          |d|          d          	                    t
          j
                  }	t          j        t          j        ||	z
            ||t          j        |	          z  z             }
|
                                S )a  
    Returns true if all components of a and b are equal to given tolerances.

    If fill_value is True, masked values considered equal. Otherwise,
    masked values are considered unequal.  The relative error rtol should
    be positive and << 1.0 The absolute error atol comes into play for
    those elements of b that are very small or zero; it says how small a
    must be also.

    OFcopymaskr	   )r
   r   r   dtypecharnpequalravelr   astypefloat64
less_equalumathabsolute)ab
fill_valuertolatolmd1d2xyds              R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numpy/ma/testutils.pyr   r   )   s    	

GAJJ''A	B	B	x}rx}33xB%%'''Re!,,,j	 	fRZ  	|BU333Q77>>rzJJA
enQU++TD5>!;L;L4L-LMMA7799       c                    t          t          |           t          |                    }t          |           }t          |          }|j        j        dk    s|j        j        dk    r't          j        ||                                          S t          t          |d|          |          	                    t
          j
                  }t          t          |d|          d          	                    t
          j
                  }t          j        t          j        ||z
            |          d| z  k    }	|	                                S )z
    Returns True if a and b are equal up to decimal places.

    If fill_value is True, masked values considered equal. Otherwise,
    masked values are considered unequal.

    r"   Fr#   r	         $@)r
   r   r   r&   r'   r(   r)   r*   r   r+   r,   aroundabs)
r0   r1   decimalr2   r5   r6   r7   r8   r9   r:   s
             r;   r   r   A   s    	

GAJJ''A	B	B	x}rx}33xB%%'''Re!,,,j	 	fRZ  	|BU333Q77>>rzJJA
	"&Q--))Twh-??A7799r<    c           	          t          t          |           t          |          |           t          t          |                    D ]%}t          | |         ||         d|d|            &dS )z;
    Asserts the equality of two non-array sequences.

    item=
N)r   lenrange)actualdesirederr_msgks       r;   _assert_equal_on_sequencesrM   V   st    
 Vc'llG4443w<<   F FVAY
,DA,D,D7,D,DEEEE
Fr<   c                 <   t          | j        |j                   | j        j        D ]t}t          j        | |          t          j        ||          }}|t
          ur?|t
          ur6t          t          j        | |          t          j        ||                     udS )zI
    Asserts that two records are equal.

    Pretty crude for now.

    N)r   r&   namesoperatorgetitemr   )r0   r1   fafbfs        r;   r   r   a   s     !'"""W] I I$Q**H,<Q,B,BRfrV||)!Q//1A!Q1G1GHHH
Fr<   c           	         t          |t                    rt          | t                    s)t          t          t	          |                               t          t          |           t          |          |           |                                D ]@\  }}|| vrt          | d|            t          | |         ||         d|d|            AdS t          |t          t          f          r.t          | t          t          f          rt          | |d          S t          | t                    s>t          |t                    s)t          | |g|          }|| k    st          |          dS | t          u r	|t          us|t          u r-| t          ur$t          | |g|dd          }t          |          t          j        |           } t          j        |          }| j        |j        }}|j        d	k    rA|j        d	k    r6t          |                                 |                                d          S t)          | ||          S )
z,
    Asserts that two items are equal.

    z not in key=rF   NrC   rK   r8   r9   )headerrO   S)
isinstancedictAssertionErrorreprtyper   rG   itemslisttuplerM   r   r   r   
ValueErrorr(   
asanyarrayr&   r'   tolistr   )rI   rJ   rK   rL   imsgactual_dtypedesired_dtypes           r;   r   r   p   sT    '4   &$'' 	5 d6ll!3!3444S[[#g,,888MMOO 	I 	IDAq$%;%;6%;%;<<<GAJ0Gq0G0Gg0G0GHHHH'D%=)) Gj$.O.O G)&'2FFFFvw'' :gw+G+G VW-w88&   %%%	6		Gv$5$5&F*:*:VW-#BjB B Boo]6""FmG$$G%+\7==\CM$6#$=$=)&--//*1..*:*:246 6 6 	6 fgw777r<   c           	         t          |t                    rt          | t                    s)t          t          t	          |                               t          t          |           t          |          |           |                                D ]H\  }}|| vrt          t          |                    t          | |         ||         d|d|            IdS t          |t          t          f          rt          | t          t          f          rot          t          |           t          |          |           t          t          |                    D ]%}t          | |         ||         d|d|            &dS t          | t          j                  st          |t          j                  rt          | ||          S t          | |g|          }|| k    st          |          dS )z<
    Raises an assertion error if two items are equal.

    rV   rF   NrE   )r[   r\   r]   r^   r_   fail_if_equalrG   r`   ra   rb   rH   r(   r   r   r   )rI   rJ   rK   rL   rf   rg   s         r;   rk   rk      s   
 '4   &$'' 	5 d6ll!3!3444c&kk3w<<999MMOO 	J 	JDAq$T!WW---&)WQZ1H1H1Hw1H1HIIII'D%=)) j$.O.O c&kk3w<<999s7||$$ 	K 	KA&)WQZ1I1I1I1I1IJJJJ&"*%% =GRZ)H)H ="67G<<<
)7
3
3CfS!!! r<      c                 $   t          | t          j                  st          |t          j                  rt          | ||||          S t	          | |g||          }t          t          || z
            |          dk    st          |          dS )z~
    Asserts that two items are almost equal.

    The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal).

    )rB   rK   verbose)rK   rn   r   N)r[   r(   r   r   r   roundrA   r]   )rI   rJ   rB   rK   rn   rg   s         r;   r   r      s     &"*%% KGRZ)H)H K('18'K K K 	K
) ': : :CWv%&&00A55S!!! 65r<   c                    t          t          |          t          |                    }t          |d|dd          }t          |d|dd          }|t          u r	|t          us|t          u r.|t          ur%t	          ||g|||d          }t          |          t          j                            | |	                    |          |	                    |          |||          S )zn
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    F)r$   r%   	keep_masksubokrX   )rK   rn   rY   rO   rK   rn   rY   )
r
   r   r   r   r   rc   r(   testingr   r   )	
comparisonr8   r9   rK   rn   rY   r2   r5   rg   s	            r;   r   r      s     	

GAJJ''AQUe5IIIAQUe5IIIA	
fqF{{6kkAKKQFGW#)= = =oo:**:+,88J+?+?+,88J+?+?3:3:6	 + K K Kr<   c                 D    t          t          j        | |||d           dS )z@
    Checks the elementwise equality of two masked arrays.

    Arrays are not equalrs   N)r   rP   __eq__r8   r9   rK   rn   s       r;   r   r      s5    
 !Q!(' 68 8 8 8 8 8r<   c                 6    d }t          || |||d           dS )zT
    Raises an assertion error if two masked arrays are not equal elementwise.

    c                 H    t          j        t          | |                     S )N)r(   allr   rX   s     r;   comparez$fail_if_array_equal.<locals>.compare   s    F6!Q<<((()r<   rw   rs   Nr   )r8   r9   rK   rn   r}   s        r;   r   r      s?    
* * *!Q 68 8 8 8 8 8r<   c                 <    fd}t          || |||d           dS )|
    Checks the equality of two masked arrays, up to given number odecimals.

    The equality is checked elementwise.

    c                 0    t          | |d z            S )<Returns the result of the loose comparison between x and y).r?   )r3   )r   r8   r9   rB   s     r;   r}   z*assert_array_approx_equal.<locals>.compare   s    a1111r<   Arrays are not almost equalrs   Nr~   r8   r9   rB   rK   rn   r}   s     `   r;   r   r      sL    2 2 2 2 2 !Q =? ? ? ? ? ?r<   c                 <    fd}t          || |||d           dS )r   c                 &    t          | |          S )r   )r   r   s     r;   r}   z*assert_array_almost_equal.<locals>.compare
  s    aG$$$r<   r   rs   Nr~   r   s     `   r;   r   r     sL    % % % % % !Q =? ? ? ? ? ?r<   c                 D    t          t          j        | |||d           dS )z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-orderedrs   N)r   rP   __lt__ry   s       r;   r   r     s5    
 !Q!(' =? ? ? ? ? ?r<   c                     | t           u rt          |t           u            |t           u rt          | t           u            t          | ||           dS )z-
    Asserts the equality of two masks.

    rW   N)r   r   r   )m1m2rK   s      r;   r   r     sU    
 
V||f	V||fr2w//////r<   )Tr   r    )r=   T)rC   )rl   rC   T)rC   TrC   T)rC   T)r=   rC   T)*__doc__rP   numpyr(   r   numpy._core.umath_corer.   numpy.testingr   r   r   r   r   corer
   r   r   r   r   r   __all__maskedunittestr   __some__from_testing__all__r   r   rM   r   r   rk   r   r   r   r   r   r   r   r   r   r    r<   r;   <module>r      sW               ! ! ! ! ! ! ! ! !                  I H H H H H H H H H H H H H H H           
 .
.   0   *     $8 $8 $8 $8N" " " "4 ! " " " "  # MO$(K K K K28 8 8 88 8 8 8? ? ? ?? ? ? ?? ? ? ?	0 	0 	0 	0 	0 	0r<   