o
    "g (                     @   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float64
less_equalumathabsolute)ab
fill_valuertolatolmd1d2xyd r9   T/var/www/html/ecg_monitoring/venv/lib/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*   aroundabs)
r.   r/   decimalr0   r3   r4   r5   r6   r7   r8   r9   r9   r:   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kr9   r9   r:   _assert_equal_on_sequencesV   s   "rI   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afbfr9   r9   r:   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=rB   Nr@   rG   r6   r7   )headerrJ   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_dtyper9   r9   r:   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.

    rP   rB   NrA   )rU   rV   rW   rX   rY   fail_if_equalrC   rZ   r[   r\   rD   r&   r   r   r   )rE   rF   rG   rH   r`   ra   r9   r9   r:   rd      s(   

""rd      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?   rG   verbose)rG   rf   r   N)rU   r&   r   r   r   roundr>   rW   )rE   rF   r?   rG   rf   ra   r9   r9   r:   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#   	keep_masksubokrR   )rG   rf   rS   rJ   rG   rf   rS   )
r	   r
   r   r   r   r]   r&   testingr   r   )	
comparisonr6   r7   rG   rf   rS   r0   r3   ra   r9   r9   r:   r      s   	r   c                 C      t tj| |||dd dS )z@
    Checks the elementwise equality of two masked arrays.

    Arrays are not equalrj   N)r   rK   __eq__r6   r7   rG   rf   r9   r9   r:   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   rR   r9   r9   r:   compare   s   z$fail_if_array_equal.<locals>.comparern   rj   Nr   )r6   r7   rG   rf   rs   r9   r9   r:   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).r<   )r1   )r   rR   r?   r9   r:   rs      s   z*assert_array_approx_equal.<locals>.compareArrays are not almost equalrj   Nrt   r6   r7   r?   rG   rf   rs   r9   rx   r:   r         
r   c                    ru   )rv   c                    s   t | | S )rw   )r   rR   rx   r9   r:   rs   
  s   z*assert_array_almost_equal.<locals>.comparery   rj   Nrt   rz   r9   rx   r:   r     r{   r   c                 C   rm   )z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-orderedrj   N)r   rK   __lt__rp   r9   r9   r:   r     rq   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.

    rQ   N)r   r   r   )m1m2rG   r9   r9   r:   r     s
   r   )Tr   r   )r;   T)r@   )re   r@   T)r@   Tr@   T)r@   T)r;   r@   T)*__doc__rK   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   rd   r   r   r   r   r   r   r   r   r   r   r9   r9   r9   r:   <module>   s<     




'








