U
    e»{j~ˆ  ã                8   @   sª  d Z ddlZddlmZ ddlmZmZ ddddgZe	ƒ Z
i Zi Ze	ƒ Ze
d	d
„ ejjjD ƒO Z
e
ejejejejejejejejejejejejejejejejej ej!ej"ej#ej$ej%ej&ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFh7O Z
ejGejHejIejJejKejLejMejNejOejPejQejRejSejTejUhZVeVejWejXejYejZej[ej\ej]ej^ej_ej`ejaejbejcejdejeejfejgejhejiejjejkejlhO ZVeVdd
„ ejmjnjD ƒO ZVe�reVejoejphO ZVeejqejrejshO ZeeVO ZeeƒZteeƒZudd„ Zveudd„ ƒZweudd„ ƒZxeudd„ ƒZyeudd„ ƒZzeud„dd„ƒZ{etej|ej}ej~ejej€ej�hd�dd„ ƒZ‚etejƒej„ej…ej†ej‡ejˆhd�dd„ ƒZ‰etejŠej‹hd�dd „ ƒZŒetej�hd�d!d"„ ƒZŽetd…d$d%„ƒZ�eud†d&d'„ƒZ�eud‡d)d*„ƒZ‘eudˆd+d,„ƒZ’eud‰d-d.„ƒZ“eudŠd/d0„ƒZ”eud‹d2d3„ƒZ•eud4d5„ ƒZ–eud6d7„ ƒZ—eudŒd9d:„ƒZ˜eud;d<„ ƒZ™eud=d>„ ƒZšeud�d?d@„ƒZ›eudAdB„ ƒZœeudCdD„ ƒZ�eudŽdEdF„ƒZžetd�dGdH„ƒZŸeudIdJ„ ƒZ euddKœdLdM„ƒZ¡etd�dNdO„ƒZ¢eud‘d#dPœdQdR„ƒZ£dSdT„ Z¤d’dUdV„Z¥eud“dWdX„ƒZ¦dYdZ„ Z§d”d[d\„Z¨eud•d]d^„ƒZ©eud_d`„ ƒZªeud–dadb„ƒZ«eudcdd„ ƒZ¬eudedf„ ƒZ­eud—dgdh„ƒZ®etd˜didj„ƒZ¯eudkdl„ ƒZ°eudmdn„ ƒZ±eud™dpdq„ƒZ²eudrds„ ƒZ³G dtdu„ duƒZ´dšdxdy„Zµeuddddvdwej¶ddddddwfdzd{„ƒZ·eud›d|d}„ƒZ¸ddd~d~dœZ¹d€d�„ Zºejmj»jD ]"Z¼eueºe¼ƒe½ee¼ƒd�e¾ƒ e¼< �qXee¿d‚dƒ„ e	e À¡ ƒe	e À¡ ƒB D ƒƒ7 ZdS )œa¨  Helpers for letting numpy functions interact with Masked arrays.

The module supplies helper routines for numpy functions that propagate
masks appropriately., for use in the ``__array_function__``
implementation of `~astropy.utils.masked.MaskedNDArray`.  They are not
very useful on their own, but the ones with docstrings are included in
the documentation so that there is a place to find out how the mask is
interpreted.

é    N)ÚFunctionAssigner)ÚNUMPY_LT_1_23ÚNUMPY_LT_1_24ÚMASKED_SAFE_FUNCTIONSÚAPPLY_TO_BOTH_FUNCTIONSÚDISPATCHED_FUNCTIONSÚUNSUPPORTED_FUNCTIONSc                 C   s   h | ]}|d krt t|ƒ’qS )>   ÚchooseÚresizeÚputÚwhereÚalenÚsearchsorted©ÚgetattrÚnp)Ú.0Úname© r   úd/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/utils/masked/function_helpers.pyÚ	<setcomp>O   s   þr   c                 C   s   h | ]}t t|ƒ’qS r   r   )r   Z
setopsnamer   r   r   r   ˆ   s    c                  G   s:   ddl m} |j| Ž \}}tdd„ t||ƒD ƒƒ}||fS )z�Separate out arguments into tuples of data and masks.

    An all-False mask is created if an argument does not have a mask.
    é   ©ÚMaskedc                 s   s0   | ](\}}|d k	r|nt  t  |¡t¡V  qd S ©N)r   ÚzerosÚshapeÚbool)r   ÚdÚmr   r   r   Ú	<genexpr>¬   s    z&_get_data_and_masks.<locals>.<genexpr>)Úcorer   Ú_get_data_and_masksÚtupleÚzip)Úargsr   ÚdataÚmasksr   r   r   r"   ¤   s    ÿr"   c                 O   s    t j| jf|ž|Ž| j ¡ d fS r   )r   Údatetime_as_stringÚunmaskedÚmaskÚcopy)Úarrr%   Úkwargsr   r   r   r(   ³   s    r(   c                 C   s   t  | j¡| j ¡ d fS r   )r   Úsincr)   r*   r+   ©Úxr   r   r   r.   ¸   s    r.   c                 C   s   t  | j¡| j ¡ d fS r   )r   Ú	iscomplexr)   r*   r+   r/   r   r   r   r1   ½   s    r1   c                 O   s    t j| jf|ž|Ž| j ¡ d fS r   )r   Úunwrapr)   r*   r+   )Úpr%   r-   r   r   r   r2   Â   s    r2   Tç        c                 C   s.   t j| j||||d�}|r*|| j ¡ d fS | S )N)r+   ÚnanÚposinfÚneginf)r   Ú
nan_to_numr)   r*   r+   )r0   r+   r5   r6   r7   r&   r   r   r   r8   Ç   s    r8   )Zhelpsc                 O   s    t | ƒ\}}|| || |d fS r   ©r"   )Úar%   r-   r&   r*   r   r   r   Úmasked_a_helperÐ   s    r;   c                 O   s    t | ƒ\}}|| || |d fS r   r9   )r   r%   r-   r&   r*   r   r   r   Úmasked_m_helperØ   s    r<   c                 O   s    t | ƒ\}}|| || |d fS r   r9   )Úvr%   r-   r&   r*   r   r   r   Úmasked_v_helperÞ   s    r>   c                 O   s    t | ƒ\}}|| || |d fS r   r9   )Úarrayr%   r-   r&   r*   r   r   r   Úmasked_arr_helperä   s    r@   Fc                 C   s    t | ƒ\}}||t||d�dfS )a?  Broadcast array to the given shape.

    Like `numpy.broadcast_to`, and applied to both unmasked data and mask.
    Note that ``subok`` is taken to mean whether or not subclasses of
    the unmasked data and mask are allowed, i.e., for ``subok=False``,
    a `~astropy.utils.masked.MaskedNDArray` will be returned.
    ©r   ÚsubokN©r"   Údict)r?   r   rB   r&   r*   r   r   r   Úbroadcast_toê   s    	rE   c                 C   s   t jjt  | ¡t  |¡|d�S )N)Úout)r   ÚmultiplyÚouterÚravel)r:   ÚbrF   r   r   r   rH   ÷   s    rH   ÚKc                 C   s^   t j| j||||d�}|dk	r>|jjr4t j |j¡nt  d¡}t j| j||||d�}||dfS )z€Return a new array with the same shape and type as a given array.

    Like `numpy.empty_like`, but will add an empty mask.
    ©ÚdtypeÚorderrB   r   Nú?)r   Ú
empty_liker)   rM   ÚnamesÚmaZmake_mask_descrr*   )Z	prototyperM   rN   rB   r   r)   r*   r   r   r   rP   ü   s(        ÿÿý    ÿrP   c                 C   s    t j| j||||d�}|ddfS )zŠReturn an array of zeros with the same shape and type as a given array.

    Like `numpy.zeros_like`, but will add an all-false mask.
    rL   FN)r   Ú
zeros_liker)   ©r:   rM   rN   rB   r   r)   r   r   r   rS     s        ÿrS   c                 C   s    t j| j||||d�}|ddfS )zˆReturn an array of ones with the same shape and type as a given array.

    Like `numpy.ones_like`, but will add an all-false mask.
    rL   FN)r   Ú	ones_liker)   rT   r   r   r   rU     s        ÿrU   c                 C   s    t j| ||||d�}||d< |S )züReturn a full array with the same shape and type as a given array.

    Like `numpy.full_like`, but with a mask that is also set.
    If ``fill_value`` is `numpy.ma.masked`, the data will be left unset
    (i.e., as created by `numpy.empty_like`).
    rL   .)r   rP   )r:   Ú
fill_valuerM   rN   rB   r   Úresultr   r   r   Ú	full_like*  s    rX   Úraisec                 C   sf   ddl m} t||ƒs t| |ƒs$t‚|  |¡\}}|dk	rNtj| j|||d� tj| j|||d� dS )zÁReplaces specified elements of an array with given values.

    Like `numpy.put`, but for masked array ``a`` and possibly masked
    value ``v``.  Masked indices ``ind`` are not supported.
    r   r   N)Úmode)	Úastropy.utils.maskedr   Ú
isinstanceÚNotImplementedErrorÚ_get_data_and_maskr   r   r)   r*   )r:   Úindr=   rZ   r   Zv_dataZv_maskr   r   r   r   7  s    r   c                 C   s^   ddl m} t||ƒs t| |ƒs$t‚|  |¡\}}|dk	rJt | j||¡ t | j||¡ dS )zÅChanges elements of an array based on conditional and input values.

    Like `numpy.putmask`, but for masked array ``a`` and possibly masked
    ``values``.  Masked ``mask`` is not supported.
    r   r   N)	r[   r   r\   r]   r^   r   Úputmaskr)   r*   )r:   r*   Úvaluesr   Zvalues_dataZvalues_maskr   r   r   r`   K  s    r`   c                 C   s^   ddl m} t||ƒs t| |ƒs$t‚|  |¡\}}|dk	rJt | j||¡ t | j||¡ dS )zÂChange elements of an array based on conditional and input values.

    Like `numpy.place`, but for masked array ``a`` and possibly masked
    ``values``.  Masked ``mask`` is not supported.
    r   r   N)	r[   r   r\   r]   r^   r   Úplacer)   r*   )r,   r*   Úvalsr   Z	vals_dataZ	vals_maskr   r   r   rb   ^  s    rb   Ú	same_kindc                 C   sl   ddl m} t| |ƒr t||ƒr$t‚|  |¡\}}|dk	rNtj| j|||d� |dk	rhtj| j||d� dS )z­Copies values from one array to another, broadcasting as necessary.

    Like `numpy.copyto`, but for masked destination ``dst`` and possibly
    masked source ``src``.
    r   r   N)Úcastingr   )r   )	r[   r   r\   r]   r^   r   Úcopytor)   r*   )ÚdstÚsrcre   r   r   Zsrc_dataZsrc_maskr   r   r   rf   q  s    rf   c                 O   s8   t j| jf|ž|Ž}t j| jf|ž|Ž t¡}||d fS r   )r   Úpackbitsr)   r*   Úastyper   ©r:   r%   r-   rW   r*   r   r   r   ri   †  s    ri   c                 O   sP   t j| jf|ž|Ž}t j| jdd�}d|| j< t j|f|ž|Ž t¡}||d fS )NÚu1©rM   éÿ   )r   Ú
unpackbitsr)   r   r   r*   rj   r   rk   r   r   r   ro   �  s
    
ro   c                 C   s¸   ddl m} |dk	rt |¡}t| |ƒr`| jdkr`|dk	rR|j| jkrR|| j  }| j| j  } d}|dk	rž| |¡\}}|dk	ržtj	| | 
t¡|d� 
t¡}tj	| |dd�}||dfS )zîCount number of occurrences of each value in array of non-negative ints.

    Like `numpy.bincount`, but masked entries in ``x`` will be skipped.
    Any masked entries in ``weights`` will lead the corresponding bin to
    be masked.
    r   r   Nr   )Ú	minlength)r[   r   r   Ú
asanyarrayr\   Úndimr*   r)   r^   Úbincountrj   Úintr   )r0   Úweightsrp   r   r*   Zw_maskrW   r   r   r   rs   –  s    
rs   c                 C   s   |   ¡ }|jdd� |S )Nr   ©Úaxis)r+   Úsort)r:   rW   r   r   r   Úmsort°  s    ry   c                 C   s`   |   ¡ }| ¡  t|jjtjƒsX|jjdkr6| d¡S |jjdkrL| d¡S | d¡S n|S d S )NZbhBHÚFÚgÚGÚD)	r+   rx   Ú
issubclassrM   Útyper   ZcomplexfloatingÚcharrj   )r:   rJ   r   r   r   Úsort_complex·  s    

r�   c                 C   s€   t | Ž \}}|d kr6tj||||d�tj||d�d fS ddlm} t||ƒsPt‚tj||j|d� tj||j|||d� |S d S )N)rw   rM   re   rv   r   r   )rF   rw   )rF   rw   rM   re   )	r"   r   Úconcatenater[   r   r\   r]   r*   r)   )Úarraysrw   rF   rM   re   r&   r'   r   r   r   r   r‚   Ç  s    ý
r‚   c                 C   s    t | |ƒ\}}||t|d�d fS )Nrv   rC   )r,   ra   rw   r&   r'   r   r   r   ÚappendÚ  s    r„   c                 C   s¼   ddl m} tjj | ¡\} }}}tjj | ||¡\}}} tjdd„ | D ƒŽ }tdd„ | D ƒƒ}tdd„ | D ƒƒ}	|r~|	s~dnd	}
|tj	|||
d
�ƒ}t
|| ƒD ]\}}||tf| < q |S )Nr   r   c                 S   s   g | ]
}|j ‘qS r   rm   ©r   r,   r   r   r   Ú
<listcomp>ï  s     zblock.<locals>.<listcomp>c                 s   s   | ]}|j d  V  qdS )ZF_CONTIGUOUSN©Úflagsr…   r   r   r   r    ð  s     zblock.<locals>.<genexpr>c                 s   s   | ]}|j d  V  qdS )ZC_CONTIGUOUSNr‡   r…   r   r   r   r    ñ  s     rz   ÚC)r   rM   rN   )r[   r   r   r!   Z
shape_baseZ_block_setupZ_block_info_recursionÚresult_typeÚallÚemptyr$   ÚEllipsis)rƒ   r   Z	list_ndimZresult_ndimZ
final_sizer   ZslicesrM   ZF_orderZC_orderrN   rW   Z	the_slicer,   r   r   r   Úblockà  s    	  ÿ
rŽ   ©rB   c                    s¦   ddl m‰  ‡ fdd„|D ƒ}dd„ t||ƒD ƒ}tj|dˆiŽ}t|tƒrV|d jn|j‰‡‡fdd„t||ƒD ƒ}‡ fd	d„t||ƒD ƒ}t|ƒdkrž|S |d S )
aI  Broadcast arrays to a common shape.

    Like `numpy.broadcast_arrays`, applied to both unmasked data and masks.
    Note that ``subok`` is taken to mean whether or not subclasses of
    the unmasked data and masks are allowed, i.e., for ``subok=False``,
    `~astropy.utils.masked.MaskedNDArray` instances will be returned.
    r   r   c                    s   g | ]}t |ˆ ƒ‘qS r   )r\   )r   Úargr   r   r   r†     s     z$broadcast_arrays.<locals>.<listcomp>c                 S   s   g | ]\}}|r|j n|‘qS r   )r)   ©r   r�   Z	is_maskedr   r   r   r†     s    rB   r   c                    s*   g | ]"\}}|r"t j|jˆ ˆd �nd‘qS )r�   N)r   rE   r*   r‘   rA   r   r   r†     s   ÿc                    s&   g | ]\}}|d k	rˆ ||ƒn|‘qS r   r   )r   rW   r*   r   r   r   r†     s   ÿ)	r!   r   r$   r   Úbroadcast_arraysr\   Úlistr   Úlen)rB   r%   Z
are_maskedr&   Úresultsr'   r   )r   r   rB   r   r’   ù  s    	ÿþ
þr’   c           	      C   sV   ddl m} t||ƒs t| |ƒs$t‚t| |ƒ\\}}\}}||||f||||fi dfS )z¯Insert values along the given axis before the given indices.

    Like `numpy.insert` but for possibly masked ``arr`` and ``values``.
    Masked ``obj`` is not supported.
    r   r   N)r[   r   r\   r]   r"   )	r,   Úobjra   rw   r   Zarr_dataZval_dataZarr_maskZval_maskr   r   r   Úinsert  s
    r—   ©Úkeepdimsc                C   s$   |   t d| j¡¡}tj|||d�S )zŠCounts the number of non-zero values in the array ``a``.

    Like `numpy.count_nonzero`, with masked values counted as 0 or `False`.
    r   r˜   )Úfilledr   r   rM   Úcount_nonzero)r:   rw   r™   rš   r   r   r   r›   &  s    r›   c                 C   sJ   | j | j  }|jr(|  tj||d�¡S | jtj| j dd�d dd�S d S )N)Úoverwrite_input)r   ©r   r   T©r*   )r)   r*   ÚsizeÚfrom_unmaskedr   ÚmedianrS   )r:   rœ   r)   r   r   r   Ú_masked_median_1d0  s    r¢   c                 C   sJ   |d ks| j dkr&|  ¡ }t||ƒ}nt t|| |¡}|d k	rF||d< |S )Nr   .)rr   rI   r¢   r   Úapply_along_axis)r:   rw   rF   rœ   ÚpartrW   r   r   r   Ú_masked_median9  s    r¥   c                 K   sœ   ddl m} |d k	r"t||ƒs"t‚|| ƒ} trz| dd¡}tjjj	| ft
||dœ|—Ž\}}|d krv|rr| |¡qx|S |S tjjj	| ft
||dœ|—ŽS d S )Nr   r   r™   F)Úfuncrw   rF   )r[   r   r\   r]   r   Úpopr   ÚlibÚfunction_baseÚ_ureducer¥   Úreshape)r:   rw   rF   r-   r   r™   ÚrÚkr   r   r   r¡   E  s2    ÿ  ÿÿ
ÿ  ÿÿr¡   c                 K   sP   | j | j  }|jr2tjjj||f|Ž}|  |¡S |  tj| j |j	d�d¡S dS )zw
    Private function for rank 1 arrays. Compute quantile ignoring NaNs.
    See nanpercentile for parameter usage
    r�   TN)
r)   r*   rŸ   r   r¨   r©   Z_quantile_uncheckedr    rS   r   )r:   Úqr-   r)   rW   r   r   r   Ú_masked_quantile_1d[  s
    
r¯   c                 K   sj   |d ks| j dkr*|  ¡ }t||f|Ž}n,tjt|| |f|Ž}|j dkrVt ||d¡}|d k	rf||d< |S )Nr   r   .)rr   rI   r¯   r   r£   Úmoveaxis)r:   r®   rw   rF   r-   r¤   rW   r   r   r   Ú_masked_quantileh  s    
r±   c           	      K   sÐ   ddl m} t||ƒs(|d k	r,t||ƒs,t‚|| ƒ} t |¡}tjj |¡sTt	dƒ‚t
r¬| dd¡}tjjj| ft|||dœ|—Ž\}}|d kr¨|r¤| |j| ¡qª|S |S tjjj| ft|||dœ|—ŽS d S )Nr   r   z%Quantiles must be in the range [0, 1]r™   F)r¦   r®   rw   rF   )r[   r   r\   r]   r   rq   r¨   r©   Z_quantile_is_validÚ
ValueErrorr   r§   rª   r±   r«   r   )	r:   r®   rw   rF   r-   r   r™   r¬   r­   r   r   r   Úquantilez  s<    
ÿ   ÿÿ
$ÿ   ÿÿr³   c                 O   s   t  |d¡}t| |f|ž|ŽS )Néd   )r   Ztrue_divider³   )r:   r®   r%   r-   r   r   r   Ú
percentile’  s    rµ   c                 C   s^   t | |ƒ\\}}\}}|j|jkr&dS ||k}|rJ|t |¡t |¡@ O }t||B |B  ¡ ƒS )NF)r"   r   r   Úisnanr   r‹   )Úa1Úa2Z	equal_nanZa1dZa2dZa1mZa2mÚequalr   r   r   Úarray_equal˜  s    rº   c                 C   s   t | |k ¡ ƒS r   )r   r‹   )r·   r¸   r   r   r   Úarray_equiv¤  s    r»   c                 G   st   ddl m} |s|  ¡ d d fS | | ¡\} }t|Ž \}}tj| f|žŽ }tj| f|žŽ }|d k	rh||O }|||d�S )Nr   r   rž   )r[   r   Znonzeror^   r"   r   r   )Ú	conditionr%   r   Zc_maskr&   r'   r)   r*   r   r   r   r   ©  s    r   c                 C   sÂ   ddl m} | | ¡\}}|dk	r6|dkr6| jdd�}d|i}|dk	r^t||ƒsTt‚|j|d< t|Ž \}}	tj	||f|Ž}
|dk	rŒ|j
|d< tj	||	f|Ž}|dk	r¬||O }|dkr¾||
|ƒS |S )aA  Construct an array from an index array and a set of arrays to choose from.

    Like `numpy.choose`.  Masked indices in ``a`` will lead to masked output
    values and underlying data values are ignored if out of bounds (for
    ``mode='raise'``).  Any values masked in ``choices`` will be propagated
    if chosen.

    r   r   NrY   )rV   rZ   rF   )r[   r   r^   rš   r\   r]   r)   r"   r   r	   r*   )r:   ÚchoicesrF   rZ   r   Za_dataZa_maskr-   r&   r'   Zdata_chosenZmask_chosenr   r   r   r	   º  s"    



r	   c                    sf   ddl m‰  ‡ fdd„| D ƒ} t|Ž \}}|tjjk	r>ˆ |ƒn
ˆ ddd�}| ||jf| ||jfi dfS )zÃReturn an array drawn from elements in choicelist, depending on conditions.

    Like `numpy.select`, with masks in ``choicelist`` are propagated.
    Any masks in ``condlist`` are ignored.

    r   r   c                    s    g | ]}t |ˆ ƒr|jn|‘qS r   )r\   r)   )r   Úcr   r   r   r†   ç  s     zselect.<locals>.<listcomp>Trž   N)r[   r   r"   r   rR   Zmaskedr)   r*   )ÚcondlistZ
choicelistÚdefaultZ	data_listZ	mask_listr   r   r   ÚselectÝ  s     

ürÁ   c                 O   sT  t |ƒ}t |¡s0t|d ttjfƒs6| jdkr6|g}tj|td�}t |ƒ}||d kr†tj	|ddd� }tj
||gdd�}|d7 }n(||kr®td|› d|› d	|d › d
�ƒ‚t | ¡}g }	g }
t|ƒD ]h}|| }t|ƒsö|	 || ¡ |
 |¡ qÈ| ||  }|jdkrÈ|	 || ¡ |
 ||f|ž|Ž¡ qÈt|	|
ƒD ]\}}|||< �q<|S )z•Evaluate a piecewise-defined function.

    Like `numpy.piecewise` but for masked input array ``x``.
    Any masks in ``condlist`` are ignored.

    r   rm   r   T)rw   r™   rv   zwith z condition(s), either z or z functions are expected)r”   r   Zisscalarr\   r“   Zndarrayrr   r?   r   Úanyr‚   r²   rS   ÚrangeÚcallabler„   rŸ   r$   )r0   r¿   Zfunclistr%   ÚkwZn2ÚnZcondelseÚyr   Úwhatr­   Úitemrc   Úvaluer   r   r   Ú	piecewiseó  s@    

ÿÿ
ÿ

rË   c                 O   s¬   ddl m} | | ¡\}}t||ƒs.t||ƒr|t||ƒ\\}}\}}	|j|j  kr\dkr|n n||	B }
||
  }||
  }tj|||f|ž|Ž}|dkrž|S ||| ¡ ƒS )zÏOne-dimensional linear interpolation.

    Like `numpy.interp`, but any masked points in ``xp`` and ``fp``
    are ignored.  Any masked values in ``x`` will still be evaluated,
    but masked on output.
    r   r   r   N)	r[   r   r^   r\   r"   rr   r   Úinterpr+   )r0   ZxpÚfpr%   r-   r   ZxdZxmZxpmZfpmr   rW   r   r   r   rÌ   %  s    

rÌ   éÿÿÿÿc                 C   sz   ddl m} g }| D ]V}t||ƒr`|j}|rN|j ¡ rN| ¡ }|jd ||j< | ||jg¡ q| 	|¡ qt
j||d�S )z¶Perform an indirect stable sort using a sequence of keys.

    Like `numpy.lexsort` but for possibly masked ``keys``.  Masked
    values are sorted towards the end for each key.
    r   r   r   rv   )r!   r   r\   r)   r*   rÂ   r+   ZflatÚextendr„   r   Úlexsort)Úkeysrw   r   Znew_keysÚkeyZnew_keyr   r   r   rÐ   <  s    
rÐ   c                 C   s†   |}|j }t |¡j dkr |f}|D ]\}|dk r8|| }||f}| |Ž }|j |j krZ|}q$t ||¡}|j |j krx|}q$tdƒ‚q$|S )Nr   z7function is not returning an array of the correct shape)rr   r   r?   Úexpand_dimsr²   )r¦   r:   ZaxesÚvalÚNrw   r%   Úresr   r   r   Úapply_over_axesV  s$    ÿr×   c                   @   s,   e Zd ZdZdd„ Zdd„ Zedd„ ƒZdS )	ÚMaskedFormatzõFormatter for masked array scalars.

    For use in `numpy.array2string`, wrapping the regular formatters such
    that if a value is masked, its formatted string is replaced.

    Typically initialized using the ``from_data`` class method.
    c                 C   sH   || _ t|dd ƒ}|r(dd„ |D ƒ| j _t|dd ƒ}|rDt|ƒ| j _ d S )NÚformat_functionsc                 S   s   g | ]}t |ƒ‘qS r   )rØ   )r   Úffr   r   r   r†   „  s     z)MaskedFormat.__init__.<locals>.<listcomp>Úformat_function)rÛ   r   rÙ   rØ   )ÚselfrÛ   ZffsrÚ   r   r   r   Ú__init__|  s    zMaskedFormat.__init__c                    s~   ˆ j jr$|  ‡ fdd„ˆ j jD ƒ¡S ˆ jr4|  ˆ ¡S |  ˆ jd ¡}ˆ jrvtdtdt|ƒƒƒ}dt|ƒ|  d|  S |S d S )Nc                    s   g | ]}ˆ | ‘qS r   r   )r   Úfieldr/   r   r   r†   �  s     z)MaskedFormat.__call__.<locals>.<listcomp>r   é   r   ú u   â€”)	rM   rQ   rÛ   r   r)   r*   ÚminÚmaxr”   )rÜ   r0   ÚstringrÆ   r   r/   r   Ú__call__‹  s    
zMaskedFormat.__call__c                 K   s   ddl m} | ||f|ŽƒS )Nr   )Ú_get_format_function)Únumpy.core.arrayprintrå   )Úclsr&   Úoptionsrå   r   r   r   Ú	from_data¤  s    zMaskedFormat.from_dataN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rÝ   rä   Úclassmethodré   r   r   r   r   rØ   s  s
   rØ   rà   Ú c              
   C   sˆ   ddl m}m} t | ¡}| j|d kr<d}|||d ƒ}nd}tj|f|Ž}d}	|	dt|ƒ 7 }	|| ||d |	||d ||d	 ƒ}
|
S )
Nr   )Ú_formatArrayÚ_leading_trailingÚ	thresholdz...Ú	edgeitemsrï   rà   Ú	linewidthÚlegacy)	ræ   rð   rñ   r   ZasarrayrŸ   rØ   ré   r”   )r:   rè   Ú	separatorÚprefixrð   rñ   r&   Zsummary_insertrÛ   Znext_line_prefixÚlstr   r   r   Ú_array2string«  s(    
ø
rù   c                 C   sl   ddl m}m} ||||	||d d |
||ƒ
}| ¡ }| |¡ |d  t|ƒ8  < | jdkr^dS t| |||ƒS )Nr   )Ú_format_optionsÚ_make_options_dictrô   z[])ræ   rú   rû   r+   Úupdater”   rŸ   rù   )r:   Úmax_line_widthÚ	precisionÚsuppress_smallrö   r÷   ÚstyleÚ	formatterrò   ró   ÚsignZ	floatmodeÚsuffixrú   rû   Z	overridesrè   r   r   r   Úarray2stringÎ  s&    ö

r  c                 C   s   t | |||ddƒS )Nrà   rï   )r  )r:   rý   rþ   rÿ   r   r   r   Ú	array_strù  s    r  r   )ZnansumZ	nancumsumZnanprodZ
nancumprodc                    s|   t t| dd … ƒ‰t | d ¡‰ ‡ ‡fdd„}d| › d�}ˆ d k	rR|dˆ › d�7 }nd| krd|d	7 }n|d
7 }||_| |_|S )Nrß   c                    s|   ddl m} | | ¡\} }t| jjtjƒrHt | ¡}|d kr@|n||B }|d k	rl|| |ƒ} ˆ d k	rl|  	ˆ ¡} ˆ| f|ž|ŽS )Nr   r   )
r[   r   r^   r~   rM   r   r   Zinexactr¶   rš   )r:   r%   r-   r   r*   Znans©rV   Znp_funcr   r   Únanfunc  s    


zmasked_nanfunc.<locals>.nanfunczLike `numpy.z$`, skipping masked values as well.

z$Masked/NaN values are replaced with z. The output is not masked.r�   zRNo exceptions are raised for fully masked/NaN slices.
Instead, these give index 0.zZNo warnings are given for fully masked/NaN slices.
Instead, they are masked in the output.)r   r   Ú_nanfunc_fill_valuesÚgetrí   rê   )Únanfuncnamer  Údocr   r  r   Úmasked_nanfunc  s$    
ÿÿÿr  c                 c   s   | ]}|j r|jV  qd S r   )rí   rê   )r   Úhelperr   r   r   r    7  s   ür    )Tr4   NN)F)N)NrK   TN)NrK   TN)NrK   TN)NrK   TN)rY   )rd   T)Nr   )r   NNrd   )N)N)N)NNF)NN)NN)NN)F)NrY   )r   )rÎ   )rà   rï   )NNN)Árí   Únumpyr   Z.astropy.units.quantity_helper.function_helpersr   Zastropy.utils.compatr   r   Ú__all__Úsetr   r   r   r   r!   ZfromnumericZmay_share_memoryZcan_castZmin_scalar_typerŠ   Zshares_memoryZ
array_reprZlinspaceZlogspaceZ	geomspaceÚiscloseZallcloseZflatnonzeroZargwhereZ
atleast_1dZ
atleast_2dZ
atleast_3dÚstackZhstackZvstackZaverageÚdiffÚextractZmeshgridZtrapzZgradientZdiag_indices_fromZtriu_indices_fromZtril_indices_fromZfill_diagonalZcolumn_stackZ	row_stackZdstackZarray_splitÚsplitZhsplitZvsplitZdsplitrÓ   r£   ZkronZtileZtake_along_axisZput_along_axisZiscomplexobjZ	isrealobjÚimagZisrealÚrealZreal_if_closeZcommon_typeZfixZisneginfZisposinfZangleZi0ÚsaveZsavezZsavetxtZsavez_compressedZpolyZpolyaddZpolyderZpolydivZpolyfitZpolyintZpolymulZpolysubZpolyvalÚrootsZvanderZIGNORED_FUNCTIONSÚpadr   ZdigitizeZ	is_busdayZbusday_countZbusday_offsetZcovZcorrcoefZ
trim_zerosZ	correlateZconvolveZ	histogramZhistogram2dZhistogramddZhistogram_bin_edgesÚdotZvdotÚinnerZ	tensordotÚcrossZeinsumZeinsum_pathr¨   ZarraysetopsZasscalarr   Zunravel_indexZravel_multi_indexZix_Zapply_to_bothZdispatched_functionr"   r(   r.   r1   r2   r8   r+   Zasfarrayr
   r°   ZrollaxisZrollr;   ÚflipZflipudZfliplrZrot90ZtriuZtrilr<   ZdiagZdiagflatr>   Údeleter@   rE   rH   rP   rS   rU   rX   r   r`   rb   rf   ri   ro   rs   ry   r�   r‚   r„   rŽ   r’   r—   r›   r¢   r¥   r¡   r¯   r±   r³   rµ   rº   r»   r   r	   rÁ   rË   rÌ   rÐ   r×   rØ   rù   Z_NoValuer  r  r  r  Znanfunctionsr
  r   ÚglobalsÚsortedra   r   r   r   r   Ú<module>   sî  
üþ                                      ä             û               õÿýý



ÿ
 









		




"
1

8
#ó*+ ÿ
ý