o
    1ήc*                     @   s  d Z ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZmZ ejjZejjZejjZejjZejjZejjZe ej!e ej"e ej#e ej$iZ%e ej&e ej$kre%'e ej(e ej&i dddedfddZ)dddedfddZ*ddddedfddZ+ddddedfddZ,d3ddddZ-d3ddddZ.d4ddZ/dd Z0dd Z1ddd d!d"Z2d5dd#d$d%Z3d3ddd&d'Z4d6ddd(d)Z5d6ddd*d+Z6d7d,d-Z7d8d/d0Z8d8d1d2Z9dS )9zx
Array methods which are called by both the C-code for the method
and the Python code for the NumPy-namespace function

    N)nullcontext)
multiarray)umath)
asanyarray)numerictypes)_exceptions)_NoValue)pickle	os_fspathFTc                 C      t | |d ||||S N)umr_maximumaaxisoutkeepdimsinitialwhere r   :/tmp/pip-target-vg8gfxp4/lib/python/numpy/core/_methods.py_amax&      r   c                 C   r   r   )umr_minimumr   r   r   r   _amin*   r   r   c                 C      t | ||||||S r   )umr_sumr   r   dtyper   r   r   r   r   r   r   _sum.   r   r   c                 C   r   r   )umr_prodr   r   r   r   _prod2   r   r!   r   c                C   ,   |du rt | ||||S t | |||||dS NTr"   )umr_anyr   r   r   r   r   r   r   r   r   _any6      r'   c                C   r#   r$   )umr_allr&   r   r   r   _all<   r(   r*   c                 C   s   |du r2|d u rt t| j}nt|t s|f}d}|D ]}|| jt|| j 9 }qt|}|S ddl	m
} t||| j|tjd |}|S )NT   r   )broadcast_to)tuplerangendim
isinstanceshapemunormalize_axis_indexntintpnumpy.lib.stride_tricksr,   r   )arrr   r   r   itemsaxr,   r   r   r   _count_reduce_itemsB   s   


r:   c                 C   s>   ddl m} || dkrdS zt| W S  ty   Y dS w )Nr   )r/   F)numpy.core.fromnumericr/   umisnan	TypeError)r   r/   r   r   r   _clip_dep_is_scalar_nan\   s   r?   c                 C   s   t | tjr| jj S dS )NF)r0   r2   ndarrayr   isnative)r   r   r   r   _clip_dep_is_byte_swappedf   s   
rB   r   castingc             
   O   s   |d ur| |||d|S z
| |d|i|W S  t jyC } ztjd|j|jtdd | ||dd|W  Y d }~S d }~ww )NrC   r   zConverting the output of clip from {!r} to {!r} is deprecated. Pass `casting="unsafe"` explicitly to silence this warning, or correct the type of the variables.   
stacklevelunsafe)r   _UFuncOutputCastingErrorwarningswarnformatfrom_toDeprecationWarning)ufuncr   rD   argskwargser   r   r   _clip_dep_invoke_with_castingk   s    rT   )rD   c                K   s   |d u r|d u rt dt| s5t|s5d}t|r!td }d}t|r+td}d}|r5tjdtdd |d u rGttj	| |f||d|S |d u rYttj
| |f||d|S ttj| ||f||d|S )	NzOne of max or min must be givenFinfTa  Passing `np.nan` to mean no clipping in np.clip has always been unreliable, and is now deprecated. In future, this will always return nan, like it already does when min or max are arrays that contain nan. To skip a bound, pass either None or an np.inf of an appropriate sign.rE   rF   rC   )
ValueErrorrB   r?   floatrJ   rK   rO   rT   r<   minimummaximumclip)r   minmaxr   rD   rR   using_deprecated_nanr   r   r   _clip~   sN   

r^   c          
      C   s(  t | }d}t||||d}|du r|dkr'nt|dkd dr'tjdtdd |d u rKt|jjt	j
t	jfr<td	}nt|jjt	jrKtd
}d}t||||||d}	t|	tjrstj|	||	ddd}	|rq|d u rq|j|	}	|	S t|	dr|r|j|	| }	|	S |	j|	| }	|	S |	| }	|	S )NFr   r   Tr   r   zMean of empty slice.rE   rF   f8f4r"   rH   r   rD   subokr   )r   r:   r%   rJ   rK   RuntimeWarning
issubclassr   typer4   integerbool_r2   float16r   r0   r@   r<   true_dividehasattr)
r   r   r   r   r   r   r7   is_float16_resultrcountretr   r   r   _mean   s6   "

	
rp   c                C   s  t | }t||||d}|du r||kr%nt||kd dr%tjdtdd |d u r9t|jjt	j
t	jfr9td}t|||d|d}	|jdkrJ|}
n||	j}
t|	tjratj|	|
|	d	d
d}	nt|	dro|	j|	| }	n|	| }	t ||	 }t|jjt	jt	j
frtj|||d}n3|jtv r|jt|j dfd}tj|||d tj|d |d |jdj}ntj|t||dj}t||||||d}t|| d}t|tjrtj|||d	d
d}|S t|dr|j|| }|S || }|S )Nr_   Tr`   z!Degrees of freedom <= 0 for slicerE   rF   ra   r   rH   Frc   r   r   rE   )r   ).r   ).r+   )r   r:   r%   rJ   rK   re   rf   r   rg   r4   rh   ri   r2   r   r/   reshaper1   r0   r@   r<   rk   rl   floatingmultiply_complex_to_floatviewaddreal	conjugaterY   )r   r   r   r   ddofr   r   r7   rn   arrmeandivxxvro   r   r   r   _var   sN   "





r   c             	   C   sb   t | ||||||d}t|tjrtj||d}|S t|dr*|jt|}|S t|}|S )N)r   r   r   r{   r   r   rq   r   )	r   r0   r2   r@   r<   sqrtrl   r   rg   )r   r   r   r   r{   r   r   ro   r   r   r   _std  s   

r   c              	   C   s&   t t| |d ||t| |d d ||S r   )r<   subtractr   r   )r   r   r   r   r   r   r   _ptp  s
   r   rE   c                 C   s\   t |dr
t|}ntt|d}|}tj| ||d W d    d S 1 s'w   Y  d S )Nwritewbprotocol)rl   r   openr
   r	   dump)selffiler   ctxfr   r   r   _dump  s   

"r   c                 C   s   t j| |dS )Nr   )r	   dumps)r   r   r   r   r   _dumps$  s   r   )NNNF)FT)NNN)NNNr   F)NNFrr   ):__doc__rJ   
contextlibr   
numpy.corer   r2   r   r<   numpy.core.multiarrayr   r   r4   r   numpy._globalsr   numpy.compatr	   r
   rY   reducer   rX   r   rx   r   ru   r    
logical_orr%   logical_andr)   r   csinglesinglecdoubledoublerv   
longdoubleupdateclongdoubler   r   r   r!   r'   r*   r:   r?   rB   rT   r^   rp   r   r   r   r   r   r   r   r   r   <module>   sh    





%!C

