o
    k)h (                     @   s4  d Z ddlZddlZddlmZ ddlm  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d,ddZd-ddZd.ddZdd Zd.ddZd.ddZeZ d/ddZ!e!Z"		
d0ddZ#d1d d!Z$d1d"d#Z%d2d$d%Z&d2d&d'Z'd1d(d)Z(d.d*d+Z)dS )3zMiscellaneous 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                 C   s   t t| t|}t| }t|}|jjdks|jjdkr%t|| S tt|d|d|	tj
}tt|d|dd	tj
}	tt||	 ||t|	  }
|
 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float64Z
less_equalumathZabsolute)ab
fill_valuertolZatolmd1d2xyd r6   2lib/python3.10/site-packages/numpy/ma/testutils.pyr   )   s   $r      c           
      C   s   t t| t|}t| }t|}|jjdks|jjdkr%t|| S tt|d|d|	tj
}tt|d|dd	tj
}tt|| |d|  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*   Zaroundabs)
r,   r-   decimalr.   r0   r1   r2   r3   r4   r5   r6   r6   r7   r   A   s    r    c                 C   sJ   t t| t|| tt|D ]}t | | || d|d|  qdS )z;
    Asserts the equality of two non-array sequences.

    item=
N)r   lenrange)actualdesirederr_msgkr6   r6   r7   _assert_equal_on_sequencesV   s   "rE   c                 C   sd   t | j|j | jjD ]$}t| |t||}}|tur/|tur/t t| |t|| qdS )zI
    Asserts that two records are equal.

    Pretty crude for now.

    N)r   r$   namesoperatorgetitemr   )r,   r-   fafZbfr6   r6   r7   r   a   s   r   c                 C   s|  t |trDt | tsttt| tt| t|| | D ]!\}}|| vr1t| d|  t| | || d|d|  q dS t |tt	frYt | tt	frYt
| |ddS t | tstt |tstt| |g|}|| ksrt|dS | tu r||tus|tu r| turt| |g|ddd}t|t| } t|}| j|j}}|jd	kr|jd	krt
|  | ddS t| ||S )
z,
    Asserts that two items are equal.

    z not in key=r>   Nr<   rC   r3   r4   )headerrF   S)
isinstancedictAssertionErrorreprtyper   r?   itemslisttuplerE   r   r   r   
ValueErrorr&   Z
asanyarrayr$   r%   tolistr   )rA   rB   rC   rD   imsgZactual_dtypeZdesired_dtyper6   r6   r7   r   p   s>   

"

r   c                 C   s.  t |trAt | tsttt| tt| t|| | D ]\}}|| vr.tt|t| | || d|d|  q dS t |tt	frtt | tt	frttt| t|| t
t|D ]}t| | || d|d|  q_dS t | tjst |tjrt| ||S t| |g|}|| kst|dS )z<
    Raises an assertion error if two items are equal.

    rK   r>   Nr=   )rP   rQ   rR   rS   rT   fail_if_equalr?   rU   rV   rW   r@   r&   r   r   r   )rA   rB   rC   rD   rZ   r[   r6   r6   r7   r\      s(   

""r\      c                 C   s^   t | tjst |tjrt| ||||dS t| |g||d}tt||  |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).

    )r;   rC   verbose)rC   r^   r   N)rP   r&   r   r   r   roundr:   rR   )rA   rB   r;   rC   r^   r[   r6   r6   r7   r      s   r   c           	      C   s   t t|t|}t|d|ddd}t|d|ddd}|tu r#|tus+|tu r:|tur:t||g|||dd}t|tjj| |	||	||||dS )zn
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    F)r"   r#   Z	keep_maskZsubokrM   )rC   r^   rN   rF   rC   r^   rN   )
r	   r
   r   r   r   rX   r&   Ztestingr   r   )	Z
comparisonr3   r4   rC   r^   rN   r.   r0   r[   r6   r6   r7   r      s   	r   c                 C      t tj| |||dd dS )z@
    Checks the elementwise equality of two masked arrays.

    Arrays are not equalr`   N)r   rG   __eq__r3   r4   rC   r^   r6   r6   r7   r         

r   c                 C   s    dd }t || |||dd dS )zT
    Raises an assertion error if two masked arrays are not equal elementwise.

    c                 S   s   t t| | S )N)r&   allr   rM   r6   r6   r7   compare   s   z$fail_if_array_equal.<locals>.comparerb   r`   Nr   )r3   r4   rC   r^   rg   r6   r6   r7   r      s   
r   c                    $    fdd}t || |||dd dS )|
    Checks the equality of two masked arrays, up to given number odecimals.

    The equality is checked elementwise.

    c                    s   t | |d   dS )<Returns the result of the loose comparison between x and y).r9   )r/   )r   rM   r;   r6   r7   rg      s   z*assert_array_approx_equal.<locals>.compareArrays are not almost equalr`   Nrh   r3   r4   r;   rC   r^   rg   r6   rl   r7   r         
r   c                    ri   )rj   c                    s   t | | S )rk   )r   rM   rl   r6   r7   rg   
  s   z*assert_array_almost_equal.<locals>.comparerm   r`   Nrh   rn   r6   rl   r7   r     ro   r   c                 C   ra   )z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-orderedr`   N)r   rG   __lt__rd   r6   r6   r7   r     re   r   c                 C   s:   | t u r
t|t u  |t u rt| t u  t| ||d dS )z-
    Asserts the equality of two masks.

    rL   N)r   r   r   )Zm1Zm2rC   r6   r6   r7   r     s
   r   )Tr   r   )r8   T)r<   )r]   r<   T)r<   Tr<   T)r<   T)r8   r<   T)*__doc__rG   Znumpyr&   r   Znumpy._core.umathZ_corer+   Znumpy.testingr   r   r   r   r   corer	   r
   r   r   r   r   Z__all__maskedZunittestr   Z__some__from_testing__all__r   r   rE   r   r   r\   r   r   r   r   r   r   r   r   r   r   r6   r6   r6   r7   <module>   s<     




'








