
    wg (                        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)y)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   c                    t        t        |       t        |            }t        |       }t        |      }|j                  j                  dk(  s|j                  j                  dk(  r$t        j                  ||      j                         S t        t        |d|      |      j                  t
        j                        }t        t        |d|      d      j                  t
        j                        }	t        j                  t        j                  ||	z
        ||t        j                  |	      z  z         }
|
j                         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              W/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/numpy/ma/testutils.pyr   r   )   s     	
GAJ'A	B	B	xx}}rxx}}3xxB%%''Re!,j	fRZZ  	|BU3Q7>>rzzJA
ennQU+TD5>>!;L4L-LMA779    c                 p   t        t        |       t        |            }t        |       }t        |      }|j                  j                  dk(  s|j                  j                  dk(  r$t        j                  ||      j                         S t        t        |d|      |      j                  t
        j                        }t        t        |d|      d      j                  t
        j                        }t        j                  t        j                  ||z
        |      d| z  k  }	|	j                         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)
r.   r/   decimalr0   r3   r4   r5   r6   r7   r8   s
             r9   r   r   A   s     	
GAJ'A	B	B	xx}}rxx}}3xxB%%''Re!,j	fRZZ  	|BU3Q7>>rzzJA
		"&&Q-)Twh-??A779r:   c           	          t        t        |       t        |      |       t        t        |            D ]  }t        | |   ||   d|d|         y)z;
    Asserts the equality of two non-array sequences.

    item=
N)r   lenrange)actualdesirederr_msgks       r9   _assert_equal_on_sequencesrI   V   sV    
 Vc'lG43w<  FVAY
eA57),DEF
r:   c                 ^   t        | j                  |j                         | j                  j                  D ]t  }t        j                  | |      t        j                  ||      }}|t
        us8|t
        usAt        t        j                  | |      t        j                  ||             v y)zI
    Asserts that two records are equal.

    Pretty crude for now.

    N)r   r$   namesoperatorgetitemr   )r.   r/   fafbfs        r9   r   r   a   s     !''"WW]] I$$Q*H,<,<Q,BRfrV|))!Q/1A1A!Q1GHI r:   c           	         t        |t              rt        | t              st        t        t	        |                   t        t        |       t        |      |       |j                         D ]2  \  }}|| vrt        | d|        t        | |   ||   d|d|        4 yt        |t        t        f      r$t        | t        t        f      rt        | |d      S t        | t              s/t        |t              st        | |g|      }|| k(  st        |      y| 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(  r9|j$                  d	k(  r*t        | j'                         |j'                         d      S t)        | ||      S )
z,
    Asserts that two items are equal.

    z not in key=rB   N rG   r6   r7   )headerrK   S)
isinstancedictAssertionErrorreprtyper   rC   itemslisttuplerI   r   r   r   
ValueErrorr&   
asanyarrayr$   r%   tolistr   )rE   rF   rG   rH   imsgactual_dtypedesired_dtypes           r9   r   r   p   s    '4 &$' d6l!344S[#g,8MMO 	IDAq$s(6(%;<<GAJ$qe2gY0GH	I 	'D%=)j$.O)&'2FFvw':gw+GVW-w8&  %%	6	Gv$5&F*:VW-#BjBo]]6"FmmG$G%+\\7===\CM$6$6#$=)&--/*1..*:246 	6 fgw77r:   c           	      
   t        |t              rt        | t              st        t        t	        |                   t        t        |       t        |      |       |j                         D ]6  \  }}|| vrt        t        |            t        | |   ||   d|d|        8 yt        |t        t        f      rht        | t        t        f      rRt        t        |       t        |      |       t        t        |            D ]  }t        | |   ||   d|d|         yt        | t        j                        st        |t        j                        rt        | ||      S t        | |g|      }|| k7  st        |      y)z<
    Raises an assertion error if two items are equal.

    rR   rB   NrA   )rX   rY   rZ   r[   r\   fail_if_equalrC   r]   r^   r_   rD   r&   r   r   r   )rE   rF   rG   rH   rc   rd   s         r9   rh   rh      sW   
 '4 &$' d6l!344c&k3w<9MMO 	JDAq$T!W--&)WQZ4uBwi1HI	J 	'D%=)j$.Oc&k3w<9s7|$ 	KA&)WQZ5Ry1IJ	K&"**%GRZZ)H"67G<<
)7
3CfS!! r:   c                     t        | t        j                        st        |t        j                        rt        | ||||      S t	        | |g||      }t        t        || z
        |      dk(  st        |      y)z~
    Asserts that two items are almost equal.

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

    )r?   rG   verbose)rG   rj   r   N)rX   r&   r   r   r   roundr>   rZ   )rE   rF   r?   rG   rj   rd   s         r9   r   r      sx     &"**%GRZZ)H('18'K 	K
) ':CWv%&0A5S!! 6r:   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                  j                  | |j                  |      |j                  |      |||      S )zn
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    F)r"   r#   	keep_masksubokrU   )rG   rj   rV   rK   rG   rj   rV   )
r
   r   r   r   r   r`   r&   testingr   r   )	
comparisonr6   r7   rG   rj   rV   r0   r3   rd   s	            r9   r   r      s     	
GAJ'AQUe5IAQUe5IA	
fqF{6kAKQFGW#)=o::**:+,88J+?+,88J+?3:3:6	 + K Kr:   c                 B    t        t        j                  | |||d       y)z@
    Checks the elementwise equality of two masked arrays.

    Arrays are not equalro   N)r   rL   __eq__r6   r7   rG   rj   s       r9   r   r      s    
 !Q!(' 68r:   c                 ,    d }t        || |||d       y)zT
    Raises an assertion error if two masked arrays are not equal elementwise.

    c                 B    t        j                  t        | |             S )N)r&   allr   rU   s     r9   comparez$fail_if_array_equal.<locals>.compare   s    FF6!Q<(()r:   rs   ro   Nr   )r6   r7   rG   rj   ry   s        r9   r   r      s    
*!Q 68r:   c                 2    fd}t        || |||d       y)|
    Checks the equality of two masked arrays, up to given number odecimals.

    The equality is checked elementwise.

    c                 (    t        | |d z        S )<Returns the result of the loose comparison between x and y).r<   )r1   )r   r6   r7   r?   s     r9   ry   z*assert_array_approx_equal.<locals>.compare   s    a11r:   Arrays are not almost equalro   Nrz   r6   r7   r?   rG   rj   ry   s     `   r9   r   r      s    2 !Q =?r:   c                 2    fd}t        || |||d       y)r|   c                     t        | |      S )r~   )r   r   s     r9   ry   z*assert_array_almost_equal.<locals>.compare
  s    aG$$r:   r   ro   Nrz   r   s     `   r9   r   r     s    % !Q =?r:   c                 B    t        t        j                  | |||d       y)z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-orderedro   N)r   rL   __lt__ru   s       r9   r   r     s    
 !Q!(' =?r:   c                     | t         u rt        |t         u        |t         u rt        | t         u        t        | ||       y)z-
    Asserts the equality of two masks.

    rT   N)r   r   r   )m1m2rG   s      r9   r   r     s6    
 
V|f	V|fr2w/r:   )Tgh㈵>g:0yE>)   T)rS   )   rS   T)rS   TrS   T)rS   T)r   rS   T)*__doc__rL   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   rI   r   r   rh   r   r   r   r   r   r   r   r   r   r    r:   r9   <module>r      s       ! !   I H  
 .
.0*$8N"4 ! "  # MO$(K288???	0r:   