o
    i}6                    @   s  d Z ddlZddlmZ ddlZddlZddlZddlZ	ddl
mZmZ ddlmZmZmZ ddlmZmZmZmZmZmZ ddlmZmZmZmZ ddlmZmZm Z m!Z! dd	l"m#Z# dd
lm$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- dd Z.e. Z/e$dd Z0e$dd Z1ee	j2ej3edej3dd Z4edd Z5dd Z6ee	j2ej3ej7ej8ee	j2ej3ej9ej8edej3ej7ej8edej3ej9ej8dd Z:ee	j2ej3ej8edej3ej8dd Z;ee	j2ej3ej7ee	j2ej3ej9edej3ej7edej3ej9dd Z<d d! Z=ee	j>eej3d"d#d$ Z?ee	j@eej3d%d&d' ZAee	jBeej3d(d)d* ZCee	jDeej3d+d,d- ZEee	jFeej3d.d/d0 ZGee	jHeej3d1d2d3 ZIed4d5 ZJed6d7 ZKed8d9 ZLee	jMee	jNeej3d:d;d< ZOee	jPee	jQeej3d=d>d? ZRed@dA ZSedBdC ZTedDdE ZUee	jVeej3dFddGdHZWedIdJ ZXedKdL ZYedMdN ZZdOdP Z[ee	j\eej3dQddRdSZ]ee	j^eej3dTdUdV Z_eddZd[Z`ee	jaeej3d\dd]d^Zbee	jceej3d_d`da Zdee	jeddbdcZfddde Zgee	jhdfdg Ziee	jjdhdi Zkee	jldjdk Zlee	jmdldm Zmee	jndndo Zodpdq Zpee	jqddrdsZqee	jrddtduZredvdw Zsedxdy Ztedzd{ Zud|d} ZveevesdYd~ZweevetdYd~Zxeevesdd~Zyeevetdd~Zzedd Z{ee	j|dddZ|ee	j}dd Z~ee	jdd Zee	jdd Zee	jdd Zee	jdd Zee	jdd Zee	jdd Zee	jdd Zee	jdd Zedd Zdd Zdd Zdd Zeedd Zeedd Zdd Zeedd Zeej3dee	jdd Zedd ZdddZeeesZeeeZeeeddZdd ZeeeZeeeZeeeZedd Zedd Zee	jdd Zedd Zedd Zedd Zedd Zedd Zedd ZddÄ Zee	jddń Zee	jddǄ Zee	jddɄ Zee	jdd˄ Zee	jdd̈́ Zeddτ Zeddф Zeddӄ Zee	jddՄ Zee	jddׄ Zeddل Zee	jdddۄZedd݄ Zeddd߄Zee	jÃdddZee	jŃdddZee	jǃdddZedddZee	jʃdddZee	j̃dddZee	j΃dddZdd ZeeЃdd Zdd Zee	jӃdddZdd ZeeՃdd Zdd Zee׃dd Zee	jكddd Zedd Zedd Zee	j݃dؐddZee	j߃dd Zd	Zed
d Zedd Zedd Zee	jdd Zedd Zedd Zdd Zeedd Zedd Zedd Zdd Zd d! Zed"d# Zed$d Zed%d& Zd'd( Zed)d* Zed+d, Zee	jdِd-d.Zee	jdڐd/d0Zee	jd1d2 Zee	jd3d4 Zed5d6 Zed7d8 Zed9d: Zed;d< Z ed=d> Zed?d Zd@dA ZeedBdC Zee	jdӐdDdEZdFdG Ze$dHdI ZedJdK Z	ee	j
ee	jee	jd֐dLdMZee	jdNdO Zee	jdӐdPdQZee	jej3edRej3dSdT ZdUdV ZedWdX ZedYdZ Zd[d\ Zee	jd]d^ Zee	jd_d` Zee	jdadb Zee	jdcdd Zeejdedf Z ee	j!dАdgdhZ"edid Z#edjd Z$ee	j%dkdl Z&ee	j'dېdndoZ(ee	j)dpdq Z*ee	j+drds Z,dtdu Z-ee	j.dԐdvdwZ/dxdy Z0esZ1edzd Z2ee0e1Z3ee0e2Z4ee	j5dܐd|d}Z5ee	j6dӐd~dZ7e8Z9ee	j:dݐddZ;dZ<ede<Z=dZ>ede>Z?dZ@ede@ZAdd ZBeB  dd ZCee	j?dd ZDee	jAdd ZEdd ZFdd ZGdd ZHeeHdd ZIee	jJdސddZKee	jLdߐddZMee	jNdАddZOee	jPe	jQfddZRee	jSdd ZTee	jUdՐddZVee	jWdd ZXee	jYdАddZZedd Z[edd Z\edd Z]edd Z^dd Z_ee	j`e_e[ ee	jae_e\ ee	jbe_e] ee	jce_e^ e	dg dZee	dg dZfedd Zgedd Zhedd Ziee	jjdd Zkedd Zldd ZmeemdÐdĄ Znee	jodŐdƄ ZpedǐdȄ Zqdɐdʄ Zreerdːd̄ Zsee	jtddΐdτZudS (  z5
Implementation of math operations on Array objects.
    N)
namedtuple)typescgutils)overloadoverload_methodregister_jitable)as_dtypetype_can_asarraytype_is_scalarnumpy_versionis_nonelikecheck_is_integer)lower_builtinimpl_ret_borrowedimpl_ret_new_refimpl_ret_untracked)
make_array	load_item
store_item_empty_nd_impl)ensure_blas)	intrinsic)RequireLiteralValueTypingErrorNumbaValueErrorNumbaNotImplementedErrorNumbaTypeErrorNumbaDeprecationWarning)tuple_setitemc                   C   s"   zt   W dS  ty   Y dS w NFT)r   ImportError r!   r!   a/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/np/arraymath.py_check_blas    s   r#   c                    s<   t |d  ttj |} fdd}||fS )a  
    This routine converts shape list where the axis dimension has already
    been popped to a tuple for indexing of the same size.  The original shape
    tuple is also required because it contains a length field at compile time
    whereas the shape list does not.
       c              	      sp   |  }t|}|\}}dd }t D ]}	| tj|	}
| ||ttj||
g}||||	}q|S )Nc                 S   s   | | S Nr!   )air!   r!   r"   array_indexerE      zB_create_tuple_result_shape.<locals>.codegen.<locals>.array_indexer)	get_value_typer   get_null_valuerangeget_constantr   intpcompile_internalinsert_value)cgctxbuilder	signatureargslltuptytupZin_shape_r(   r'   Zdataidxdatand
shape_listtuptyr!   r"   codegen=   s   

z+_create_tuple_result_shape.<locals>.codegen)lenr   UniTupler.   )tyctxr;   shape_tuplefunction_sigr=   r!   r9   r"   _create_tuple_result_shape,   s
   
rC   c           	         s   t |tjs
td|j t| krd  }| d }g }|tjg| 7 }|tjg7 }|tjg| 7 }t||||} fdd}||fS )aH  
    Generates a tuple that can be used to index a specific slice from an
    array for sum with axis.  shape_tuple is the size of the dimensions of
    the input array.  'value' is the value to put in the indexing tuple
    in the axis dimension and 'axis' is that dimension.  For this to work,
    axis has to be a const.
    z axis argument must be a constantr   r$   c                    s   |  }t|}|\}}}dd }| ||t g }	td D ]	}
|||	|
}q"||| }t d D ]	}
|||	|
}q:|S )Nc                   S   s
   t d d S r%   )slicer!   r!   r!   r"   create_full_slice      
z<_gen_index_tuple.<locals>.codegen.<locals>.create_full_slicer   r$   )r*   r   r+   r/   r   slice2_typer,   r0   )r1   r2   r3   r4   r5   r6   r7   Z	value_argrE   Z
slice_datar'   Z
axis_valuer:   r<   r!   r"   r=   |   s   


z!_gen_index_tuple.<locals>.codegen)	
isinstancer   Literalr   literal_valuer>   rG   r.   Tuple)	r@   rA   valueaxisbeforeafterZ
types_listrB   r=   r!   rH   r"   _gen_index_tupleU   s    	
rQ   z	array.sumc                    B   | d  fdd}| j||||t|j dd}t| ||j |S )Nr   c                    s$    }t | D ]}|| 7 }q|S r%   npnditeritem)arrcvzeror!   r"   array_sum_impl      z!array_sum.<locals>.array_sum_implrX   localsreturn_typer/   dictr   contextr2   sigr4   r\   resr!   rZ   r"   	array_sum      

rh   c                 C      | S r%   r!   )rW   rY   r!   r!   r"   _array_sum_axis_nop      rk   c                    s    fdd}|S )Nc                    s2  | j }s|dk s|dkrtd||krtdt| j}|| }|| t|| j}t|t}t	|D ]Y}rLt
| j| }|| | 7 }q:|dkr^t
| j|d}	|| |	 7 }q:|dkrpt
| j|d}
|| |
 7 }q:|dkrt
| j|d}|| | 7 }q:|dkrt
| j|d}|| | 7 }q:|dS )a(  
        function that performs sums over one specific axis

        The third parameter to gen_index_tuple that generates the indexing
        tuples has to be a const so we can't just pass "axis" through since
        that isn't const.  We can check for specific values and have
        different instances that do take consts.  Supporting axis summation
        only up to the fourth dimension for now.

        typing/arraydecl.py:sum_expand defines the return type for sum with
        axis. It is one dimension less than the input array.
        r      zHNumba does not support sum with axis parameter outside the range 0 to 3.zaxis is out of bounds for arrayr$      )ndim
ValueErrorlistshapepoprC   rT   fulltyper,   rQ   )rW   rN   ro   ZashapeZaxis_lenZashape_without_axisresultZ
axis_indexZindex_tuple_genericZindex_tuple1Zindex_tuple2Zindex_tuple3Zindex_tuple4const_axis_valis_axis_constopr[   r!   r"   inner   s>   


z gen_sum_axis_impl.<locals>.innerr!   )ry   rx   rz   r[   r{   r!   rw   r"   gen_sum_axis_impl   s   =r|   c                    s  |j }t|d|d}t|dd d u rtj}nt}|j\}}}	d}
d}t|tjrb|j	}|dk r5|j
| }|dk s>||j
krBtd| j|}| ||}|d ||d f}|j|||	gd}d}
t|
|||}t|  fd	d
}| ||||}t| ||j |S )Ndtyper   ro   Fz'axis' entry is out of boundsrn   r4   Tc                    
    | |S r%   r!   )rW   rN   r}   compiledr!   r"   array_sum_impl_axis  rF   z1array_sum_axis_dtype.<locals>.array_sum_impl_axis)rb   getattrrT   takerk   r4   rI   r   rJ   rK   ro   rp   typing_contextresolve_value_typer-   replacer|   r   r/   r   )re   r2   rf   r4   rettyr[   rz   ty_arrayty_axisZty_dtypery   rx   axis_valgen_implr   rg   r!   r   r"   array_sum_axis_dtype   s0   
r   c                    rR   )Nr   c                    s$    }t | D ]}|| 7 }q|S r%   rS   )rW   r}   rX   rY   rZ   r!   r"   r\   '  r]   z'array_sum_dtype.<locals>.array_sum_implr^   r_   ra   rd   r!   rZ   r"   array_sum_dtype"  ri   r   c                    s  |j }t|d|d}t|dd d u rtj}nt}|j\}}d}	d}
t|tjrc|j	}
|
dk r4|j
|
 }
|
dk s=|
|j
krGd|
 d}t|| j|
}| ||
}|d |f}|j||gd}d}	t|	|
||}t|  fd	d
}| ||||}t| ||j |S )Nr}   r   ro   Fz'axis' entry (z) is out of boundsr~   Tc                    r   r%   r!   )rW   rN   r   r!   r"   r   W  rF   z+array_sum_axis.<locals>.array_sum_impl_axis)rb   r   rT   r   rk   r4   rI   r   rJ   rK   ro   r   r   r   r-   r   r|   r   r/   r   )re   r2   rf   r4   r   r[   rz   r   r   ry   rx   msgr   r   r   rg   r!   r   r"   array_sum_axis2  s2   

r   c                 C   s.   | j tjkrt|| }|S |  |}|S r%   )ru   rT   Ztimedelta64int64view)r}   rM   acc_initr!   r!   r"   get_accumulator^  s
   
r   prodc                    s4   t | tjrt| j}t|d  fdd}|S d S )Nr$   c                    s$    }t | D ]}|| 9 }q|S r%   rS   r&   rX   rY   r   r!   r"   array_prod_impln  r]   z#array_prod.<locals>.array_prod_impl)rI   r   Arrayr   r}   r   )r&   r}   r   r!   r   r"   
array_prodf  s   

r   cumsumc                    r   t | tjr7| jtjv }| jtjk}|r| jjtjjk s|r$ttjnt| jt	d  fdd}|S d S )Nr   c                    s:   t | j} }t| jD ]\}}||7 }|||< q|S r%   rT   emptysize	enumerateflatr&   outrX   idxrY   r   r}   r!   r"   array_cumsum_impl     
z'array_cumsum.<locals>.array_cumsum_impl
rI   r   r   r}   Zsigned_domainbool_bitwidthr.   r   r   )r&   
is_integeris_boolr   r!   r   r"   array_cumsumw     

r   cumprodc                    r   )Nr$   c                    s:   t | j} }t| jD ]\}}||9 }|||< q|S r%   r   r   r   r!   r"   array_cumprod_impl  r   z)array_cumprod.<locals>.array_cumprod_implr   )r&   r   r   r   r!   r   r"   array_cumprod  r   r   meanc                    s\   t | tjr,| jtjttjgB v }|rttj}nt| j}t	|d  fdd}|S d S )Nr   c                    s*    }t | D ]}|| 7 }q|| j S r%   )rT   rU   rV   r   r   r   r!   r"   array_mean_impl  s   
z#array_mean.<locals>.array_mean_impl)
rI   r   r   r}   Zinteger_domain	frozensetr   r   float64r   )r&   Z	is_numberr}   r   r!   r   r"   
array_mean  s   

r   varc                 C      t | tjrdd }|S d S )Nc                 S   sJ   |   }d}t| D ]}| | }|t|t| 7 }q|| j S Nr   )r   rT   rU   rV   realconjr   )r&   mssdrY   valr!   r!   r"   array_var_impl  s   
z!array_var.<locals>.array_var_implrI   r   r   )r&   r   r!   r!   r"   	array_var  s   r   stdc                 C   r   )Nc                 S   s   |   d S N      ?)r   r&   r!   r!   r"   array_std_impl     z!array_std.<locals>.array_std_implr   )r&   r   r!   r!   r"   	array_std  s   r   c                 C      | |k S r%   r!   r&   Zmin_valr!   r!   r"   min_comparator     r   c                 C      | |kS r%   r!   r   r!   r!   r"   max_comparator  r   r   c                 C      dS NFr!   r   r!   r!   r"   return_false  rl   r   minc                       t | tjsd S t | jtjtjfrtjt n#t | jtj	r*t
dd }t| nt | jtjr7tjt nt
t  fdd}|S )Nc                 S   s0   | j |j k rdS | j |j kr| j|jk rdS dS NTFr   imagr   r!   r!   r"   	comp_func     znpy_min.<locals>.comp_funcc                    j   | j dkr	tdt| }t|d}|r|S |D ]}| }|r+|  S  ||r2|}q|S )Nr   zDzero-size array to reduction operation minimum which has no identityr   rp   rT   rU   nextr   rV   )r&   it	min_valuer   rY   Z
comparatorZpre_return_funcr!   r"   impl_min     


znpy_min.<locals>.impl_min)rI   r   r   r}   
NPDatetimeNPTimedeltarT   isnatr   Complexr   r   Floatisnan)r&   r   r   r!   r   r"   npy_min      
r   maxc                    r   )Nc                 S   s0   | j |j krdS | j |j kr| j|jkrdS dS r   r   )r&   Zmax_valr!   r!   r"   r   *  r   znpy_max.<locals>.comp_funcc                    r   )Nr   zDzero-size array to reduction operation maximum which has no identityr   )r&   r   	max_valuer   rY   r   r!   r"   impl_max:  r   znpy_max.<locals>.impl_max)rI   r   r   r}   r   r   rT   r   r   r   r   r   r   r   )r&   r   r   r!   r   r"   npy_max  r   r   c                 C   s   | j dkr	tdt| }t|d}d}t|r|S d}|D ]}| }t|r1|  S ||k r9|}|}|d7 }q"|S Nr   *attempt to get argmin of an empty sequencer$   r   rp   rT   rU   r   r   r   rV   )arryr   r   min_idxr   r   rY   r!   r!   r"   array_argmin_impl_datetimeO  "   




r   c                 C   sr   | j dkr	td| jD ]}|}d} t|r|S d}| jD ]}t|r*|  S ||k r2|}|}|d7 }q|S r   r   rp   r   rT   r   r   rY   r   r   r   r!   r!   r"   array_argmin_impl_floate  "   





r   c                 C   s\   | j dkr	td| jD ]}|}d} ntdd}| jD ]}||k r'|}|}|d7 }q|S )Nr   r   Zunreachabler$   )r   rp   r   RuntimeErrorr   r!   r!   r"   array_argmin_impl_generic{  s   



r   argminc                    \   t | jtjtjfrt nt | jtjrt nt t	|r&d fdd	}|S t
| | }|S )Nc                        | S r%   r!   r&   rN   flatten_implr!   r"   array_argmin_impl  r)   z'array_argmin.<locals>.array_argmin_implr%   )rI   r}   r   r   r   r   r   r   r   r   %build_argmax_or_argmin_with_axis_impl)r&   rN   r   r!   r   r"   array_argmin     r  c                 C   s   | j dkr	tdt| }t|d}d}t|r|S d}|D ]}| }t|r1|  S ||kr9|}|}|d7 }q"|S Nr   z*attempt to get argmax of an empty sequencer$   r   )r   r   r   max_idxr   r   rY   r!   r!   r"   array_argmax_impl_datetime  r   r  c                 C   sr   | j dkr	td| jD ]}|}d} t|r|S d}| jD ]}t|r*|  S ||kr2|}|}|d7 }q|S r  r   r   rY   r   r  r   r!   r!   r"   array_argmax_impl_float  r   r  c                 C   sR   | j dkr	td| jD ]}|}d} d}| jD ]}||kr"|}|}|d7 }q|S r  )r   rp   r   r  r!   r!   r"   array_argmax_impl_generic  s   



r	  c                    s4   t |d tjtt| jd fdd	}|S )z|
    Given a function that implements the logic for handling a flattened
    array, return the implementation function.
    rN   Nc           	         s  |dk r	| j | }|dk s|| j krtd| j dkr | S }t|| j d D ]
}t|||d }q)t|| j d |}| |}|jd }| }|j| jksSJ |j| dks\J t	|j| }t|jD ]} ||| |d |  ||< qj|
|jd d S )Nr   zaxis is out of boundsr$   )ro   rp   r,   r   	transposerr   ravelr   rT   r   reshape)	r&   rN   tmpr'   Ztranspose_indexZtransposed_arrr   Zraveledr   r   r   Ztuple_bufferr!   r"   impl  s&   



"z3build_argmax_or_argmin_with_axis_impl.<locals>.implr%   )r   r   r.   tupler,   ro   )r&   rN   r   r  r!   r  r"   r    s
   
r  argmaxc                    r   )Nc                    r   r%   r!   r   r   r!   r"   array_argmax_impl  r)   z'array_argmax.<locals>.array_argmax_implr%   )rI   r}   r   r   r   r  r   r  r	  r   r  )r&   rN   r  r!   r   r"   array_argmax  r  r  allc                 C      dd }|S )Nc                 S   s"   t | D ]	}| s dS qdS r   rS   r&   rY   r!   r!   r"   flat_all$  
   znp_all.<locals>.flat_allr!   )r&   r  r!   r!   r"   np_all!     r  h㈵>:0yE>Fc                 C   s   t | }t |}|s|s|r|sdS |r|r|sdS dS t | s(t |r,| |kS t | | ||t |d   kr@dS dS )NF      ?TrT   r   isinfabs)Za_vZb_vrtolatol	equal_nanZ	a_v_isnanZ	b_v_isnanr!   r!   r"   _allclose_scalars-  s"   

$r%  allclosec                 C   s   t | stdt |stdt|ttjfstdt|ttjfs(tdt|ttjfs4tdt| tj}t|tj}|rM|rM		dd	d
}|S |rZ|sZ		ddd}|S |sg|rg		ddd}	|	S |st|sv		ddd}
|
S d S d S )N)The first argument "a" must be array-like*The second argument "b" must be array-like2The third argument "rtol" must be a floating point3The fourth argument "atol" must be a floating point0The fifth argument "equal_nan" must be a booleanr  r  Fc                 S   s   t | ||||dS )Nr"  r#  r$  )r%  r&   br"  r#  r$  r!   r!   r"   np_allclose_impl_scalar_scalara  s   
z3np_allclose.<locals>.np_allclose_impl_scalar_scalarc                 S   s:   t |}t |D ]}t| | |||ds dS q
dS Nr,  FTrT   asarrayrU   r%  rV   )r&   r.  r"  r#  r$  bvr!   r!   r"   np_allclose_impl_scalar_arrayg     
z2np_allclose.<locals>.np_allclose_impl_scalar_arrayc                 S   s:   t | } t | D ]}t| ||||ds dS q
dS r0  r1  )r&   r.  r"  r#  r$  avr!   r!   r"   np_allclose_impl_array_scalarq  r5  z2np_allclose.<locals>.np_allclose_impl_array_scalarc           	      S   s`   t | } t |}t | |\}}t ||fD ]\}}t| | |||ds- dS qdS r0  )rT   r2  Zbroadcast_arraysrU   r%  rV   )	r&   r.  r"  r#  r$  Za_aZb_br6  r3  r!   r!   r"   np_allclose_impl_array_array{  s   

z1np_allclose.<locals>.np_allclose_impl_array_arrayr  r  F)	r	   r   rI   floatr   r   boolBooleanNumber)r&   r.  r"  r#  r$  Zis_a_scalarZis_b_scalarr/  r4  r7  r8  r!   r!   r"   np_allcloseG  sB   



r>  anyc                 C   r  )Nc                 S   s"   t | D ]	}| r dS qdS r   rS   r  r!   r!   r"   flat_any  r  znp_any.<locals>.flat_anyr!   )r&   r@  r!   r!   r"   np_any  r  rA  c                 C   sR   |d u s
t |tjrddd}|S |d u st |tjr"ddd}|S ddd}|S )Nc                 S   s   t | }t |S r%   )rT   r2  r   )r&   rN   weightsrW   r!   r!   r"   np_average_impl  s   

z#np_average.<locals>.np_average_implc                 S   sv   t | }t |}|j|jkr!|d u rtd|jdkr!tdt |}|dkr.tdt t ||| }|S )NzCNumba does not support average when shapes of a and weights differ.r$   z81D weights expected when shapes of a and weights differ.        z)Weights sum to zero, can't be normalized.)rT   r2  rr   	TypeErrorro   sumZeroDivisionErrormultiply)r&   rN   rB  rW   ZsclZavgr!   r!   r"   rC    s$   



c                 S   s   t d)Nz)Numba does not support average with axis.)rE  )r&   rN   rB  r!   r!   r"   rC    r)   NN)rI   r   NoneType)r&   rN   rB  rC  r!   r!   r"   
np_average  s   


rK  c                 C   s(   t | tjtjfrtjS tdd }|S )z$
    A generic isnan() function
    c                 S   r   r   r!   xr!   r!   r"   _trivial_isnan  rl   z!get_isnan.<locals>._trivial_isnan)rI   r   r   r   rT   r   r   )r}   rN  r!   r!   r"   	get_isnan  s
   
rO  c                 C      t | rdd S d S )Nc                 S   s   t | jdkS r   rT   r2  r   rL  r!   r!   r"   <lambda>      znp_iscomplex.<locals>.<lambda>r	   rL  r!   r!   r"   np_iscomplex     rU  c                 C   rP  )Nc                 S   s   t | jdkS r   rQ  rL  r!   r!   r"   rR    rS  znp_isreal.<locals>.<lambda>rT  rL  r!   r!   r"   	np_isreal  rV  rW  c                    sX   t | }t| tjrt | j}t|tj t| tjr$ fdd}|S  fdd}|S )Nc                    s   | d u rdS  S r   r!   rL  Ziscmplxr!   r"   r    s   ziscomplexobj.<locals>.implc                        S r%   r!   rL  rX  r!   r"   r       )determine_dtyperI   r   Optionalru   rT   
issubdtypecomplexfloating)rM  dtr  r!   rX  r"   iscomplexobj  s   
r`  c                 C   r  )Nc                 S   s   t |  S r%   )rT   r`  rL  r!   r!   r"   r    r   zisrealobj.<locals>.implr!   rM  r  r!   r!   r"   	isrealobj  s   rb  c                    s   t |   fdd}|S )Nc                    rY  r%   r!   )elementrg   r!   r"   r    rZ  znp_isscalar.<locals>.impl)r
   )rc  r  r!   rd  r"   np_isscalar  s   re  c                    s,   t |rd fdd	}|S d fdd	}|S )Nc                    s   t t |  t | S r%   rT   logical_andr   ZsignbitrM  r   fnr!   r"   r       zis_np_inf_impl.<locals>.implc                    s   t t |  t | |S r%   rf  rh  ri  r!   r"   r       r%   r   )rM  r   rj  r  r!   ri  r"   is_np_inf_impl   s
   rn  c                 C      t dd }t| ||S )Nc                 S   rj   r%   r!   rL  r!   r!   r"   rR        zisneginf.<locals>.<lambda>r   rn  rM  r   rj  r!   r!   r"   isneginf     rs  c                 C   ro  )Nc                 S   s   |  S r%   r!   rL  r!   r!   r"   rR    s    zisposinf.<locals>.<lambda>rq  rr  r!   r!   r"   isposinf  rt  ru  c                 C   r   r%   r!   r&   r.  r!   r!   r"   	less_than  r   rw  c                 C   r   r%   r!   rv  r!   r!   r"   greater_than  r   rx  c                 C   s   | j dkr	tdd S )Nr   z3zero-size array to reduction operation not possible)r   rp   r   r!   r!   r"   check_array#  s   
ry  c                    s$   |r
 fdd}|S  fdd}|S )Nc                    s   t | }t| t |}t|d}|D ].}| }t |jr,t |js,|}q |j|jr6|}q|j|jkrE |j	|j	rE|}q|S r   )
rT   r2  ry  rU   r   r   rV   r   r   r   r&   rW   r   
return_valr   rY   comparison_opr!   r"   r  +  s   

z!nan_min_max_factory.<locals>.implc                    sX   t | }t| t |}t|d}|D ]}| }t |s) ||s)|}q|S r   )rT   r2  ry  rU   r   r   rV   r   rz  r|  r!   r"   r  <  s   



r!   )r}  is_complex_dtyper  r!   r|  r"   nan_min_max_factory)  s
   r  )r~  Tc                 C   sp   t | rt |r|S t | rt |r| dk|dkkS t | s(t |r*dS t| | ||t|  kS )Nr   Fr  )rM  yr"  r#  r$  r!   r!   r"   _isclose_itemY  s   r  c                 C   s   t | stdt |stdt|ttjfstdt|ttjfs(tdt|ttjfs4tdt| tjrGt|tj	rGdd	d
}|S t| tj	rZt|tjrZddd
}|S t| tjrmt|tjrmddd
}|S ddd
}|S )Nr'  r(  r)  r*  r+  r  r  Fc           	      S   sV   |  d}|}tt|tj}tt|D ]}t|| ||||||< q| | jS Nr
  r  rT   zerosr>   r   r,   r  rr   	r&   r.  r"  r#  r$  rM  r  r   r'   r!   r!   r"   isclose_implz  s   
zisclose.<locals>.isclose_implc           	      S   sV   | }| d}tt|tj}tt|D ]}t||| |||||< q| |jS r  r  r  r!   r!   r"   r    s   
c                 S   s   t | j|j}t | |}t ||}t jt|t jd}tt ||fD ]\}	\}
}t	|

 |
 |||||	< q't ||S Nr}   )rT   broadcast_shapesrr   broadcast_tor  r>   r   r   rU   r  rV   )r&   r.  r"  r#  r$  rr   a_b_r   r'   r6  r3  r!   r!   r"   r    s   
c                 S   s   t | ||||S r%   )r  r-  r!   r!   r"   r       r9  )
r	   r   rI   r:  r   r   r;  r<  r   r=  )r&   r.  r"  r#  r$  r  r!   r!   r"   isclosee  s*   
!


r  c                 C      t | }t|tjrtS tS r%   )r[  rT   r]  r^  complex_nanminreal_nanminr&   r_  r!   r!   r"   	np_nanmin     r  c                 C   r  r%   )r[  rT   r]  r^  complex_nanmaxreal_nanmaxr  r!   r!   r"   	np_nanmax  r  r  c                    *   t | tjsd S t| j  fdd}|S )Nc                    sH   d}d}t | D ]}| } |s|| 7 }|d7 }q	t ||S NrD  r   r$   )rT   rU   rV   divide)r&   rX   countr   rY   r   r!   r"   nanmean_impl  s   z np_nanmean.<locals>.nanmean_implrI   r   r   rO  r}   )r&   r  r!   r  r"   
np_nanmean  s
   
r  c                    r  )Nc                    sj   t | }d}d}t | D ] }| } |s.| | }|t |t | 7 }|d7 }qt ||S r  )rT   nanmeanrU   rV   r   r   r  )r&   r   r   r  r   rY   r   r  r!   r"   nanvar_impl  s   
znp_nanvar.<locals>.nanvar_implr  )r&   r  r!   r  r"   	np_nanvar  
   
r  c                 C      t | tjsd S dd }|S )Nc                 S   s   t | d S r   )rT   nanvarr   r!   r!   r"   nanstd_impl     znp_nanstd.<locals>.nanstd_implr   )r&   r  r!   r!   r"   	np_nanstd  s   r  c                    P   t | tjsd S t | jtjrtj}n| j}|dt| j  fdd}|S )Nr   c                    s0   }t | D ]}| } |s||7 }q|S r%   rS   r&   rX   r   rY   r   r[   r!   r"   nansum_impl     znp_nansum.<locals>.nansum_implrI   r   r   r}   Integerr.   rO  )r&   r   r  r!   r  r"   	np_nansum     
r  c                    r  )Nr$   c                    s0   }t | D ]}| } |s||9 }q|S r%   rS   r  r   oner!   r"   nanprod_impl	  r  z np_nanprod.<locals>.nanprod_implr  )r&   r   r  r!   r  r"   
np_nanprod  r  r  c                    sV   t | tjsd S t | jtjtjfrdd S | jt d fdd}|S )Nc                 S   
   t | S r%   )rT   r   r   r!   r!   r"   rR       
 znp_nancumprod.<locals>.<lambda>r$   c                    sD   t | j}}t| jD ]\}} | r||9 }|||< q|S r%   r   r   is_nanr  r   r!   r"   nancumprod_impl!     

z&np_nancumprod.<locals>.nancumprod_implrI   r   r   r}   r<  r  rO  )r&   r  r!   r  r"   np_nancumprod     	r  c                    sV   t | tjsd S t | jtjtjfrdd S | jt d fdd}|S )Nc                 S   r  r%   )rT   r   r   r!   r!   r"   rR  4  r  znp_nancumsum.<locals>.<lambda>r   c                    sD   t | j}}t| jD ]\}} | r||7 }|||< q|S r%   r   r   r  r   r[   r!   r"   nancumsum_impl:  r  z$np_nancumsum.<locals>.nancumsum_implr  )r&   r  r!   r  r"   np_nancumsum-  r  r  c                 C   s    t | }t|dkrtd|S )Nr   z&zero-size array reduction not possible)_asarrayr>   rp   r&   rW   r!   r!   r"   prepare_ptp_inputF  s   r  c                    s,   t |tjr fdd}|S  fdd}|S )Nc                    s4    |j | j r	|S |j | j kr |j| jr|S | S r%   r   current_valr   rz   r!   r"   r  V  s   z+_compute_current_val_impl_gen.<locals>.implc                    s    || r|S | S r%   r!   r  r  r!   r"   r  ^  s   )rI   r   r   )rz   r  r   r  r!   r  r"   _compute_current_val_impl_genO  s
   
r  c                 C      d S r%   r!   r  r!   r!   r"   _compute_a_maxc  rZ  r  c                 C   r  r%   r!   r  r!   r!   r"   _compute_a_ming  rZ  r  c                 C      t tj| |S r%   )r  operatorgtr  r!   r!   r"   _compute_a_max_implk     r  c                 C   r  r%   )r  r  ltr  r!   r!   r"   _compute_a_min_implp  r  r  c                 C   r  r%   r!   r   r!   r!   r"   _early_returnu  rZ  r  c                    sL   d t | tjr fdd}|S t | tjr fdd}|S  fdd}|S )Nr   c                    sB   t | jrt | jrdt jt jd  fS dt jd fS d fS )NT              ?y                F)rT   r   r   r   nanr  ZUNUSEDr!   r"   r  }  s
   z _early_return_impl.<locals>.implc                    s   t | r
dt jfS d fS r   )rT   r   r  r  r  r!   r"   r    s   

c                    s   d fS r   r!   r  r  r!   r"   r    r)   )rI   r   r   r   )r   r  r!   r  r"   _early_return_imply  s   r  ptpc                 C   s,   t | drt| jtjrtddd }|S )Nr}   +Boolean dtype is unsupported (as per NumPy)c           	      S   sj   t | }|j}|d }|d }t|jD ]}|| }t|\}}|r&|  S t||}t||}q|| S r   )r  r   r,   r   r  r  r  )	r&   rW   Za_flatZa_mina_maxr'   r   Ztake_branchretvalr!   r!   r"   np_ptp_impl  s   
znp_ptp.<locals>.np_ptp_impl)hasattrrI   r}   r   r<  r   )r&   r  r!   r!   r"   np_ptp  s
   
r  c                 C   s$   t | rdS t |rdS | |k S r   )rT   r   rv  r!   r!   r"   nan_aware_less_than  s
   

r  c                    s   d fdd	}|S )Nc                    s2  || d? }| | | | r+| | | | | |< | |<  r+|| || ||< ||< | | | | rP| | | | | |< | |<  rP|| || ||< ||< | | | | ru| | | | | |< | |<  ru|| || ||< ||< | | }| | | | | |< | |<  r|| || ||< ||< |}|d }	 ||k r| | |r|d7 }||k r| | |s||krЈ|| | r|d8 }||krЈ|| | s||krn%| | | | | |< | |<  r|| || ||< ||< |d7 }|d8 }q| | | | | |< | |<  r|| || ||< ||< |S Nr$   r!   )AlowhighImidZpivotr'   jargpartition	pivotimplr!   r"   
_partition  sL   z&_partition_factory.<locals>._partitionr%   r!   )r  r  r  r!   r  r"   _partition_factory  s   -r  )r  c                    s   d fdd	}|S )Nc                    s\    | |||}||kr*||k r|d } | |||}n|d } | |||}||ks| | S )zJ
        Select the k'th smallest element in array[low:high + 1].
        r$   r!   )r   kr  r  r   r'   partitionimplr!   r"   _select  s   z _select_factory.<locals>._selectr%   r!   )r  r  r!   r  r"   _select_factory  s   r  c                 C   s   	 ||ksJ t | ||}||k r|d }n%||d kr!|d }n||kr1t| |d |d | nt| |||d  nq| | | |d  fS )z
    Select the k'th and k+1'th smallest elements in array[low:high + 1].

    This is significantly faster than doing two independent selections
    for k and k+1.
    Tr$   )r  r  )r   r  r  r  r'   r!   r!   r"   _select_two  s   

r  c                 C   sP   d}|d }|d? }|d@ dkr!t | |d ||\}}|| d S t| |||S )zt
    The main logic of the median() call.  *temp_arry* must be disposable,
    as this function will mutate it.
    r   r$   rn   )r  r  )	temp_arrynr  r  Zhalfr&   r.  r!   r!   r"   _median_inner$  s   r  c                 C   r  )Nc                 S   s   |   }|jd }t||S r   )flattenrr   r  )r&   r  r  r!   r!   r"   median_impl9  s   

znp_median.<locals>.median_implr   )r&   r  r!   r!   r"   	np_median4  s   r  c                 C   s  t | }|dkrtjt || d tjd}|S tjt |tjd}tt |D ]}|| }|dkrIt| }tt|  rHt| rHtj	}n|dkrt
| }tt|  rt| tjk}t| tj k}|||  }	|	dkrytj	}|dkr|dkrtj	}|dkrtj	}|	dkr|dkr|dkrtj	}n/d|d t|d  }
t|
}|
| }t| t|d d|d d\}}|d|  ||  }|||< q'|S )Nr$   r   r  d   rn         Y@)r  r  r  )r>   rT   rt   r   r   r,   r   r  isfiniter  r   rF  inftrue_dividemathfloorr  int)r&   qr  r   r'   
percentiler   Znum_pos_infZnum_neg_infZ
num_finiteZrankfr   lowerupperr!   r!   r"   _collect_percentiles_innerC  sJ   *


 
r  c                 C   sP   |r| |  } t | dkrdS nt|rdS t | dkr&| d }t|S dS )Nr   Fr$   T)r>   rT   r?  r  )r&   nan_maskskip_nanr   r!   r!   r"   _can_collect_percentilesx  s   


r	  c                 C   s   d}| j dkr.| jdk r.t| jD ]}| | dk s&| | |ks&t| | r+d} |S q|S tt| sDt| dk sDt| |krFd}|S )NTr$   
   rD  F)ro   r   r,   rT   r   r?  )r  q_upper_boundvalidr'   r!   r!   r"   check_valid  s   &,r  c                 C      t | dds
tdd S )Nr  r  z)Percentiles must be in the range [0, 100]r  rp   r  r!   r!   r"   percentile_is_valid     r  c                 C   r  )Nr  r  z%Quantiles must be in the range [0, 1]r  r  r!   r!   r"   quantile_is_valid  r  r  c                 C   s|   t j|t jd }|| || }t j| t jd }t |}t|||r3||  }t||}|S t t|t j	}|S r  )
rT   r2  r   r  r   r	  r  rt   r>   r  )r&   r  check_qfactorr  r  r  r   r!   r!   r"   _collect_percentiles  s   


r  c                    sr   t | }t|tjrtd fdd} fdd}t|tjtjfr*|S t|tj	r7|j
dkr7|S |S )z
    The underlying algorithm to find percentiles and quantiles
    is the same, hence we converge onto the same code paths
    in this inner function implementation
    zNot supported for complex dtypec                    s   t | | d S r   r  r&   r  r  r  r  r!   r"   np_percentile_q_scalar_impl     z?_percentile_quantile_inner.<locals>.np_percentile_q_scalar_implc                    s   t | | S r%   r  r  r  r!   r"   np_percentile_impl  r  z6_percentile_quantile_inner.<locals>.np_percentile_implr   )r[  rT   r]  r^  r   rI   r   r=  r<  r   ro   )r&   r  r  r  r  r_  r  r  r!   r  r"   _percentile_quantile_inner  s   r  c                 C      t | |ddtdS )NFr  r  r  r  r  r  r  r!   r!   r"   np_percentile     
r"  c                 C   r  )NTr  r   r!  r  r!   r!   r"   np_nanpercentile  r#  r$  c                 C   r  )NFr  r   r  r  r  r!   r!   r"   np_quantile  r#  r&  c                 C   r  )NTr  r   r%  r  r!   r!   r"   np_nanquantile  r#  r'  c                    r  )Nc                    s\   t | j| j}d}t | D ]}| } |s!|||< |d7 }q|dkr)t jS t||S Nr   r$   )rT   r   r   r}   rU   rV   r  r  )r&   r  r  r   rY   r  r!   r"   nanmedian_impl  s   
z$np_nanmedian.<locals>.nanmedian_implr  )r&   r)  r!   r  r"   np_nanmedian  r  r*  c           	      C   sl   t | }t | jd d }|D ]"}| |  }d}t|d }|D ]}t|||| |}q#|||< q|S )Nr
  r   r$   )rT   
empty_likendindexrr   copyr>   _select_w_nan)	r&   	kth_arrayr   r   sr   r  r  kthr!   r!   r"   np_partition_impl_inner  s   

r2  c           
      C   s   t j| t jd}t | jd d }|D ]*}| |  }t t|}d}t|d }|D ]}	t||	||| |	}q-|||< q|S )Nr  r
  r   r$   )	rT   r+  r.   r,  rr   r-  aranger>   _arg_select_w_nan)
r&   r/  r   r   r0  r   Zidx_arryr  r  r1  r!   r!   r"   np_argpartition_impl_inner  s   
r5  c                 C   s   t |tj}|jdkrtdtt|| jd kr"tdt	|}t
|D ]\}}|dk r>|| jd  ||< q,|||< q,t|S )a  
    Returns a sorted, unique array of kth values which serve
    as indexers for partitioning the input array, a.

    If the absolute value of any of the provided values
    is greater than a.shape[-1] an exception is raised since
    we are partitioning along the last axis (per Numpy default
    behaviour).

    Values less than 0 are transformed to equivalent positive
    index values.
    r$   zkth must be scalar or 1-Dr
  zkth out of boundsr   )r  astyperT   r   ro   rp   r?  r!  rr   r+  ndenumerateunique)r&   r1  r/  r   indexr   r!   r!   r"   
valid_kths2  s   



r:  c                 C   n   t | tjtjtjfstdt | tjr| jdkrtdt|d|}t |tjtj	fs1tddd }|S )N(The first argument must be an array-liker   3The first argument must be at least 1-D (found 0-D)r}   Partition index must be integerc                 S   s.   t | }|jdkr| S t||}t||S r   )r  r   r-  r:  r2  r&   r1  Za_tmpr/  r!   r!   r"   np_partition_implc  s
   


z'np_partition.<locals>.np_partition_impl
rI   r   r   SequencerL   rE  ro   r   r<  r  )r&   r1  kthdtr@  r!   r!   r"   np_partitionU     rD  c                 C   r;  )Nr<  r   r=  r}   r>  c                 S   s4   t | }|jdkr| dS t||}t||S )Nr   r.   )r  r   r-  r6  r:  r5  r?  r!   r!   r"   np_argpartition_impl|  s
   


z-np_argpartition.<locals>.np_argpartition_implrA  )r&   r1  rC  rF  r!   r!   r"   np_argpartitionn  rE  rG  c                 C   sv   t d| t d|f}tj|tjd}t|d D ] }tt d|| d |d }d||d |f< d|||d f< q|S )Nr   r  r$   )r   rT   r   r   r,   r   )NMr  rr   r   r'   Zm_maxr!   r!   r"   	_tri_impl  s   rJ  c                 C   s   t |d ddd}|S )Nr  r   c                 S   s   |d u r| }t | ||S r%   )rJ  )rH  rI  r  r!   r!   r"   tri_impl  s   znp_tri.<locals>.tri_implr   )r   )rH  rI  r  rK  r!   r!   r"   np_tri  s   

rL  c                 C   sD   | j dksJ t| }tj||f| jd}t|D ]}| ||< q|S )zq
    Takes a 1d array and tiles it to form a square matrix
    - i.e. a facsimile of np.tile(m, (len(m), 1))
    r$   r  )ro   r>   rT   r   r}   r,   )r   Zlen_mr   r'   r!   r!   r"   _make_square  s   
rM  c                 C   s>   t j| jd | jd |dt j}t || t j| | jdS Nr
  rI  r  r  rT   trirr   r6  uintwhere
zeros_liker}   r   r  maskr!   r!   r"   np_tril_impl_2d  s   $rX  c                 C   >   t |d d	dd}d	dd}| jdkr|S | jdkrtS |S )
Nr  r   c                 S      t | }t||S r%   )rM  rX  r   r  Zm_2dr!   r!   r"   np_tril_impl_1d     
z my_tril.<locals>.np_tril_impl_1dc                 S   sv   t j| jd | jd |dt j}t | jd d }t | }t j|| jd}|D ]}t 	|| | |||< q+|S rN  
rT   rR  rr   r6  rS  r,  r+  rU  r}   rT  r   r  rW  r   zZzero_optselr!   r!   r"   np_tril_impl_multi  s   $
z#my_tril.<locals>.np_tril_impl_multir$   rn   r   )r   ro   rX  )r   r  r\  rb  r!   r!   r"   my_tril  s   



	
rd  c                 C   4   t | d t |d t|st |d ddd}|S )Nr  r  r   r   c                 S   s   t t j| ||dS )Nr  rT   nonzerorR  r  r  r   r!   r!   r"   np_tril_indices_impl  s   z-np_tril_indices.<locals>.np_tril_indices_implr   Nr   r   )r  r  r   rj  r!   r!   r"   np_tril_indices     



rm  c                 C   *   t |d | jdkrtdddd}|S )Nr  rn   input array must be 2-dr   c                 S      t j| jd || jd dS Nr   r$   )r  r   )rT   tril_indicesrr   rW   r  r!   r!   r"   np_tril_indices_from_impl  rk  z7np_tril_indices_from.<locals>.np_tril_indices_from_implrc  r   ro   r   )rW   r  ru  r!   r!   r"   np_tril_indices_from  
   


rw  c                 C   sB   t j| jd | jd |d dt j}t |t j| | jd| S NrO  r
  r$   rP  r  rQ  rV  r!   r!   r"   np_triu_impl_2d  s   (rz  c                 C   rY  )
Nr  r   c                 S   rZ  r%   )rM  rz  r[  r!   r!   r"   np_triu_impl_1d  r]  z my_triu.<locals>.np_triu_impl_1dc                 S   sz   t j| jd | jd |d dt j}t | jd d }t | }t j|| jd}|D ]}t 	||| | ||< q-|S ry  r^  r_  r!   r!   r"   np_triu_impl_multi  s   (
z#my_triu.<locals>.np_triu_impl_multir$   rn   rc  )r   ro   rz  )r   r  r{  r|  r!   r!   r"   my_triu  s   



	
r}  c                 C   re  )Nr  r  r   r   c                 S   s   t dt j| ||d d S )Nr$   rf  rg  ri  r!   r!   r"   np_triu_indices_impl  rl  z-np_triu_indices.<locals>.np_triu_indices_implrk  rl  )r  r  r   r~  r!   r!   r"   np_triu_indices  rn  r  c                 C   ro  )Nr  rn   rp  r   c                 S   rq  rr  )rT   triu_indicesrr   rt  r!   r!   r"   np_triu_indices_from_impl*  rk  z7np_triu_indices_from.<locals>.np_triu_indices_from_implrc  rv  )rW   r  r  r!   r!   r"   np_triu_indices_from!  rx  r  c                 C   r  r%   r!   rW   r!   r!   r"   _prepare_array/  rZ  r  c                 C   s   | d t jfv rdd S dd S )Nc                 S   s
   t dS )Nr!   rT   arrayr  r!   r!   r"   rR  6  r  z%_prepare_array_impl.<locals>.<lambda>c                 S   s   t |  S r%   )r  r  r  r!   r!   r"   rR  8  s    r   noner  r!   r!   r"   _prepare_array_impl3  s   r  c                 C   s~   | }	 t |tjtjfrt|S t|dd }|d ur"| dkr"tjS t|dd }|d u r0tdt |tj	r:|j
}nt|S q)NT__len__r   r}   ztype has no dtype attr)rI   r   r=  r<  r   r   rT   r   rE  rB  r}   )Zinobjobjlr_  r!   r!   r"   _dtype_of_compound;  s   r  c                 C   s   t | tjrt | jtjrtdt| }d }t|st|}d }t|s)t|}|d ur9t	||s9d}t||d urIt	||sId}t|ddd}|S )Nr  z3dtype of to_begin must be compatible with input aryz1dtype of to_end must be compatible with input aryc           
      S   s   t |}t | }t |}|j}t|dkrMtjt|t| t| d |d}t|}t|t| d }	||d |< t||||	< |||	d < |S tjt|t| |d}t|}||d |< |||d < |S )Nr   r$   r  )r  r}   r>   rT   r   diff)
aryto_endto_beginstartr  end	out_dtyper   Z	start_idxZmid_idxr!   r!   r"   np_ediff1d_implf  s&   z#np_ediff1d.<locals>.np_ediff1d_implrI  )
rI   r   r   r}   r<  r   r  r   rT   Zcan_cast)r  r  r  Zary_dtZto_begin_dtZ	to_end_dtr   r  r!   r!   r"   
np_ediff1dL  s$   
r  c                 C   r  r%   r!   r  r!   r!   r"   _select_element  rZ  r  c                 C   s,   t | dd dk}|rdd }|S dd }|S )Nro   r   c                 S   s$   t jd| jd}| |d d < |d S )Nr$   r  r   )rT   r  r}   )rW   rM  r!   r!   r"   r    s   z"_select_element_impl.<locals>.implc                 S   rj   r%   r!   r  r!   r!   r"   r    rZ  r   )rW   Zzerodr  r!   r!   r"   _select_element_impl  s   r  c                 C   r  r%   r!   )dxrM  r!   r!   r"   _get_d  rZ  r  c                 C   s    t | r
dd }|S dd }|S )Nc                 S   s
   t |S r%   rT   r2  rM  r  r!   r!   r"   r    rF   zget_d_impl.<locals>.implc                 S   s   t t | S r%   )rT   r  r2  r  r!   r!   r"   r    r  rm  )rM  r  r  r!   r!   r"   
get_d_impl  s
   r  r  c                 C   sF   t | tjtjfrtdt | tjr| jdkrtdddd}|S )Nzy cannot be a scalarr   zy cannot be 0Dr  c                 S   sX   t | }t||}|dtdd f |dtd df  d }t || d}t|}|S )N.r$   r
         @)rT   r2  r  rD   rF  r  )r  rM  r  ZyarrdZy_averet	processedr!   r!   r"   r    s   

(znp_trapz.<locals>.implNr  )rI   r   r=  r<  r   r   ro   )r  rM  r  r  r!   r!   r"   np_trapz  s   
r  c                 C   s   |j \}}|t| ksJ ||ksJ |r?t|D ]#}|dkr(d|dd|f< qt| |dd|d f |dd|f< qdS t|d ddD ]%}||d krXd|dd|f< qGt| |dd|d f |dd|f< qGdS )a*  
    Generate an N-column Vandermonde matrix from a supplied 1-dimensional
    array, x. Store results in an output matrix, out, which is assumed to
    be of the required dtype.

    Values are accumulated using np.multiply to match the floating point
    precision behaviour of numpy.vander.
    r   r$   Nr
  )rr   r>   r,   rT   rH  )rM  rH  
increasingr   r   r  r'   r!   r!   r"   
_np_vander  s   

**r  c                 C   s&   | j dkr	td|dk rtdd S )Nr$   z.x must be a one-dimensional array or sequence.r   z#Negative dimensions are not allowed)ro   rp   )rM  rH  r!   r!   r"   _check_vander_params  s
   
r  c                    sz   |d t jfvrt|t jstdd fdd	}ddd}t| t jr0t| j}t	|t
 |S t| t jt jfr;|S d S )Nz,Second argument N must be None or an integerFc                    sF   |d u rt | }t| | tjt | t|f d}t| ||| |S r  )r>   r  rT   r   r   r  )rM  rH  r  r   r  r!   r"   np_vander_impl  s   
z!np_vander.<locals>.np_vander_implc                 S   sR   |d u rt | }t| }t|| tjt | t|f|jd}t|||| |S r  )r>   rT   r  r  r   r   r}   r  )rM  rH  r  x_arrr   r!   r!   r"   np_vander_seq_impl  s   

z%np_vander.<locals>.np_vander_seq_implr   )r   r  rI   r  r   r   r   r}   rT   promote_typesr   rL   rB  )rM  rH  r  r  r  x_dtr!   r  r"   	np_vander  s   

r  c                 C   s@   t |tjtjfstddd }t | tjtjfrdd S |S )Nzshift must be an integerc                 S   sR   t | }t j|j|jd}|j}t|jD ]}|| |j }|| |j|< q|S r  )rT   r2  r   rr   r}   r   r,   r   )r&   shiftrW   r   Zarr_flatr'   r   r!   r!   r"   np_roll_impl	  s   
znp_roll.<locals>.np_roll_implc                 S   r  r%   r  )r&   r  r!   r!   r"   rR  	  r  znp_roll.<locals>.<lambda>)rI   r   r  r<  r   r=  )r&   r  r  r!   r!   r"   np_roll	  s   r     c                 C   s|  d}|}| ||d  kr|S | |d k rdS |dkr8d}||k r4| || kr4|d7 }||k r4| || ks&|d S ||d krB|d }|dk rHd}| || k ro| ||d  k rk|d }|t krj| ||t   krj|t  }n2|d S | ||d  k ry|S | ||d  k r|d S |d }||t  d k r| ||t   k r|t  }||k r||| d?  }| || kr|d }n|}||k s|d S )Nr   r$   r
     rm   rn   )LIKELY_IN_CACHE_SIZE)keyrW   lengthguessZiminZimaxr'   Zimidr!   r!   r"   binary_search_with_guess%	  sN   
r  c                 C   s  t | }t |}t |}t|dkrtdt|t|kr%td|jdkr5t j|j|d |dS t j|j|d}|j}t|}	|d }
||	d  }|	dkr|d }|d }t|D ] }|j	| }||k ro|
|j	|< q^||kry||j	|< q^||j	|< q^|S d}|	|krt j|	d |d}nt jd|d}|jrt|	d D ]2}d||d  ||   }||d  j
|| j
 | }||d  j|| j | }|d|  ||< qt|D ]}|j	| }t |r|}d}|d|  |j	|< qt|||	|}|d	kr|
|j	|< q||	kr||j	|< q||	d kr|| |j	|< q|| |kr.|| |j	|< q|jr7|| }n.d||d  ||   }||d  j
|| j
 | }||d  j|| j | }|d|  }|j
|||   || j
 }t |r|j
|||d    ||d  j
 }t |r|| j
||d  j
kr|| j
}|j|||   || j }t |r|j|||d    ||d  j }t |r|| j||d  jkr|| j}|d|  |j	|< q|S )
Nr   array of sample points is empty#fp and xp are not of the same size.r$   Z
fill_valuer}   r  r  rD  r
  )rT   r2  r>   rp   r   rt   rr   r   r,   r   r   r   r   r  )rM  xpfpr}   dzr  dydreslenxlenxplvalrvalxp_valfp_valr'   x_valr  slopesZinv_dxr   r   sloper!   r!   r"   np_interp_impl_complex_innerj	  s   




D




	$&
$&
r  c                 C   s  t j| t jd}t j|t jd}t j|t jd}t|dkr"tdt|t|kr.td|jdkr>t j|j|d |dS t j|j|d}|j}t|}	|d }
||	d  }|	dkr|d }|d }t	|D ] }|j
| }||k rx|
|j
|< qg||kr||j
|< qg||j
|< qg|S d}|	|kr|dd  |d d  |dd  |d d   }nt jd|d}t	|D ]}|j
| }t |r||j
|< qt|||	|}|dkr|
|j
|< q||	kr||j
|< q||	d kr|| |j
|< q|| |kr|| |j
|< q|jr|| }n||d  ||  ||d  ||   }||||   ||  |j
|< t |j
| r`||||d    ||d   |j
|< t |j
| r`|| ||d  kr`|| |j
|< q|S )Nr  r   r  r  r$   r  r
  )rT   r2  r   r>   rp   r   rt   rr   r   r,   r   r   r  )rM  r  r  r}   r  r  r  r  r  r  r  r  r  r  r'   r  r  r  r  r!   r!   r"   np_interp_impl_inner	  sj   

02



(&(r  c                    s   t |dr|jdkrtdt |dr|jdkrtdd}t|}t|tjr-t|t|}t|tj t tjrBt	nt
 fdd} fdd	}t| tjrdt| tjrbt||S |S )
Nro   r$   zxp must be 1Dzfp must be 1Dz:Cannot cast array data from complex dtype to float64 dtypec                    s   | || S r%   r!   rM  r  r  r}   r{   r!   r"   np_interp_implL
  r  z!np_interp.<locals>.np_interp_implc                    s   | || j d S r   r   r  r  r!   r"   np_interp_scalar_implO
  r  z(np_interp.<locals>.np_interp_scalar_impl)r  ro   r   r[  rT   r]  r^  result_typer   r  r  rI   r   r=  r   )rM  r  r  Zcomplex_dtype_msgZxp_dtZfp_dtr  r  r!   r  r"   	np_interp1
  s*   r  c                 C   s`   | j dksJ | j\}}tj|df| jd}t|D ]}t| |d d f | ||df< q|S )Nrn   r$   r  r   )ro   rr   rT   r   r}   r,   rF  )r&   r   r  r   r'   r!   r!   r"   row_wise_average]
  s   
$r  c                 C   sb   |d u r|r	d}nd}| j d | }t|d}| t| 8 } t| t| j}|td|9 }|S )Nr   r$   rD  )rr   r   r  rT   dotr   Tr  )XbiasddofZfactrX   r!   r!   r"   np_cov_impl_innerj
  s   
r  c                   C   r  r%   r!   r!   r!   r!   r"   _prepare_cov_input_inner
  rZ  r  c                 C   s&   |d t jfv rdd }|S dd }|S )Nc                 S   s   t t| }|s|j}|S r%   )rT   
atleast_2dr  r  )r   r  rowvarr}   m_arrr!   r!   r"   r  
  s   z9_prepare_cov_input_impl.<locals>._prepare_cov_input_innerc                 S   s   t t| }t t|}|s$|jd dkr|j}|jd dkr$|j}|j\}}|j\}}	||	kr6tdt j|| |f|d}
||
d |d d f< ||
| d d d f< |
S )Nr   r$   z$m and y have incompatible dimensionsr  )rT   r  r  rr   r  rp   r   )r   r  r  r}   r  y_arrZm_rowsZm_colsZy_rowsZy_colsr   r!   r!   r"   r  
  s   

r  )r   r  r  r}   r  r!   r!   r"   _prepare_cov_input_impl
  s
   "r  c                 C   s,   | j dkr| jd dkrd}t|d S d S )Nrn   r   r$   z2D array containing a single row is unsupported due to ambiguity in type inference. To use numpy.cov in this case simply pass the row as a 1D array, i.e. m[0].)ro   rr   r   )r   r   r!   r!   r"   _handle_m_dim_change
  s   r  c                 C   rj   r%   r!   rL  r!   r!   r"   rR  
  rp  rR  c                    s   t j}t| tjrt| j}|S t| tjtjfrt| }|S t| tj	tj
frbt  | D ]}t|dr> fdd|D  q- | q-t dkrVt jdd  D  }|S t dkrbt  }|S )Nr  c                    s   g | ]}  |qS r!   )add).0rY   Zcoltypesr!   r"   
<listcomp>
      z#determine_dtype.<locals>.<listcomp>r$   c                 S   s   g | ]}t |qS r!   )r   )r  tyr!   r!   r"   r  
      )rT   r   rI   r   r   r   r}   r=  r<  r?   rL   setr  r  r>   r  rs   )
array_likeZarray_like_dtr   r!   r  r"   r[  
  s&   

r[  c                 C   sx   t | tjr| jdkrtd|d S t | tjr6t | jd tjr8t | jd jd tjr:td|d S d S d S )Nrn   z{0} has more than 2 dimensionsr   )rI   r   r   ro   rE  formatrB  r  )r  namer!   r!   r"   check_dimensions
  s   
r  c                 C   s.   t | s	td| t|  dkrtdd S )Nz)Cannot convert non-finite ddof to integerr   zddof must be integral value)rT   r  rp   r   )r  r!   r!   r"   _handle_ddof
  s
   
r  c                 C   rj   r%   r!   rL  r!   r!   r"   rR  
  rp  c                 C   s   ||  || t | |||S r%   )r  )r   r  r  r}   r  _DDOF_HANDLER_M_DIM_HANDLERr!   r!   r"   _prepare_cov_input
  s   r  c                 C   s   |d t jfv }t| t jr| jdkr|S t| t jr8tdd | j D r&|S t| j dkr8t| j d t jr8|S t| t jt j	frC|S t| t j
rVt| jd t j
sV|rVdS dS )Nr$   c                 s   s"    | ]}t |tjtjfV  qd S r%   )rI   r   r=  r<  r  rM  r!   r!   r"   	<genexpr>
  s    z)scalar_result_expected.<locals>.<genexpr>r   TF)r   r  rI   r   ro   Z	BaseTupler  r>   r=  r<  rB  r  )Zmandatory_inputZoptional_inputZopt_is_noner!   r!   r"   scalar_result_expected
  s(   r  c                 C   s   t t | dkt | | S r  )rT   rT  fabssignrL  r!   r!   r"   
_clip_corr  s   r  c                 C   s    t | j}t | j}|d|  S )Nr  )r  r   r   )rM  r   r   r!   r!   r"   _clip_complex  s   

r  c           	         s   t | d t |d |d tjfv rt nt|tjtjfr t nt|tjr)t nt	dt
t| tjr7tt| }t|}t||tjd
 fdd	}		 d
 fdd		}t| |rb|S |S )Nr   r  z)ddof must be a real numerical scalar typeTFc                    s^   t | ||| }tt|jdkr)tj|jd |jd ftjdS t|||S )Nr   r  )	r  r6  rT   r?  r  rr   rt   r  r  )r   r  r  r  r  r  r  r  r}   r!   r"   np_cov_impl2  s   znp_cov.<locals>.np_cov_implc                    sT   t | ||| }tt|jdkrtj}n	t|||jd }t|S r   )	r  r6  rT   r?  r  rr   r  r  r   )r   r  r  r  r  r  Zvariancer  r!   r"   np_cov_impl_single_variable<  s   
z+np_cov.<locals>.np_cov_impl_single_variableNTFN)r  r   r  _handle_ddof_noprI   r  r<  r   r  r   _handle_m_dim_nopr   r  r[  rT   r  r   r  )	r   r  r  r  r  Zm_dty_dtr  r  r!   r  r"   np_cov  s,   



r  c                    s^   t | }t |}t||tj}|tjkrt nt d fdd	}ddd}t| |r-|S |S )NTc                    sp   t | ||}t |}t |j}t|jd D ]}||d d f  |  < |d d |f  |  < q |S r   )rT   covZdiagsqrtr   r,   rr   )rM  r  r  rX   r  Zstddevr'   Zclip_fnr!   r"   np_corrcoef_implZ  s   
z%np_corrcoef.<locals>.np_corrcoef_implc                 S   s   t | ||}|| S r%   )rT   r   )rM  r  r  rX   r!   r!   r"    np_corrcoef_impl_single_variablee  s   z5np_corrcoef.<locals>.np_corrcoef_impl_single_variableNT)r[  rT   r  r   Zcomplex_r  r  r  )rM  r  r  r  r  r}   r  r  r!   r  r"   np_corrcoefN  s   


r  c                    sD   t | tjtjf}t| r|sdd }|S d d fdd}|S )Nc                 S   s:   t | }|jdkrt jdtjdS t t t |S )Nr!   )r   r$   r  )	rT   r2  rr   r  r   r.   r  Zvstackrh  r  r!   r!   r"   r  z  s   

znp_argwhere.<locals>.impl)r   r   )r$   r   c                    s0   | d urt | rtjtjdS tj tjdS r  )r;  rT   r  r   r.   r   ZfalseishZtrueishr!   r"   r    s   )rI   r   r=  r<  r	   )r&   Z
use_scalarr  r!   r  r"   np_argwheres  s   r  c                 C   s    t | r
dd }|S dd }|S )Nc                 S   s   t | }t t |d S r   )rT   r2  rh  r  r  r!   r!   r"   r    s   
znp_flatnonzero.<locals>.implc                 S   s:   | d urt | rdg}n	dd tdD }tj|tjdS )Nr   c                 S   s   g | ]}|qS r!   r!   r  r!   r!   r"   r    rS  z0np_flatnonzero.<locals>.impl.<locals>.<listcomp>r  )r;  r,   rT   r  r   r.   )r&   r8   r!   r!   r"   r    s   rT  )r&   r  r!   r!   r"   np_flatnonzero  s
   r	  c                 C   s   | j dkr(| jd }| jd }d| }|r|| }||fS |t|| }||fS t| j}tt|dks<tddt|d d 	  }|
 }||fS )Nrn   r   r$   z/All dimensions of input must be of equal lengthr
  )ro   rr   r   rT   r  r  r  rp   r   rF  r   )r&   wrapr   r  stepr  rr   r!   r!   r"   _fill_diagonal_params  s   



r  c                 C   s.   t | |\}}td||D ]}|| j|< qd S r   )r  r,   r   )r&   r   r
  r  r  r'   r!   r!   r"   _fill_diagonal_scalar  s   r  c                 C   sN   t | |\}}d}t|}td||D ]}|| | j|< |d7 }|| }qd S r(  )r  r>   r,   r   )r&   r   r
  r  r  ZctrZv_lenr'   r!   r!   r"   _fill_diagonal  s   
r  c                 C   sR   t | j}|j}|j}t t | s#t ||k s#t ||kr'tdd S Nz'Unable to safely conform val to a.dtype)rT   iinfor}   r   r   r?  r  rp   )r&   r   r  v_minv_maxr!   r!   r"   _check_val_int  s   .r  c                 C   sN   t | j}|j}|j}|t | }t ||k s!t ||kr%tdd S r  )rT   finfor}   r   r   r  r?  rp   )r&   r   r  r  r  Zfinite_valsr!   r!   r"   _check_val_float  s   r  c                 C   rj   r%   r!   rM  r  r!   r!   r"   rR    rp  c                 C   r  r%   r!   rL  r!   r!   r"   r    rZ  r  c                    sX   t | tjr
dd S t | tjtjfrdd S t | tjtjfr*t|   fddS d S )Nc                 S   rj   r%   r!   rL  r!   r!   r"   rR    rp  z_asarray_impl.<locals>.<lambda>c                 S   r  r%   r  rL  r!   r!   r"   rR    r  c                    s   t j| g dS r  r  rL  r  r!   r"   rR    rS  )rI   r   r   rB  rL   r=  r<  r   rL  r!   r  r"   _asarray_impl  s   r  c                    s   | j dkrEt| jtjrt nt| jtjrt nt d fdd	}d fdd	}t|tjtjtj	fr6|S t|tj
tjtjfrC|S d S d| j  }t|)	Nr$   Fc                    s&   t | } | | t| || d S r%   )r  r  r  r&   r   r
  tmpvalcheckerr!   r"   scalar_impl      
z%np_fill_diagonal.<locals>.scalar_implc                    s&   t | } | | t| || d S r%   )r  r  r  r  r  r!   r"   non_scalar_impl  r  z)np_fill_diagonal.<locals>.non_scalar_implz4The first argument must be at least 2-D (found %s-D)F)ro   rI   r}   r   r  r  r   r  
_check_nopr<  rL   rB  r   r   )r&   r   r
  r  r  r   r!   r  r"   np_fill_diagonal  s   

r"  c                 C   s   d| j f S )Nzllvm.rint.f%d)r   )tpr!   r!   r"   _np_round_intrinsic  s   r$  c                 C   s   ||}dd }||fS )Nc                 S   s`   |\}|j d }| |}|j}tj||g}t||t|}	|	|	|f}
t
| ||j|
S r   )r4   r*   modulellvmliteZirFunctionTyper   Zget_or_insert_functionr$  callr   rb   )re   r2   rf   r4   r   r#  Zlltyr%  Zfntyrj  rg   r!   r!   r"   r=     s   

z _np_round_float.<locals>.codegenr!   )Z	typingctxr   rf   r=   r!   r!   r"   _np_round_float  s   r)  c                 C   s   t | s
t | r| S |dkr8|dkrd|d  }d}nd| }d}| | | }t |r0| S t|| | S d|  }| | }t|| S )Nr      g      $@gMDr  )r  r   r   r)  )rM  ndigitsZpow1Zpow2r  r!   r!   r"   round_ndigits*  s   

r,  c                 C   s   t | stdt|tjst|sd}t|t| tjtjtjfrWt|rPt| tjr4ddd}|S t| tjrAddd}|S t| tjrNddd}|S d S ddd}|S t| tjrot|rhdd	d}|S dd
d}|S d S )Nz#The argument "a" must be array-likez5The argument "out" must be an array if it is providedr   c                 S   s   |dkrt | S t| |S r   )r)  r,  r&   decimalsr   r!   r!   r"   r  S  s   
zimpl_np_round.<locals>.implc                 S   s   |dkr| S t t| |S r   )r   r,  r-  r!   r!   r"   r  Z  s   c                 S   s@   |dkrt | j}t | j}nt| j|}t| j|}t||S r   )r)  r   r   r,  complex)r&   r.  r   r   r   r!   r!   r"   r  a  s   

c                 S   s   t | ||d< |S r   )rT   roundr-  r!   r!   r"   r  k  s   c                 S   s   t | }t | ||S r%   )rT   r+  r0  r-  r!   r!   r"   r  q     
c                 S   s<   | j |j kr
tdt| D ]\}}t||||< q|S )Nzinvalid output shape)rr   rp   rT   r7  r0  )r&   r.  r   r9  r   r!   r!   r"   r  v  s
   rk  )	r	   r   rI   r   r   r   r   r  r   )r&   r.  r   r   r  r!   r!   r"   impl_np_roundE  s4   





r2  c                 C   s8   t | tjrdd }|S t | tjrdd }|S td)Nc                 S   s$   | dkrd} | t j9 } t | |  S )NrD  g#B;)rT   pisinrL  r!   r!   r"   r    s   
zimpl_np_sinc.<locals>.implc                 S   s0   t | }t | D ]\}}t |||< q
|S r%   )rT   rU  r7  sinc)rM  r   r9  r   r!   r!   r"   r    s   
z,Argument "x" must be a Number or array-like.)rI   r   r=  r   r   ra  r!   r!   r"   impl_np_sinc  s   r6  c                    s   t dtj  t| tjrd fdd	}|S t| tjr=| j}t|tjr)|j	nt|tj
r2|nd S dfdd	}|S td|  )N   Fc                    s(   |rt | j| j  S t | j| jS r%   )rT   Zarctan2r   r   )r`  deg)deg_multr!   r"   r    s   zov_np_angle.<locals>.implc                    s6   t j|  d}t | D ]\}}t ||||< q|S r  )rT   rU  r7  angle)r`  r8  r   r9  r   )	ret_dtyper!   r"   r    s   z6Argument "z" must be a complex or Array[complex]. Got r   )r:  rT   r3  rI   r   r=  r   r}   r   Zunderlying_floatr   r   )r`  r8  r  r}   r!   )r9  r;  r"   ov_np_angle  s    r<  zarray.nonzeroc                    s  |j d }|j}|j|j}t| |d }t |j}t |j}	|j	}
|j
}tjd}tjd}t |}t ||jD}t |
||	||}t ||} |j|} |    ||| W d    n1 sw   Y  W d    n1 sw   Y   |f fddt|D } fdd|D }dd |D }t |}t ||jk}t |
||	||}t ||} |j|} |; |s|f} |}t|D ]}t || dd|g}t || | q  ||| W d    n	1 s'w   Y  W d    n	1 s7w   Y   |j|}t |j|S )	Nr   r$   c                    s   g | ]}t   qS r!   )r   Z	_getvalue)r  r'   r2   re   	out_shapeoutarytyr!   r"   r    s    z!array_nonzero.<locals>.<listcomp>c                    s   g | ]
}t  |qS r!   )r   r  r   )r2   re   r?  r!   r"   r    s    c                 S   s   g | ]}|j qS r!   )r8   r@  r!   r!   r"   r    s    r!   C)r4   rb   r}   r  r   r   Zunpack_tuplerr   stridesr8   layoutr-   r   r.   Zalloca_once_valueZ	loop_nestru   Zget_item_pointer2r   Zis_trueZif_thenstorer  loadr,   r   Z
make_tupler   )re   r2   rf   r4   Zarytyr   Znoutsr  rr   rB  r8   rC  r[   r  r  indicesZptrr   ZnzZoutsZoutarysZ	out_datasr9  curr'   r6   r!   r=  r"   array_nonzero  sh   
	
rH  c                        fdd}|S )Nc                    s,   t | }t | }| r|S |S r%   )rT   r2  r6  )	conditionrM  r  x_y_r  r!   r"   r    s   z)_where_zero_size_array_impl.<locals>.implr!   r}   r  r!   r  r"   _where_zero_size_array_impl  s   rN  c                 C   s0   t | D ]\}}|r|| n|| ||< q|S r%   )rT   r7  )condrM  r  rg   r   rX   r!   r!   r"   _where_generic_inner_impl  s   rP  c           	      C   sH   | j }|j }|j }|j }t| jD ]}|| r|| n|| ||< q|S r%   )r   r,   r   )	rO  rM  r  rg   cfZxfZyfrfr'   r!   r!   r"   _where_fast_inner_impl  s   rS  c                    s$   dhdhfv  fdd}|S )NrA  Fc                    s   t | t |t |}}}t |j|j|j}t ||}t ||}t ||}	dkr?t j|d d d  dj}
nt j| d}
rOt|||	|
S t|||	|
S )NrT  r
  r  )	rT   r2  r  rr   r  r   r  rS  rP  )rJ  rM  r  Zcond1x1y1rr   Zcond_rK  rL  rg   r}   rC  Zuse_faster_implr!   r"   r    s   "z!_where_generic_impl.<locals>.implr!   )r}   rC  r  r!   rW  r"   _where_generic_impl  s   rX  c                 C   s    t | s
d}t|dd }|S )N+The argument "condition" must be array-likec                 S   s   t |  S r%   )rT   r2  rh  )rJ  r!   r!   r"   where_cond_none_none%  r  z)ov_np_where.<locals>.where_cond_none_none)r	   r   )rJ  r   rZ  r!   r!   r"   ov_np_where  s
   r[  c                    s   t | s
d}t|t|st|rtdt||fdD ]\}}t |s.d}t||qt| tj}t|tj}t|tj}|rt|}	t|}
t	
|	|
}dd  t fdd| ||fD }|rit|S | j}|r|r|j|j  kr}| jkrn n|j}nd	}t||S d
d }|S )NrY  z"Argument "x" or "y" cannot be Noner  z0The argument "{}" must be array-like if providedc                 S   s"   t | tjpt | tjo| jdkS r   )rI   r   r=  r   ro   argr!   r!   r"   check_0_dimL  s   z$ov_np_where_x_y.<locals>.check_0_dimc                    s   g | ]} |qS r!   r!   )r  r&   r^  r!   r"   r  O  r  z#ov_np_where_x_y.<locals>.<listcomp>r  c                 S   s    t t | t |t |S r%   )rT   rT  r2  )rJ  rM  r  r!   r!   r"   r  [  s    zov_np_where_x_y.<locals>.impl)r	   r   r   zipr  rI   r   r   r[  rT   r  r  rN  rC  rX  )rJ  rM  r  r   r]  r  Zcond_arrr  r  r  r  r}   Zspecial_0_caserC  r  r!   r_  r"   ov_np_where_x_y*  s:   
ra  c                 C   r  )Nc                 S      | j S r%   )r   r  r!   r!   r"   np_real_implb     znp_real.<locals>.np_real_implr!   )r   rc  r!   r!   r"   np_real`     re  c                 C   r  )Nc                 S   rb  r%   )r   r  r!   r!   r"   np_imag_implj  rd  znp_imag.<locals>.np_imag_implr!   )r   rg  r!   r!   r"   np_imagh  rf  rh  c                 C   s   t | tjsd S dd }|S )Nc                 S   s"   t | D ]	}||kr dS qdS r   )rT   rU   )rW   r  rM  r!   r!   r"   np_contains_implx  r  z%np_contains.<locals>.np_contains_implr   )rW   r  ri  r!   r!   r"   np_containss  s   rj  c                 C   s4   t | stdt|rddd}|S ddd}|S )Nz3The argument to np.count_nonzero must be array-likec                 S   s   t | }t |dkS r   )rT   r  rF  r&   rN   Zarr2r!   r!   r"   r    r1  znp_count_nonzero.<locals>.implc                 S   s   |  tj}tj||dS )N)rN   )r6  rT   r   rF  rk  r!   r!   r"   r    s   r%   )r	   r   r   )r&   rN   r  r!   r!   r"   np_count_nonzero  s   

rl  c                 C   rj   r%   r!   rL  r!   r!   r"   rR    rp  c                 C   r  r%   r  rL  r!   r!   r"   rR    r  c                    s   t | tjtjfstdt |tjtjtjfr6t |tjr!t nt |jtjs,tdt	  fdd}|S t |tjs@tddd }|S )Nz)arr must be either an Array or a Sequencezobj should be of Integer dtypec                    s>   t t | } | j}t j|t jd} |}d||< | | S )Nr  F)rT   r  r2  r   onesr   )rW   r  rH  Zkeephandlerr!   r"   np_delete_impl  s   z!np_delete.<locals>.np_delete_implc                 S   sf   t t | } | j}|}|| k s||krtd|dk r"||7 }t | d | | |d d  fS )Nz"obj must be less than the len(arr)r   r$   )rT   r  r2  r   
IndexErrorconcatenate)rW   r  rH  posr!   r!   r"   np_delete_scalar_impl  s   "z(np_delete.<locals>.np_delete_scalar_impl)
rI   r   r   rB  r   Z	SliceTypenp_delete_handler_isslicer}   r  np_delete_handler_isarray)rW   r  rp  rt  r!   rn  r"   	np_delete  s   rw  r$   c                 C   s(   t | tjr| jdkrd S ddd}|S )Nr   r$   c                 S   s0  |dkr|   S |dk rtd| jd }| jd d t|| df }t|| j}|jdkr2|S | d|f}|d|jd f}t|| j}t	|jd D ]D}t	|d D ]}	|||	d f |||	f  ||	< qYt	d|D ]}
t	||
 d D ]}	||	d  ||	  ||	< q{qq|d ||  ||< qQ|S )Nr   z"diff(): order must be non-negativer
  r$   )
r-  rp   rr   r   rT   r   r}   r   r  r,   )r&   r  r   r>  r   a2Zout2Zworkmajorr'   Zniterr!   r!   r"   	diff_impl  s*   

"znp_diff_impl.<locals>.diff_implr  )rI   r   r   ro   )r&   r  rz  r!   r!   r"   np_diff_impl  s   
r{  c                 C   sP   t | rt |stdtjtjf}t| |r"t||r"dd }|S dd }|S )Nz3Both arguments to "array_equals" must be array-likec                 S   s   | |kS r%   r!   )a1rx  r!   r!   r"   r    r)   znp_array_equal.<locals>.implc                 S   s2   t | }t |}|j|jkrt ||kS dS r   )rT   r2  rr   r  )r|  rx  r&   r.  r!   r!   r"   r    s
   

)r	   r   r   r<  r=  rI   )r|  rx  acceptedr  r!   r!   r"   np_array_equal  s   
r~  c                 C   s$   t | st |stddd }|S )Nz.intersect1d: first two args must be array-likec                 S   sj   t | } t |}t | } t |}t | |f}|  |dd  |d d k}|d d | }|S )Nr$   r
  )rT   r2  r8  rr  sort)ar1ar2ZauxrW  Zint1dr!   r!   r"   np_intersects1d_impl
  s   



z0jit_np_intersect1d.<locals>.np_intersects1d_implr	   r   )r  r  r  r!   r!   r"   jit_np_intersect1d  s   r  c                 C   sF   t |tjr|jdkrtd| d S t |tjs!td| d S )Nr$   z${0}(): input should have dimension 1z+{0}(): input should be an array or sequence)rI   r   r   ro   rE  r  rB  )	func_nameseqr!   r!   r"   validate_1d_array_like  s   
r  c                    s   t d|  t| jtjsd S t|d |d tjfvr/t d| tjt	dd t	dd  ntj
t	dd t	dd  d fd
d	}|S )Nbincount	minlengthc                 S   s   t | t |krtdd S )Nz7bincount(): weights and list don't have the same length)r>   rp   r&   rB  r  r!   r!   r"   validate_inputs2  s   z$np_bincount.<locals>.validate_inputsc                 S   s   | |  || 7  < d S r%   r!   r   r   r   rB  r!   r!   r"   
count_item8     znp_bincount.<locals>.count_itemc                 S   r  r%   r!   r  r!   r!   r"   r  ?  rl   c                 S   s   | |  d7  < d S r  r!   r  r!   r!   r"   r  C  s   r   c                    s   | || |dk rt dt| }|dkr| d nd}td|D ]}| | dk r-t dt|| | }q!t|d |}t|}t|D ]} ||| | | qF|S )Nr   z 'minlength' must not be negativer
  r$   z/bincount(): first argument must be non-negative)rp   r>   r,   r   rT   r  )r&   rB  r  r  r  r'   Z
out_lengthr   r  r  r  r!   r"   bincount_implG  s   z"np_bincount.<locals>.bincount_implr   )r  rI   r}   r   r  r   r  rT   r   r   r.   )r&   rB  r  r  r!   r  r"   np_bincount#  s$   





r  c                    rI  )Nc                    s   t |rt|ddD ]}t | |d  s|  S qdS ||k r$|}nd}||k r.|d n|}||krL|| d? } | | |rF|d }n|}||ks4|S )a  Perform inner loop of searchsorted (i.e. a binary search).

        This is loosely based on the NumPy implementation in [1]_.

        Parameters
        ----------
        a: 1-D array_like
            The input array.
        v: array_like
            The current value to insert into `a`.
        v_last: array_like
            The previous value inserted into `a`.
        lo: int
            The initial/previous "low" value of the binary search.
        hi: int
            The initial/previous "high" value of the binary search.
        n: int
            The length of `a`.


        .. [1] https://github.com/numpy/numpy/blob/809e8d26b03f549fd0b812a17b8a166bcd966889/numpy/core/src/npysort/binsearch.cpp#L173
        r   r
  r$   )rT   r   r,   )r&   rY   v_lastlohir  r'   r  funcr!   r"   searchsorted_inner^  s"   

z)_searchsorted.<locals>.searchsorted_innerr!   )r  r  r!   r  r"   _searchsorted]  s   .r  c                 C   s   | |kS r%   r!   r  r!   r!   r"   rR    s    leftc                    s   t |d|}|dkrt n|dkrt ntd| t|tjr*d	 fdd	}|S t|tjr9d	 fdd	}|S d	 fdd	}|S )
NrK   r  rightz Invalid value given for 'side': c           
         sn   t | }d}|}t|jtj}|jd }t||fD ]\}}	 | | ||||}| }|	| q|S r   )	r>   rT   r   rr   r.   r   rU   rV   itemset)
r&   rY   sider  r  r  r   r  r   outviewZ	loop_implr!   r"   searchsorted_impl  s   
z'searchsorted.<locals>.searchsorted_implc           	         sf   t | }d}|}tt |tj}|d }tt |D ]} | || ||||}|||< || }q|S r   )r>   rT   r   r.   r,   )	r&   rY   r  r  r  r  r   r  r'   r  r!   r"   r    s   
c                    s   t | } | ||d||S r   )r>   )r&   rY   r  r  r  r!   r"   r    s   r  )r   _searchsorted_left_searchsorted_rightr   rI   r   r   rB  )r&   rY   r  Zside_valr  r!   r  r"   searchsorted  s    r  c                    sl   t dd  t dd t dd t| tjr#d fdd		}|S t| tjr4d fd
d		}|S d S )Nc                 S   sl   t | }d}d}|dkr4| d }td|D ]}| | }|o!||k }|o(||k  }|s1|s1td|}q|S )NTr$   r   z3bins must be monotonically increasing or decreasing)r>   r,   rp   )binsr  is_increasingZis_decreasingprevr'   rG  r!   r!   r"   are_bins_increasing  s   z(np_digitize.<locals>.are_bins_increasingc                 S   s   t |}d}|}|rDt| r't|ddD ]}t||d  s$|  S qdS ||krB|| d? }|| | k r<|d }n|}||ks+|S t| rK|S ||krf|| d? }|| | kr`|d }n|}||ksO|S )Nr   r
  r$   r>   rT   r   r,   rM  r  r  r  r  r  r'   r  r!   r!   r"   digitize_scalar  s4   



	z$np_digitize.<locals>.digitize_scalarc                 S   s   t |}d}|}|rAt| r$td|D ]}t|| s!|  S q|S ||kr?|| d? }|| | k r7|}n|d }||ks(|S t| rHdS ||krc|| d? }|| | kr[|}n|d }||ksL|S r(  r  r  r!   r!   r"   digitize_scalar_decreasing   s4   

	z/np_digitize.<locals>.digitize_scalar_decreasingFc                    sd    |}t | jt j}t | |fD ]\}}|r"| ||}n| ||}|| q|S r%   )rT   r   rr   r.   rU   rV   r  )rM  r  r  r  r   r   r  r9  r  r  r  r!   r"   digitize_impl(  s   z"np_digitize.<locals>.digitize_implc                    s^    |}t t| t j}tt| D ]}|r"| | ||||< q| | ||||< q|S r%   )rT   r   r>   r.   r,   )rM  r  r  r  r   r'   r  r!   r"   r  8  s   r   )r   rI   r   r   rB  )rM  r  r  r  r!   r  r"   np_digitize  s   

%
$
r  r
  c                    sT   t |ttjfr#|d tjfv rtd d fdd	}|S ddd}|S ddd}|S )Nr  r
  c                    sL    }  }t | D ]}| }||kr|}||k r|}q
t | |||fS r%   )rT   rU   rV   	histogram)r&   r  r,   bin_minbin_maxr   rY   r  r!   r"   histogram_implQ  s   z$np_histogram.<locals>.histogram_implc                 S   s   |dkrt d|\}}||kst dt|tj}||kr_|||  }t| D ]4}| }t|| | }	d|	  krC|k rPn n|t|	  d7  < q*||kr^||d   d7  < q*t	|||d }
||
fS )Nr   z0histogram(): `bins` should be a positive integerz;histogram(): max must be larger than min in range parameterr$   )
rp   rT   r  r.   rU   rV   r  r  r   Zlinspace)r&   r  r,   r  r  histZ	bin_ratior   rY   r.  Z
bins_arrayr!   r!   r"   r  ]  s$   c                 S   s   t |d }t|D ]}|| ||d  kstdq
|d }|| }t|tj}|dkrqt| D ]=}| }	||	  krC|ksEn q3d}
|d }|
|k rh|
| d d? }|	|| k rb|d }n|}
|
|k sO||
  d7  < q3||fS )Nr$   z-histogram(): bins must increase monotonicallyr   )r>   _rangerp   rT   r  r.   rU   rV   )r&   r  r,   Znbinsr'   r  r  r  r   rY   r  r  r  r!   r!   r"   r  w  s.   
r
  N)rI   r   r   r  r  r:  )r&   r  r,   r  r!   r  r"   np_histogramH  s   G
;
!r  )Zibetar   machepepsnegepepsnegiexpminexpZxminmaxexpZxmaxZirndZngrdepsilontinyZhuge	precision
resolutionMachAr)r  r  r  r  r   r  r   r  r  ZnexpZnmantr  r  r  bitsr  )r   r   r  r  c                     sr   t dkrd S d tjddd} tjd| tdd tj W d    n1 s'w   Y  t  fdd	}d S )
N)r$      T)recordz(`np.MachAr` is deprecated \(NumPy 1.22\)alwaysz.*numba.*arraymath)messagecategoryr%  c                     sT    t fddtD  r"d } t| jjd t| j| j  fdd}|S )Nc                       g | ]}t  |qS r!   r  r  r  r!   r"   r    r  z7_gen_np_machar.<locals>.MachAr_impl.<locals>.<listcomp>r   c                      s   t   S r%   )r  r!   )_mach_ar_datar!   r"   r    r)   z1_gen_np_machar.<locals>.MachAr_impl.<locals>.impl)	r  _mach_ar_supportedwarningswarn_explicitr  r4   r   filenamelineno)Zwmsgr  Z	np_MachArw)r  r  r"   MachAr_impl  s   z#_gen_np_machar.<locals>.MachAr_impl)r   r  catch_warningsfilterwarningsDeprecationWarningrT   r  r   )r   r  r!   r  r"   _gen_np_machar  s   r  c                    sb   t | d| }t|}z||W n
 ty   Y d S w tfdd|D t fdd}|S )Nr}   c                    r  r!   r  r  r  r!   r"   r    r  z'generate_xinfo_body.<locals>.<listcomp>c                    s     S r%   r!   r\  )	containerr8   r!   r"   r    r   z!generate_xinfo_body.<locals>.impl)r   r   rp   r  r   )r]  Znp_funcr  attrZnbtyZnp_dtyper  r!   )r  r8   r  r"   generate_xinfo_body  s   r  c                        t | tjtt  fdd}|S )Nc                    r   r%   r!   r  ri  r!   r"   r    r)   zol_np_finfo.<locals>.impl)r  rT   r  _finfo_supportedrM  r!   ri  r"   ol_np_finfo     r  c                    r  )Nc                    r   r%   r!   )int_typeri  r!   r"   r    r)   zol_np_iinfo.<locals>.impl)r  rT   r  _iinfo_supported)r  r  r!   ri  r"   ol_np_iinfo  r  r  c                    sh   t dd }ts
|S tjtjB }| |v o||v }|s|S t| }t|}t|| t  fdd}|S )Nc                 S   s.   d}t t| D ]}|| | ||   }q|S r   r,   r>   )r&   r.  accr'   r!   r!   r"   
_innerprod  s   z#_get_inner_prod.<locals>._innerprodc                    s   t |  | S r%   )rT   r  r6  rv  r_  r!   r"   	_dot_wrap  r  z"_get_inner_prod.<locals>._dot_wrap)r   
_HAVE_BLASr   Zreal_domaincomplex_domainr   rT   r  )ZdtaZdtbr  ZfltyZfloatsa_dtb_dtr  r!   r  r"   _get_inner_prod  s   
r  c                 C   s*   t | tjr| jdkstd| d S d S )Nr$   z!%s() only supported on 1D arrays )rI   r   r   ro   r   )r&   r  r!   r!   r"   
_assert_1d  s
   
r  c                 C   r  r%   r!   )ap1ap2mode	directionr!   r!   r"   _np_correlate_core  rZ  r  c                    s@   t | j}t |j}t|| t| j|j fdd}|S )Nc                    s  t | }t |}||k rtd|}|}|dkr#|| d }d}d}	n&|dkr6|d }	|d }|| d }n|dkrE|d }|| d }	ntdt| }
|dkrXd}d}n|d	krc|d }d	}ntd
t|D ]}|| | }| d | || d  |
|< || }qkt|| d D ]}| |||  ||
|< || }qt|	D ]}|| d }| | d  |d | |
|< || }q|
S )Nz''len(ap1)' must greater than 'len(ap2)'r  r$   r   rt   Zsamern   z1Invalid 'mode', valid are 'full', 'same', 'valid'r
  zInvalid direction)r>   rp   rT   r  r,   )r  r  r  r  Zn1Zn2r  r  Zn_leftZn_rightr  r   incr'   r  r_  Z	innerprodr!   r"   r  &  sP   	 

 
z%_np_correlate_core_impl.<locals>.impl)r   r}   rT   r  r  )r  r  r  r  r  r  r  r!   r  r"   _np_correlate_core_impl  s   

@r  r  c                    s   t | d t |d tdd }tdd }| jtjv r,|jtjv r'| |n| |n|jtjv r7| |n| |d	 fdd	}|S )
Nznp.correlatec                 S   r  r%   )rT   r   rL  r!   r!   r"   op_conjn  s   
z_np_correlate.<locals>.op_conjc                 S   rj   r%   r!   rL  r!   r!   r"   op_nopr  rl   z_np_correlate.<locals>.op_nopr  c                    sd   t | }t |}|dkrtd|dkrtd||k r't| | |dS t | ||dS Nr   z'a' cannot be emptyz'v' cannot be emptyr
  r$   r>   rp   r  r&   rY   r  ZlalvZa_opZb_opr!   r"   r    s   z_np_correlate.<locals>.implr  )r  r   r}   r   r  )r&   rY   r  r  r  r  r!   r  r"   _np_correlatei  s&   



r  rt   c                 C   s"   t | d t |d ddd}|S )Nznp.convolvert   c                 S   sh   t | }t |}|dkrtd|dkrtd||k r(t|| d d d |dS t| |d d d |dS r  r  r  r!   r!   r"   r    s   znp_convolve.<locals>.implrt   )r  )r&   rY   r  r  r!   r!   r"   np_convolve  s   


r   c                    s6  t | sd S d }t| tjr&t|s| j|jkrd
dd}|S d
dd}|S t| tjtjfrAt|r:d
dd}|S d
dd}|S t| tjtj	fr_t|rP| n|}t
|d
fdd	}|S t| tjjrt| jtjtj	fsttdt|r{| jn|d
fdd	}|S t| tjrt| j d
 fd	d	}|S )Nc                 S   rj   r%   r!   r&   r}   r!   r!   r"   r    rZ  znp_asarray.<locals>.implc                 S   s
   |  |S r%   )r6  r  r!   r!   r"   r    rF   c                 S   r  r%   r  r  r!   r!   r"   r    rF   c                 S   s   t | |S r%   r  r  r!   r!   r"   r    r   c                       t |  S r%   r  r  r  r!   r"   r    r   z?asarray support for List is limited to Boolean and Number typesc                    s4   t | }tj| d}t| D ]\}}|||< q|S r  )r>   rT   r   r   )r&   r}   r  r  r'   rY   )target_dtyper!   r"   r    s
   
c                    s      S r%   )r-  r  r  r!   r"   r    r)   r%   )r	   rI   r   r   r   r}   rB  rL   r=  r<  r   
containersZListTyper   ZStringLiteralrT   r2  rK   )r&   r}   r  Zdt_convr!   )rW   r  r  r"   
np_asarray  s@   
)
&

r  c                    sD   t |tjr
t|}t|tjstj n| tjf fdd	}|S )Nc                    r  r%   r  r  r  r!   r"   r    r   znp_asfarray.<locals>.impl)rI   r   Typer   rT   r]  Zinexactr   )r&   r}   r  r!   r  r"   np_asfarray  s   r  c                 C   s   dd }|S )Nc                    s   t |  t |  jdkrtdt  jd  r+j jkr+d}t|t jj} fddt|D }t |S )Nr   z"Cannot extract from an empty arrayz+condition shape inconsistent with arr shapec                    s   g | ]}| r j | qS r!   r  )r  r   r&   rO  r!   r"   r    s    z7np_extract.<locals>.np_extract_impl.<locals>.<listcomp>)	rT   r2  r  r   rp   r?  r   r,   r  )rJ  rW   r   max_lenr   r!   r	  r"   np_extract_impl  s   

 
z#np_extract.<locals>.np_extract_implr!   )rJ  rW   r  r!   r!   r"   
np_extract  s   r  c                 C   sF  ddd}t | tjtjfstdt |tjtjfstdt |ttjtjfs-tdt | d tjs9tdt |d tjsEtdt | d tjrZt | d j	tjsZtd	t | d tjrxt | d tjrtt | d d tjsxtd
t | d tjr| d j
|d j
krtdt | d tjr| d j
dk rtd|S )Nr   c                 S   sp   t | t |krtd|t|d j|d j }tt | d ddD ]}| | }|| }t|||}q$|S )Nz7list of cases must be same length as list of conditionsr   r$   r
  )r>   rp   rT   rm  rr   r}   r,   rT  )condlist
choicelistdefaultr   r'   rO  choicer!   r!   r"   np_select_arr_impl  s   z%np_select.<locals>.np_select_arr_implz"condlist must be a List or a Tuplez$choicelist must be a List or a Tuplez,default must be a scalar (number or boolean)z items of condlist must be arraysz"items of choicelist must be arraysz%condlist arrays must contain booleansz*condlist tuples must only contain booleanszHcondlist and choicelist elements must have the same number of dimensionsr$   z/condlist arrays must be of at least dimension 1rc  )rI   r   Listr?   r   r   r=  r<  r   r}   ro   )r  r  r  r  r!   r!   r"   	np_select  s2   
r  c                 C   sT   t | rt |stdd| jjv sd|jjv r$| jj|jjkr$tddd }|S )Nz.The arguments to np.union1d must be array-likeunichrz/For Unicode arrays, arrays must have same dtypec                 S   s4   t t | }t t |}t t ||fS r%   )rT   r  r2  r8  rr  )r  r  r&   r.  r!   r!   r"   
union_implG  s   znp_union1d.<locals>.union_impl)r	   r   r}   r  )r  r  r  r!   r!   r"   
np_union1d?  s   r  c                    sh   d}t | tjtjtjfst|t|r| j nzt| W n t	y*   tdw d fdd	}|S )Nz7The argument to np.asarray_chkfinite must be array-likez!dtype must be a valid Numpy dtypec                    s4   t j|  d} t | D ]}t |stdq| S )Nr  z#array must not contain infs or NaNs)rT   r2  rU   r  rp   )r&   r}   r'   r  r!   r"   r  ^  s   
z"np_asarray_chkfinite.<locals>.implr%   )
rI   r   r   rB  rL   r   r   r}   r   r   )r&   r}   r   r  r!   r  r"   np_asarray_chkfiniteO  s   r  c                 C   s@   t d|  | d}t t |dd|| d   d|| d   S )Nr  rn   r   r$   )rT   r3  rT  Z
less_equalrI  r  r!   r!   r"   np_bartlett_implp  s   .r  c                 C   sR   t d|  | d}ddt t j| | d    dt dt j | | d    S )Nr  rn   gzG?r   r$   g{Gz?r  rT   r3  cosr3  r  r!   r!   r"   np_blackman_implv  s   r  c                 C   s2   t d|  | d}ddt t j| | d    S )Nr$   rn   gHzG?gq=
ףp?r  r  r!   r!   r"   np_hamming_impl}      r  c                 C   s2   t d|  | d}ddt t j| | d    S )Nr$   rn   r   r  r  r!   r!   r"   np_hanning_impl  r  r  c                    rI  )Nc                    s$   t | tjs
td fdd}|S )NM must be an integerc                    s8   | dk rt jdt jdS | dkrt jdt jdS  | S )Nr$   r!   r  )rT   r  float_rm  )rI  r  r!   r"   window_impl  s
   z>window_generator.<locals>.window_overload.<locals>.window_impl)rI   r   r  r   )rI  r"  r  r!   r"   window_overload  s   z)window_generator.<locals>.window_overloadr!   )r  r#  r!   r  r"   window_generator  s   r$  )g4!\Tg}b3<gr넱g^<g"P
g'&&KF5=gbLag$ӛ/=gjzg<t̾=gVg4T&>g0Kg5dMv;p>g"c쑾g$>g'doҾgY(X?>gZY&+g|t(?gRBguZ?gI ^qga?g!Ng-Ί>?g-4pKgw?gWӿg*5N?)gT`g0fFVg!<gA`<gҫ`g8箸g}<g攐*<gbe~g2hϙ]'gE_V=gsk[=g&GCi=gfCg{~5g%t9QgO $=guo >g["d,->gmրVX>gna>g+A>gRx?gI墌k?g	b?c                 C   sH   |d }d}t dt|D ]}|}|}| | | ||  }qd||  S )Nr   rD  r$   r   r  )rM  valsb0b1r'   b2r!   r!   r"   _chbevl  s   r)  c                 C   s\   | dk r|  } | dkrd|  d }t | t|t S t | td|  d t t |  S )Nr   g       @r   r  g      @@)rT   expr)  _i0A_i0Br  r  r!   r!   r"   _i0  s   &r-  c                 C   sb   t j| t jd}tt |}tt|D ]}t|t d| | | | d   | ||< q|S )Nr  r$   r  )rT   r+  r!  r-  r,   r>   r  )r  alphabetar  tr'   r!   r!   r"   _i0n  s
   0r1  c                 C   s:   t | tjs
tdt |tjtjfstddd }|S )Nr   z beta must be an integer or floatc                 S   sT   | dk rt jdt jdS | dkrt jdt jdS t d| }| d d }t|||S )Nr$   r!   r  r   r  )rT   r  r!  rm  r3  r1  )rI  r/  r  r.  r!   r!   r"   np_kaiser_impl  s   z!np_kaiser.<locals>.np_kaiser_impl)rI   r   r  r   r   )rI  r/  r2  r!   r!   r"   	np_kaiser   s   r3  c                 C   s   dd }|| \}}}||\}}}	t ||	t || }
t ||t ||	 }t ||t || }|
|d< ||d< ||d< d S )Nc                 S   sF   | d }| d }| j d dkr| d }n
t| jd|}|||fS )N.r   .r$   r
  rm   .rn   r   )rr   rT   rH  r}   ru   )rM  x0rU  Zx2r!   r!   r"   _cross_preprocessing  s   

z._cross_operation.<locals>._cross_preprocessingr4  r5  r6  )rT   rH  )r&   r.  r   r8  a0r|  rx  r&  r'  r(  Zcp0Zcp1Zcp2r!   r!   r"   _cross_operation  s   	r:  c                 C   r  r%   r!   rv  r!   r!   r"   _cross.  rZ  r;  c                    sL   t t| jt|j | jdkr|jdkr fdd}|S  fdd}|S )Nr$   c                    s   t d }t| || |S )Nrm   )rT   r   r:  )r&   r.  cpr  r!   r"   r  6  s   z_cross_impl.<locals>.implc                    s6   t | d |d j}t |d  }t| || |S )Nr4  r<  )rT   r  rr   r   r:  )r&   r.  rr   r=  r  r!   r"   r  ;  s   )rT   r  r   r}   ro   r&   r.  r  r!   r  r"   _cross_impl2  s   
r?  c                 C   $   t | rt |stddd }|S )NInputs must be array-like.c                 S   sf   t | }t |}|jd dvs|jd dvrtd|jd dks*|jd dkr/t||S td)Nr
  )rn   rm   zDIncompatible dimensions for cross product
(dimension must be 2 or 3)rm   zDimensions for both inputs is 2.
Please replace your numpy.cross(a, b) call with a call to `cross2d(a, b)` from `numba.np.extensions`.)rT   r2  rr   rp   r;  r&   r.  r  r  r!   r!   r"   r  H  s   


znp_cross.<locals>.implr  r>  r!   r!   r"   np_crossC  s   rC  c                 C   sB   dd }|| \}}||\}}t ||t || }t |S )Nc                 S   s   | d }| d }||fS )Nr4  r5  r!   )rM  r7  rU  r!   r!   r"   r8  _  s   z0_cross2d_operation.<locals>._cross_preprocessing)rT   rH  r2  )r&   r.  r8  r9  r|  r&  r'  r=  r!   r!   r"   _cross2d_operation\  s
   
rD  c                 C   r  r%   r!   rv  r!   r!   r"   cross2dp  rZ  rE  c                 C   r@  )NrA  c                 S   sB   t | }t |}|jd dks|jd dkrtdt||S )Nr
  rn   zRIncompatible dimensions for 2D cross product
(dimension must be 2 for both inputs))rT   r2  rr   rp   rD  rB  r!   r!   r"   r  y  s   


zcross2d_impl.<locals>.implr  r>  r!   r!   r"   cross2d_implt  s   
rF  fbc                 C   sL   t | tjs
td| jdkrtdt |ttjfstdddd}|S )	Nz#The first argument must be an arrayr$   zarray must be 1Dz$The second argument must be a stringrG  c                 S   s   t | }d}| }d|v r|D ]}|dkr n|d }qt| }d|v r:|d d d D ]}|dkr5 n|d }q-||| S )Nr   r  r$   r.  r
  )rT   r2  r  r>   )filttrimr  firstr'   lastr!   r!   r"   r    s   


znp_trim_zeros.<locals>.implrG  )rI   r   r   r   ro   strZUnicodeType)rH  rI  r  r!   r!   r"   np_trim_zeros  s   

rN  r%   r9  rI  r   r   rc  rk  r  r   r  r  r  r  r  r  r  rL  (v  __doc__r  collectionsr   r  r  Zllvmlite.irr&  numpyrT   Z
numba.corer   r   Znumba.core.extendingr   r   r   Znumba.np.numpy_supportr   r	   r
   r   r   r   Znumba.core.imputilsr   r   r   r   Znumba.np.arrayobjr   r   r   r   Znumba.np.linalgr   r   Znumba.core.errorsr   r   r   r   r   r   Znumba.cpython.unsafe.tupler   r#   r  rC   rQ   rF  r   rh   rk   r|   r.   Z	DTypeSpecZIntegerLiteralr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zaminr   r   Zamaxr   r   r   r   r   r  r  r  r	  r  r  r  r  r  r%  r&  r>  r?  rA  ZaveragerK  rO  Z	iscomplexrU  ZisrealrW  r`  rb  Zisscalarre  rn  rs  ru  rw  rx  ry  r  r  r  r  r  r  r  Znanminr  Znanmaxr  r  r  r  r  Znanstdr  Znansumr  Znanprodr  Z
nancumprodr  Z	nancumsumr  r  r  r  r  r  r  r  r  r  r  r  r  r  Z_partition_w_nanZ_argpartition_w_nanr  r  r.  r4  r  r  Zmedianr  r  r	  r  r  r  r  r  r  r"  Znanpercentiler$  Zquantiler&  Znanquantiler'  Z	nanmedianr*  r2  r5  r:  	partitionrD  r  rG  rJ  rR  rL  rM  rX  Ztrilrd  rs  rm  Ztril_indices_fromrw  rz  Ztriur}  r  r  Ztriu_indices_fromr  r  r  r  Zediff1dr  r  r  r  r  Ztrapzr  r  r  Zvanderr  Zrollr  r  r  r  r  Zinterpr  r  r  r  r  r  r  r[  r  r  r  r  r  r  r  r   r  Zcorrcoefr  Zargwherer  Zflatnonzeror	  r  r  r  r  r  r!  r  r  Zfill_diagonalr"  r$  r)  r,  Zaroundr0  Zround_r2  r5  r6  r:  r<  rh  rH  rN  rP  rS  rX  rT  r[  ra  r   re  r   rh  containsrj  Zcount_nonzerorl  ru  rv  deleterw  r  r{  Zarray_equalr~  Zintersect1dr  r  r  r  r  Z_ltZ_ler  r  r  Zdigitizer  r,   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Z	correlater  Zconvolver   r2  r  Zasfarrayr   r  extractr  selectr  Zunion1dr  Zasarray_chkfiniter  r  r  r  r  r$  ZbartlettZblackmanZhammingZhanningr  r+  r,  r)  r-  r1  Zkaiserr3  r:  r;  r?  crossrC  rD  rE  rF  Z
trim_zerosrN  r!   r!   r!   r"   <module>   s     	
(
K

A'(









/
/






,



B

$



	



"




8
















1



4












"




7


'DmX+'
:$


 



7
 8




5





.
&


92

. 
T


I
,

6


2
 !

	

