a
    ߙfbn                     @   sr   d dl Z d dlZd dlZd dlZd dlZddlmZ g dZej	eddZ
ddd	Zejd fd
dZdddZdS )    N   )indent)fixed_width_indentdiff_valuesreport_diff_valueswhere_not_allclose   )width        c                 C   sL   t | tr@t |tr@t| r,t|r,dS tj| |||d S | |kS dS )a  
    Diff two scalar values. If both values are floats, they are compared to
    within the given absolute and relative tolerance.

    Parameters
    ----------
    a, b : int, float, str
        Scalar values to compare.

    rtol, atol : float
        Relative and absolute tolerances as accepted by
        :func:`numpy.allclose`.

    Returns
    -------
    is_different : bool
        `True` if they are different, else `False`.

    F)rtolatolN)
isinstancefloatnpZisnanZallcloseabr   r    r   1lib/python3.9/site-packages/astropy/utils/diff.pyr      s
    r   c              	   C   s  t | tjrt |tjr| j|jkrX|td| tt| jt|j||d d dS tt	| |k}|jd }|dd D ]H}|
 }|td|d	| t| t| |t| ||d d q|dkr|td
|d dd| dS |dkS t| }t|}	||	krVd}
d}d}t | tjrDt| } t|}nt| } t|}ntt|jt|	jd }|d d }
d|j d |d }d|	j d |d }t | t}t |t}|r|r|st | tjrt| nt| } |r|r|st |tjrt|nt|}d}t|  | D ]r}|d dkr`d}||dd  }n,|d dkrd}||dd  }n|
| }|td|d| q8|S )a  
    Write a diff report between two values to the specified file-like object.

    Parameters
    ----------
    a, b
        Values to compare. Anything that can be turned into strings
        and compared using :py:mod:`difflib` should work.

    fileobj : object
        File-like object to write to.
        The default is ``sys.stdout``, which writes to terminal.

    indent_width : int
        Character column(s) to indent.

    Returns
    -------
    identical : bool
        `True` if no diff, else `False`.

    z  Different array shapes:
r   )fileobjindent_widthFr   N   z  at z:
z  ...and at dz more indices.
 za>zb>(z) T-+z  {}

)r   r   Zndarrayshapewriter   r   strZ	transposewheretolisttupletypenumbersNumberreprmaxlen__name__rjustdifflibZndiff
splitlinesformatrstrip)r   r   r   r   Zdiff_indicesZ	num_diffsidxZlidxZtypeaZtypebZlnpadZsign_aZsign_bZpaddingZis_a_strZis_b_strZ	identicalliner   r   r   r   .   s    








r   h㈵>:0yE>c                 C   s   t t | st j| j} t t |s<t j|j}|dkrZ|dkrZt | |kS t t | | ||t |  kS )a  
    A version of :func:`numpy.allclose` that returns the indices
    where the two arrays differ, instead of just a boolean value.

    Parameters
    ----------
    a, b : array-like
        Input arrays to compare.

    rtol, atol : float
        Relative and absolute tolerances as accepted by
        :func:`numpy.allclose`.

    Returns
    -------
    idx : tuple of array
        Indices where the two arrays differ.

    r
   )r   allZisfiniteZmaZfix_invaliddatar!   absr   r   r   r   r      s    r   )r
   r
   )r2   r3   )r,   	functoolssysr%   Znumpyr   Zmiscr   __all__partialr   r   stdoutr   r   r   r   r   r   <module>   s   
_