a
    p=ic'                     @   s4  d Z ddlZddlZddlmZ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d0ddZeZ d1ddZ!e!Z"d2ddZ#d3d d!Z$d4d"d#Z%d5d$d%Z&d6d&d'Z'd7d(d)Z(d8d*d+Z)dS )9zMiscellaneous 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float_)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rJt|| S tt|d|d|	t
}tt|d|dd	t
}	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   astyper   Z
less_equalumathabsolute)ab
fill_valuertolZatolmd1d2xyd r7   c/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/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rJt|| S tt|d|d|	t
}tt|d|dd	t
}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/   r1   r2   r3   r4   r5   r6   r7   r7   r8   r   ?   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kr7   r7   r8   _assert_equal_on_sequencesR   s    "rF   c                 C   sd   t | j|j | jjD ]H}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afbfr7   r7   r8   r   ]   s    r   c                 C   s  t |trt | ts$ttt| tt| t|| | D ]B\}}|| vrbt| d|  t| | || d|d|  q@dS t |tt	frt | tt	frt
| |ddS t | tst |tst| |g|}|| kst|dS | tu r|tus|tu r*| tur*t| |g|ddd}t|t| } t|}| j|j }}|jd	krz|jd	krzt
|  | ddS t| ||S )
z,
    Asserts that two items are equal.

    z not in key=r?   Nr=   rD   r4   r5   )headerrG   S)
isinstancedictAssertionErrorreprtyper   r@   itemslisttuplerF   r   r   r   
ValueErrorr'   Z
asanyarrayr%   r&   tolistr   )rB   rC   rD   rE   imsgZactual_dtypeZdesired_dtyper7   r7   r8   r   l   sD    

"

r   c                 C   s4  t |trt | ts$ttt| tt| t|| | D ]<\}}|| vr\tt|t| | || d|d|  q@dS t |tt	frt | tt	frtt| t|| t
t|D ]$}t| | || d|d|  qdS t | tjst |tjrt| ||S t| |g|}|| ks0t|dS )z<
    Raises an assertion error if two items are equal.

    rM   r?   Nr>   )rR   rS   rT   rU   rV   fail_if_equalr@   rW   rX   rY   rA   r'   r   r   r   )rB   rC   rD   rE   r\   r]   r7   r7   r8   r^      s&    

""
r^      c                 C   s^   t | tjst |tjr*t| ||||dS t| |g||d}tt||  |dksZt|dS )z~
    Asserts that two items are almost equal.

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

    )r<   rD   verbose)rD   r`   r   N)rR   r'   r   r   r   roundr;   rT   )rB   rC   r<   rD   r`   r]   r7   r7   r8   r      s    r   c           	      C   s   t t|t|}t|d|ddd}t|d|ddd}|tu rF|tusV|tu rt|turtt||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subokrO   )rD   r`   rP   rG   rD   r`   rP   )
r
   r   r   r   r   rZ   r'   testingr   r   )	Z
comparisonr4   r5   rD   r`   rP   r/   r1   r]   r7   r7   r8   r      s$    	r   c                 C   s   t tj| |||dd dS )z@
    Checks the elementwise equality of two masked arrays.

    Arrays are not equalrb   N)r   rH   __eq__r4   r5   rD   r`   r7   r7   r8   r      s    
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'   Zalltruer   rO   r7   r7   r8   compare   s    z$fail_if_array_equal.<locals>.comparerd   rb   Nr   )r4   r5   rD   r`   rg   r7   r7   r8   r      s    r   c                    s$    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).r:   )r0   )r   rO   r<   r7   r8   rg      s    z*assert_array_approx_equal.<locals>.compareArrays are not almost equalrb   Nrh   r4   r5   r<   rD   r`   rg   r7   rk   r8   r      s    r   c                    s$    fdd}t || |||dd dS )ri   c                    s   t | | S )rj   )r   rO   rk   r7   r8   rg     s    z*assert_array_almost_equal.<locals>.comparerl   rb   Nrh   rm   r7   rk   r8   r      s    r   c                 C   s   t tj| |||dd dS )z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-orderedrb   N)r   rH   __lt__rf   r7   r7   r8   r     s    
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.

    rN   N)r   r   r   )m1m2rD   r7   r7   r8   r     s
    r   )Tr   r    )r9   T)r=   )r=   )r=   )r_   r=   T)r=   Tr=   T)r=   T)r=   T)r9   r=   T)r9   r=   T)r=   T)r=   )*__doc__rH   numpyr'   r   r   Znumpy.core.umathcorer+   Znumpy.testingr   r   r   r   r   r
   r   r   r   r   r   Z__all__maskedZunittestr   Z__some__from_testing__all__r   r   rF   r   r   r^   r   r   r   r   r   r   r   r   r   r   r7   r7   r7   r8   <module>   s:    



'

  







