o
    0 i                 	   @   s  d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	Z
ddl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mZmZmZmZ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)m*Z*m+Z+m,Z,m-Z-m.Z. dd
l/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= ddl>m?Z?m@Z@ ddl3mAZA ddlBmCZDmEZFmGZGmHZHmIZI dd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPd d! ZQd"d# ZR	dTd$d%ZSd&d' ZTd(d) ZUe5eUd*d+ ZVe$d,ejWd-d. ZXd/d0 ZYe$d1ejZe*e.j[d2d3 Z\	dTd4d5Z]d6d7 Z^d8d9 Z_e$ej`ejWejae$ej`ejWejbd:d; Zce$ej`ejWejdd<d= Zee$ejfejWejgejgd>d? Zhe$eiejWd@dA Zje$dBejkdCdD Zle"dEk rxe$dFejkejgdGdH ZmG dIdJ dJenZoG dKdL dLeoZpG dMdN dNeoZqG dOdP dPeoZrG dQdR dReoZsG dSdT dTeoZtG dUdV dVenZudWdX Zve$ej`ejWejkdYdZ Zwd[d\ Zxd]d^ Zyd_d` Zzdadb Z{dcdd Z|dedf Z}dgdh Z~didj Ze7dkdl Ze7dmdn Ze4dodp Zdqdr Ze5e
jdsdt Ze4dudv Ze5e
jdwdx Ze5e
jdydz Zd{d| Ze5ed}d~dd Ze5edd~dd Zdd Zdd Ze$dejkdd Zdd Ze$dejkejddd Ze$dejkeejgdd Ze5e
jdTddZe%ejkddd Ze5e
jdUddZe5e
jdUddZe5e
jdVddZdd Zdd Ze$dejkejddd Ze$dejkeejgdd Ze"dk re5e
jdd Zn	e5e
jdd Ze5e
jdd Ze5e
jdTddZe$dejkdd Ze$e
jejkdd Ze$dejkdd Ze4dd Ze4dd Ze5e
jdTddZe6ejkddWddZdd Ze5e
jddÄ Ze5e
jddń Ze5e
jddǄ Ze5e
jddɄ Ze4dd˄ Ze6ejkd̡dd΄ Ze7ddЄ Zdd҄ Ze5ed}d~ddԄ Ze$dejkejddׄ Ze%ejkd؃ddڄ Ze%ejkdۃe%ejdۃdd݄ Ze%ejkdރe%ejdރdd Ze%ejkde%ejddd Ze%ejkddd Ze%ejkde%ejddd Ze%ejkde%ejddd Ze%ejddd Ze%ejddd Ze%ejddd Ze%ejddd Ze%ejkddd Ze%ejddd Ze(ejejЃe(ejejуdd  ZҐdd Ze%ejkddd Ze%ejde%ejddd Ze%ejddd	 Ze%ejkd
dd Ze%ejkddd Zِdd Ze6ejkde6ejkddd Zېdd Ze%ejݐde܃ e%ejݐde܃ e$dejejgdd Ze&ejkdd Ze$dejkej2dd  Ze&ejd!d" Ze'ejd#d$ Ze$dejej2d%d& Ze$dejejd'd( Ze$d)ejej2ejgd*d+ Ze$d)ejejejgd,d- Ze)ejkd.d/ Ze)ejd0d1 Ze)ejd2d3 Ze$ejejkejkd4d5 Ze8ejkd6d7d8 Zd9d: Zd;d< Z		dWd=d>Z	dTd?d@ZdAdB ZdCdD ZdEdF Ze%ejkdGdHdI Ze$d1eje*e.j[dJdK Ze$ej`ejejadLdM Ze$ejfejejaejgdNdO Ze$eiejdPdQ Ze$e
jejkdRdS Ze$d1ej e*e.j[dTdU Ze$eeejae$e
jeejadVdW Ze$eejde$e
jejddXdY Ze$d1eje*e.j[dZd[ Ze$e
jejgd\d] Ze$d1ej	e*e.j[d^d_ Z
e$ejejej݃d`da Zdbdc ZeAejkdddedf Zdgdh Ze7didj Zdkdl Zdmdn Zdodp Zdqdr Ze7dsdt Ze5e
jefdudvZe7dwdx Ze5e
jdTdydzZe7d{d| Ze6ejkd}d~d Ze5e
jefddZe5e
j dTddZ!e5e
j"dTddZ#e5e
j$dTddZ%e5e
j&dTddZ'e5e
j(dTddZ)e5e
j*dTddZ+dd Z,e5e,dd Z-e5e
j.ddefddZ/e5e
j0dXddZ1e5e
j2dd Z3e5e
j4dXddZ5dd Z6e5e
j7e6ejkddTddZ8dd Z9e5e
j:dWddZ;e5e
j<dUddZ=dd Z>e7dd Z?e$dejkdd Z@e5e
jAdd ZBdd ZCe7dd ZDe5e
jEdd ZFe5e
jGdd ZHe$dejkeje$dejkej2dd ZIe7dd ZJe5e
jKefddZLe5edTddZMe5edTddZNdd ZOdÐdĄ ZPdŐdƄ ZQdǐdȄ ZRdɐdʄ ZSdːd̄ ZTd͐d΄ ZUdϐdЄ ZVe7dѐd҄ ZWe5e
jXdTdӐdԄZYdՐdք ZZdאd؄ Z[dِdڄ Z\dېd܄ Z]e7dݐdބ Z^e5e
j]dߐd Z_dd Z`dd Zae5e
jbdd Zce5e
jddd Zee5e
jfdd Zgdd Zhdd Zidd Zjdd Zke7dd Zle5e
jmdXddZndd Zoe7dd Zpe5e
jqdd Zrdd Zse7dd  Zte5e
judXddZvdd Zwe7dd Zxe5e
jydd Zze7d	d
 Z{e5e
j|dd Z}e"dEk
re5e
j~e} e7dd Ze5e
jdd Ze6ejkddd Ze6ejkddd Ze5e
jdd Ze5e
jdd Ze7dd Ze5e
jdd Ze5e
jdXdd Ze5e
jdXd!d"Ze5e
jd#d$ Ze5e
jd%d& Ze5e
jd'd( Zi Zd)d* ZdYd,d-Zd.d/ Ze$d0ejkd1d2 Ze5e
jd3d4 Ze$d5ejkej2e$e
jejkej2d6d7 Ze(ejkejkd8d9 Ze(ejkeje(ejkeje(ejkejae(ejkeje(ejkeje(ejkeje(ejkejd:d; Ze(ejkejd<d= Zd>d? Zeed@dA Ze$eejkejdejddBdC Ze5e
jjjdZdDdEZe5e
jjjdTdFdGZe5edHdI Ze5e
jdJdK Ze4dLdM Ze5e
jdNdO Ze5e
jd[dRdSZdS (\  z[
Implementation of operations on Array objects and objects supporting
the buffer protocol.
    N)ir)Constant)pndindexliteral_unroll)typestypingerrorscgutils	extendingconfig)
as_dtype
from_dtypecarrayfarrayis_contiguous
is_fortrancheck_is_integertype_is_scalar
lt_complex	lt_floats)type_can_asarrayis_nonelikenumpy_version)lower_builtinlower_getattrlower_getattr_genericlower_setattr_generic
lower_castlower_constantiternext_implimpl_ret_borrowedimpl_ret_new_refimpl_ret_untrackedRefType)	signature)StringLiteral)register_jitableoverloadoverload_method	intrinsicoverload_attribute)	quicksort	mergesort)slicing)tuple_setitembuild_full_slice_tuple)overload_classmethod)parse_dtypeparse_shape_parse_nested_sequence_sequence_of_arrays_choose_concatenation_layoutc                 C   s4   t |j|t |j|g}| j|}|d| dS )zz
    Set the "range" metadata on a load instruction.
    Note the interval is in the form [lower_bound, upper_bound).
    rangeN)r   typemoduleZadd_metadataZset_metadata)builderloadlower_boundupper_boundZrange_operandsmd r>   ]/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/numba/np/arrayobj.pyset_range_metadata-   s
   

r@   c                 C   s&   d|j jd > d }t| |d| dS )zF
    Mark the result of a load instruction as positive (or zero).
       r   N)r7   widthr@   )r9   r:   r<   r>   r>   r?   mark_positive8   s   rC   c                    s6   j tjG  fddd  S )z
    Return the Structure representation of the given *array_type*
    (an instance of types.ArrayCompatible).

    Note this does not call __array_wrap__ in case a new array structure
    is being created (rather than populated).
    c                       s4   e Zd Z fddZefddZ  ZS )zmake_array.<locals>.ArrayStructc                    s   t }z	| jd|}W n ty   t | | Y S w | jj }| |}|d u r9tj	| j
|dd}n|}|| j
|f}||fS )NZ	__array__T)zfill)r$   _contextget_functionNotImplementedErrorsuper
_make_refsdata_model_managerZ_get_be_typer	   alloca_once_builder)selfrefsigZ
array_impl	datamodelZbe_typeZ	outer_ref)ArrayStruct	__class__
array_typereal_array_typer>   r?   rI   N   s   


z*make_array.<locals>.ArrayStruct._make_refsc                    sp   | j }dkr | dS | d}g }tD ]}t||d|}||}|| t|| qt	||S )z\
            Override .shape to inform LLVM that its elements are all positive.
            r   shape)
rL   __getattr___get_ptr_by_namer6   r	   gep_inboundsr:   appendrC   
pack_array)rM   r9   ptrdimsiZdimptrr:   )basendimr>   r?   rU   b   s   


z%make_array.<locals>.ArrayStruct.shape)__name__
__module____qualname__rI   propertyrU   __classcell__r>   rQ   rS   r^   r_   rT   )rR   r?   rQ   L   s    rQ   )Zas_arrayr	   create_struct_proxyr_   )rS   r>   re   r?   
make_array@   s
   
-rg   c                 C   s   |  |j}| |S )zB
    Return the item size for the given array or buffer type.
    )get_data_typedtypeget_abi_sizeof)contextrS   lltyr>   r>   r?   get_itemsize|   s   
rm   c                 C   s"   |j rdnd}| j||j||dS )z3
    Load the item at the given array pointer.
    NrA   align)alignedunpack_valueri   )rk   r9   arraytyr[   ro   r>   r>   r?   	load_item   s   rs   c                 C   s$   |j rdnd}| j||j|||dS )z4
    Store the item at the given array pointer.
    NrA   rn   )rp   
pack_valueri   )rk   r9   rr   valr[   ro   r>   r>   r?   
store_item   s   rv   c                 C   s@   |j r| |||tj}t|||}|S | |||tj}|S )zM
    Fix the integer index' type and value for the given dimension size.
    )signedcastr   intpr-   Z	fix_indexuintp)rk   r9   idxtyidxsizeindr>   r>   r?   fix_integer_index   s   r   c                 C   sZ   t |tjr)|jdkr)t |jtjsJ t|| ||}t| |||j}|j|fS ||fS )zS
    Normalize the index type and value.  0-d arrays are converted to scalars.
    r   )	
isinstancer   Arrayr_   ri   Integerrg   rs   data)rk   r9   r{   r|   idxaryZidxvalr>   r>   r?   normalize_index   s   
r   c                    s2   t |rt fddt||D  \}}||fS )z^
    Same as normalize_index(), but operating on sequences of
    index types and values.
    c                    s   g | ]\}}t  ||qS r>   )r   ).0r{   r|   r9   rk   r>   r?   
<listcomp>   s
    z%normalize_indices.<locals>.<listcomp>)lenzip)rk   r9   index_typesindicesr>   r   r?   normalize_indices   s
   r   c                 C   s  | j }| j}| j}	ttjdd}
|j|
 }t|j}t|	j}||@ |krC|| }d| j	 dt
|dkr7dnd d| d}t||d	u rRt||	d
d	}|tj}t|ttfrft|||}t|ttfrtt|||}t|tr}||}t|||||d}|d	u rt||	dd	|d< n||d< |tjd}t|||jj}|D ]}|j||dgd}q||d< t| }||krtd|| | D ]
\}}t| || q| S )z
    Helper function for populating array structures.
    This avoids forgetting to set fields.

    *shape* and *strides* can be Python tuples or LLVM arrays.
    rA   CzThe datamodel for type z is missing fields  .Nmeminfo)rU   stridesr   itemsizer   parentnswflagsnitemszmissing {0}) rE   rL   
_datamodelr   r   float64rJ   set_fieldsZ_fe_typer   
ValueErrorr   get_value_typeget_typery   r   tuplelistr	   rZ   intdictget_constantunpack_tupler7   countmulkeysformatitemssetattr)arrayr   rU   r   r   r   r   rk   r9   rP   Zstandard_arrayZstandard_array_type_datamodelZrequired_fieldsZdatamodel_fieldsmissingmsgintp_tattrsr   unpacked_shapeaxlenZ
got_fieldskvr>   r>   r?   populate_array   sh   





r   c                 C   sh   |j }|j}|tjd}t||j| j}|D ]}|j	||dgd}q||_
|tjt|| |_dS )z
    Update some auxiliary information in *array* after some of its fields
    were changed.  `itemsize` and `nitems` are updated.
    rA   r   r   N)rE   rL   r   r   ry   r	   r   rU   r_   r   r   rm   r   )arytyr   rk   r9   r   r   r   r>   r>   r?   update_array_info   s   
r   c                 C   s   t  )z/Constrain axis values to valid positive values.rG   	func_namearg_namer_   axisr>   r>   r?   normalize_axis     r   c                    sL   t | ts
tdt |tstd| j d|j d  fdd}|S )Nz func_name must be a str literal.zarg_name must be a str literal.z: Argument z* out of bounds for dimensions of the arrayc                    s,   |dk r||7 }|dk s||krt  |S Nr   r   r   r   r>   r?   impl$  s
   z&normalize_axis_overloads.<locals>.impl)r   r%   r   TypingErrorliteral_value)r   r   r_   r   r   r>   r   r?   normalize_axis_overloads  s   



r   Zgetiterc                 C   st   |j \}|\}| ||j}| tjd}t||}||_||_	| j
r,| j||| | }	t| ||j|	}
|
S r   )argsmake_helperreturn_typer   r   ry   r	   alloca_once_valueindexr   
enable_nrtnrtincref	_getvaluer!   )rk   r9   rO   r   rr   r   iterobjzeroZindexptrresoutr>   r>   r?   getiter_array/  s   r   c              	   C   s   t j||j|jd}t j||j|jd}||d |}t ||j|}	|dd }
|dd }t|t	j
rEt| |||||	|
|}| S |
rIJ t| |||	S )z1 Evaluate `ary[idx]`, where idx is a single int. r   r   rA   N)r	   r   rU   r_   r   r   pointer_addr   r   r   Buffer	make_viewr   rs   )rk   r9   r   r   aryr|   shapesr   offsetdataptrview_shapesview_stridesretaryr>   r>   r?   _getitem_array_single_intG  s   r   Ziternextc                 C   s   |j \}|\}|j}| j|||d}t|| ||jd}	tj||	jdd\}
||j	}|
d||
}|| ||% t| ||j||	|}|| t||}|||j	 W d    d S 1 sew   Y  d S )NvaluerA   r   <)r   rS   r   rg   r   r	   r   rU   r:   r   icmp_signed	set_validif_thenr   
yield_typeyield_increment_indexstore)rk   r9   rO   r   resultZitertyiterrr   r   r   r   r   is_validr   Znindexr>   r>   r?   iternext_array\  s"   

"r   c              	   C   s>  |  tjd}|  tjd}t||j|j}	t||j|j}
g }g }g }tdd |D }d}t	||D ]\}}|tj
u ri|jt| d | }t|D ]}|| ||	|  ||
|  |d7 }qNq6t|tjr| j|||d}t| ||| t|||	|  ||j t||}t|||
| }|| || n=t|tjrt| ||||	| }|rt| |||	| | || nt|r|| || |d8 }ntd|f |d7 }q6||jksJ ||jk r||	|  ||
|  |d7 }||jk stj| ||||ddd}|||fS )	z
    Perform basic indexing on the given array.
    A (data pointer, shapes, strides) tuple is returned describing
    the corresponding view.
    r   rA   c                 S      g | ]}t |r|qS r>   r   r   r|   r>   r>   r?   r         z"basic_indexing.<locals>.<listcomp>r   unexpected index type: %sF
wraparoundboundscheck)r   r   ry   r	   r   rU   r_   r   r   r   ellipsisr6   rY   r   	SliceTyper   r-   guard_invalid_slice	fix_slicestartget_slice_lengthZ
fix_strider   r   Zdo_boundscheckr   rG   get_item_pointer)rk   r9   r   r   r   r   r   r   oner   r   Zoutput_indicesZoutput_shapesZoutput_stridesnum_newaxesaxindexvalr{   	n_missingr]   sliceshstr~   r   r>   r>   r?   basic_indexingx  sf   










r  c           	   	   C   s.   t || |}t|||||j|j|jd |S )zF
    Build a view over the given array with the given parameters.
    r   rU   r   r   r   r   )rg   r   r   r   r   )	rk   r9   r   r   r   r   r   r   r   r>   r>   r?   r     s   r   c              	   C   s^   t | |||||| jd\}}}	t|tjr$t| |||||||	}
|
 S |r(J t| |||S )zp
    Return the result of indexing *ary* with the given *indices*,
    returning either a scalar or a view.
    r   )r  enable_boundscheckr   r   r   r   r   rs   )rk   r9   r   r   r   r   r   r   r   r   r   r>   r>   r?   _getitem_array_generic  s   r  c           	      C   sZ   |j \}}|\}}|jdksJ t|| ||}t| ||j|||f|f}t| ||j|S )z4
    Basic indexing with an integer or a slice.
    rA   )r   r_   rg   r  r   r    	rk   r9   rO   r   r   r{   r   r|   r   r>   r>   r?   getitem_arraynd_intp  s   

r  c              	   C   s   |j \}}|\}}t|| ||}|j}tj||t|d}	t| |||	\}}	tdd |D r;t| |||||||	S t	| ||j
||||	}
t| ||j
|
S )z2
    Basic or advanced indexing with a tuple.
    r   c                 s       | ]	}t |tjV  qd S Nr   r   r   )r   tyr>   r>   r?   	<genexpr>      z&getitem_array_tuple.<locals>.<genexpr>)r   rg   r   r	   r   r   r   anyfancy_getitemr  r   r    )rk   r9   rO   r   r   tuptyr   tupr   r   r   r>   r>   r?   getitem_array_tuple  s    


r  c              	   C   s   |j \}}}|\}}}	t|tjr|j}
tj||t|d}n|f}
|f}t|| ||}t| ||
|\}
}zt	| ||||
|| j
d\}}}W n tyR   d}Y nw t|}|rbt| ||||
|S | ||	||j}	t| |||	| dS )zH
    array[a] = scalar_or_array
    array[a,..,b] = scalar_or_array
    r   r	  TN)r   r   r   	BaseTupler	   r   r   rg   r   r  r
  rG   boolfancy_setslicerx   ri   rv   )rk   r9   rO   r   r   r{   valtyr   r|   ru   r   r   r   r   r   Zuse_fancy_indexingr>   r>   r?   setitem_array  s4   

r  c           	      C   sD   |j \}|\}t|}|| ||}|j}||d}t| ||j|S r   )r   rg   rU   extract_valuer"   r   )	rk   r9   rO   r   r   r   ZarysttyZshapearyr   r>   r>   r?   	array_len4  s   r  z
array.itemc                 C   s   |j \}|\}t|| ||}|j}|j|d||ddd d}| j|t|f W d    n1 s7w   Y  t	| |||j
S )N!=rA   FZlikelyz>item(): can only convert an array of size 1 to a Python scalar)r   rg   r   r   r   r7   	call_convreturn_user_excr   rs   r   )rk   r9   rO   r   r   r   r   r   r>   r>   r?   
array_item?  s   r$     r   zarray.itemsetc           
      C   s   |j \}}|\}}||jksJ t|| ||}|j}|j|d||ddd d}	| j|t	|	f W d    n1 s@w   Y  t
| ||||j |  S )Nr   rA   Fr!  z/itemset(): can only write to an array of size 1)r   ri   rg   r   r   r   r7   r"  r#  r   rv   r   get_dummy_value)
rk   r9   rO   r   r   r  r   ru   r   r   r>   r>   r?   array_itemsetO  s   
r(  c                   @   @   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )Indexerzq
    Generic indexer interface, for generating indices over a fancy indexed
    array on a single dimension.
    c                 C      t )ze
        Prepare the indexer by initializing any required variables, basic
        blocks...
        r   rM   r>   r>   r?   preparej     zIndexer.preparec                 C   r+  )z=
        Return this dimension's size as an integer.
        r   r,  r>   r>   r?   get_sizeq     zIndexer.get_sizec                 C   r+  )z;
        Return this dimension's shape as a tuple.
        r   r,  r>   r>   r?   	get_shapew  r0  zIndexer.get_shapec                 C   r+  )z}
        Return a half-open [lower, upper) range of indices this dimension
        is guaranteed not to step out of.
        r   r,  r>   r>   r?   get_index_bounds}  r.  zIndexer.get_index_boundsc                 C   r+  )aW  
        Start indexation loop.  Return a (index, count) tuple.
        *index* is an integer LLVM value representing the index over this
        dimension.
        *count* is either an integer LLVM value representing the current
        iteration count, or None if this dimension should be omitted from
        the indexation result.
        r   r,  r>   r>   r?   	loop_head  s   	zIndexer.loop_headc                 C   r+  )z)
        Finish indexation loop.
        r   r,  r>   r>   r?   	loop_tail  r0  zIndexer.loop_tailN)
r`   ra   rb   __doc__r-  r/  r1  r2  r3  r4  r>   r>   r>   r?   r*  d  s    r*  c                   @   H   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )EntireIndexerz:
    Compute indices along an entire array dimension.
    c                 C   s2   || _ || _|| _|| _|| _| j tj| _d S r  )	rk   r9   r   r   dimr   r   ry   ll_intp)rM   rk   r9   r   r   r8  r>   r>   r?   __init__  s   zEntireIndexer.__init__c                 C   sB   | j }|| jj| j| _t|| j| _	|
 | _|
 | _d S r  )r9   r  r   rU   r8  r}   r	   rK   r9  r   append_basic_blockbb_startbb_endrM   r9   r>   r>   r?   r-    s
   
zEntireIndexer.preparec                 C      | j S r  r}   r,  r>   r>   r?   r/       zEntireIndexer.get_sizec                 C      | j fS r  r@  r,  r>   r>   r?   r1       zEntireIndexer.get_shapec                 C      |  d| jfS r   r9  r}   r,  r>   r>   r?   r2       zEntireIndexer.get_index_boundsc                 C   s   | j }| j t| jd| j || j || j || j}|j	|
d|| jdd || j W d    ||fS 1 sBw   Y  ||fS Nr   >=Fr!  )r9   r   r   r9  r   branchr<  position_at_endr:   r   r   r}   r=  )rM   r9   	cur_indexr>   r>   r?   r3    s   
zEntireIndexer.loop_headc                 C   D   | j }t||| j}||| j || j || j	 d S r  )
r9   r	   r   r:   r   r   rI  r<  rJ  r=  rM   r9   
next_indexr>   r>   r?   r4    s
   zEntireIndexer.loop_tailNr`   ra   rb   r5  r:  r-  r/  r1  r2  r3  r4  r>   r>   r>   r?   r7    s    r7  c                   @   r6  )IntegerIndexerz0
    Compute indices from a single integer.
    c                 C   s&   || _ || _|| _| j tj| _d S r  )rk   r9   r|   r   r   ry   r9  )rM   rk   r9   r|   r>   r>   r?   r:    s   zIntegerIndexer.__init__c                 C      d S r  r>   r,  r>   r>   r?   r-       zIntegerIndexer.preparec                 C   s   t | jdS NrA   )r   r9  r,  r>   r>   r?   r/       zIntegerIndexer.get_sizec                 C      dS Nr>   r>   r,  r>   r>   r?   r1    rR  zIntegerIndexer.get_shapec                 C   s   | j | j| j |  fS r  )r|   r9   addr/  r,  r>   r>   r?   r2    s   zIntegerIndexer.get_index_boundsc                 C   s
   | j d fS r  )r|   r,  r>   r>   r?   r3       
zIntegerIndexer.loop_headc                 C   rQ  r  r>   r,  r>   r>   r?   r4    rR  zIntegerIndexer.loop_tailNrO  r>   r>   r>   r?   rP    s    rP  c                   @   r6  )IntegerArrayIndexerz;
    Compute indices from an array of integer indices.
    c                 C   s@   || _ || _|| _|| _|| _|jdksJ | j tj| _	d S rS  )
rk   r9   r{   r   r}   r_   r   r   ry   r9  )rM   rk   r9   r{   r   r}   r>   r>   r?   r:    s   zIntegerArrayIndexer.__init__c                 C   sD   | j }t|| jjd | _t|| j| _|	 | _
|	 | _d S r   )r9   r	   r   r   rU   idx_sizerK   r9  	idx_indexr;  r<  r=  r>  r>   r>   r?   r-    s
   
zIntegerArrayIndexer.preparec                 C   r?  r  rZ  r,  r>   r>   r?   r/    rA  zIntegerArrayIndexer.get_sizec                 C   rB  r  r\  r,  r>   r>   r?   r1    rC  zIntegerArrayIndexer.get_shapec                 C   rD  r   rE  r,  r>   r>   r?   r2    rF  z$IntegerArrayIndexer.get_index_boundsc                 C   s   | j }| j t| jd| j || j || j || j}|j	|
d|| jdd || j W d    n1 s?w   Y  t| j|| jj| j| j|}t| j|| jj|| j}||fS rG  )r9   r   r   r9  r[  rI  r<  rJ  r:   r   r   rZ  r=  r   rk   r{   ri   r   r   r}   )rM   r9   rK  r   r>   r>   r?   r3    s&   zIntegerArrayIndexer.loop_headc                 C   rL  r  )
r9   r	   r   r:   r[  r   rI  r<  rJ  r=  rM  r>   r>   r?   r4    s   
zIntegerArrayIndexer.loop_tailNrO  r>   r>   r>   r?   rY    s    	rY  c                   @   r6  )BooleanArrayIndexerz>
    Compute indices from an array of boolean predicates.
    c                 C   sH   || _ || _|| _|| _|jdksJ | j tj| _t	| jd| _
d S NrA   r   )rk   r9   r{   r   r_   r   r   ry   r9  r   r   )rM   rk   r9   r{   r   r>   r>   r?   r:  )  s   zBooleanArrayIndexer.__init__c                 C   s^   | j }t|| jjd | _t|| j| _t|| j| _	|
 | _|
 | _|
 | _d S r   )r9   r	   r   r   rU   r}   rK   r9  r[  r   r;  r<  bb_tailr=  r>  r>   r>   r?   r-  2  s   

zBooleanArrayIndexer.preparec                 C   s   | j }t|| j}t|| j-}||}t| j|| j	j
| j	| j|j}|||||j}||| W d    n1 sAw   Y  ||S r  )r9   r	   r   r   	for_ranger}   r:   r   rk   r{   ri   r   r   rW  Zzextr7   r   )rM   r9   r   loopcpredr>   r>   r?   r/  ;  s   

	zBooleanArrayIndexer.get_sizec                 C   
   |   fS r  r/  r,  r>   r>   r?   r1  J  rX  zBooleanArrayIndexer.get_shapec                 C   rD  r   rE  r,  r>   r>   r?   r2  M  s   z$BooleanArrayIndexer.get_index_boundsc                 C   s  | j }| j | j| j | j | j| j || j || j || j}|| j}|j	|
d|| jdd || j W d    n1 sKw   Y  t| j|| jj| j| j|}|	|| || j W d    n1 sww   Y  t||}||| j ||fS )NrH  Fr!  )r9   r   r   r[  r   rI  r<  rJ  r:   r   r   r}   r=  r   rk   r{   ri   r   not_r_  r	   r   )rM   r9   rK  	cur_countrc  
next_countr>   r>   r?   r3  R  s,   zBooleanArrayIndexer.loop_headc                 C   s\   | j }|| j || j t||| j}||| j || j	 || j
 d S r  )r9   rI  r_  rJ  r	   r   r:   r[  r   r<  r=  rM  r>   r>   r?   r4  j  s   
zBooleanArrayIndexer.loop_tailNrO  r>   r>   r>   r?   r]  $  s    		r]  c                   @   r6  )SliceIndexerz(
    Compute indices along a slice.
    c                 C   sL   || _ || _|| _|| _|| _|| _|| _| j tj	| _
t| j
d| _d S r   )rk   r9   r   r   r8  r{   r  r   r   ry   r9  r   r   )rM   rk   r9   r   r   r8  r{   r  r>   r>   r?   r:  z  s   zSliceIndexer.__init__c                 C   s   | j }|| jj| j| _t| j|| j	| j
 t|| j
| j t|| j
j| _t|| j| _t|| j| _| | _| | _d S r  )r9   r  r   rU   r8  dim_sizer-   r   rk   r{   r  r   r	   Z
is_neg_intstepis_step_negativerK   r9  r   r   r;  r<  r=  r>  r>   r>   r?   r-    s   
zSliceIndexer.preparec                 C   s   t | j| jS r  )r-   r   r9   r  r,  r>   r>   r?   r/       zSliceIndexer.get_sizec                 C   rd  r  re  r,  r>   r>   r?   r1    rX  zSliceIndexer.get_shapec                 C   s   t | j| j\}}||fS r  )r-   Zget_slice_boundsr9   r  )rM   lowerupperr>   r>   r?   r2    s   zSliceIndexer.get_index_boundsc              	   C   s   | j }| j | jj| j | j | j| j || j |	| j |
| j}|
| j}|| j|d|| jj|d|| jj}|j|dd || j W d    ||fS 1 s_w   Y  ||fS )Nz<=rH  Fr!  )r9   r   r  r   r   r   r   rI  r<  rJ  r:   selectrl  r   stopr   r=  )rM   r9   rK  rg  is_finishedr>   r>   r?   r3    s*   
zSliceIndexer.loop_headc                 C   sp   | j }|j|| j| jjdgd}||| j t||| j	}||| j	 |
| j || j d S )Nr   r   )r9   rW  r:   r   r  rk  r   r	   r   r   rI  r<  rJ  r=  )rM   r9   rN  rh  r>   r>   r?   r4    s   zSliceIndexer.loop_tailNrO  r>   r>   r>   r?   ri  u  s    ri  c                   @   r)  )FancyIndexerz4
    Perform fancy indexing on the given array.
    c              	   C   s|  || _ || _|| _t||j|j| _t||j|j| _| j 	t
j| _g | _g }tdd |D }d}	d}
t||D ]\}}|t
ju rm|jt| d | }t|D ]}t|||||	}|| |	d7 }	|
d7 }
qTq<t|t
jr||||}t|||||	||}|| nkt|t
jrt||||| j|	 }t|||}|| nNt|t
jrt||||}t|jt
jrt||||| j|	 }nt|jt
jrt ||||}nJ || nt!|r| j|
 |	d8 }	nt"d|f |	d7 }	|
d7 }
q<|	|jksJ |	|jf|	|jk r(t|||||	}|| |	d7 }	|	|jk st||jks9J t||jf|| _#d S )Nc                 S   r   r>   r   r   r>   r>   r?   r     r   z)FancyIndexer.__init__.<locals>.<listcomp>r   rA   r   )$rk   r9   r   r	   r   rU   r_   r   r   r   r   ry   r9  newaxesr   r   r   r6   r7  rY   r   r   r   ri  r   r   rP  r   rg   ri   rY  Booleanr]  r   AssertionErrorindexers)rM   rk   r9   r   r   r   r   rw  r   r  Znew_axr  r{   r  r]   indexerr  r~   r   r>   r>   r?   r:    sv   






"
zFancyIndexer.__init__c                 C   s^   | j D ]}|  q| jtjd}dd | j D }| jD ]	}|||f qt|d| _	d S )NrA   c                 S      g | ]}|  qS r>   )r1  r   r]   r>   r>   r?   r         z(FancyIndexer.prepare.<locals>.<listcomp>r>   )
rw  r-  rk   r   r   ry   rt  insertsumindexers_shape)rM   r]   r   Z	res_shaper>   r>   r?   r-    s   


zFancyIndexer.preparec                 C   r?  )z?
        Get the resulting data shape as Python tuple.
        )r~  r,  r>   r>   r?   r1    s   zFancyIndexer.get_shapec              	   C   s  t || jjks
J | j}tj}| d}| d}|}|}t| j| j	|D ]C\}	}
}|
||d|
|}|	 \}}|||}|||||}|d||}||||||}||||||}q&|||}||||}||||}||fS )z
        Get a half-open [lower, upper) range of byte offsets spanned by
        the indexer with the given strides and itemsize.  The indexer is
        guaranteed to not go past those bounds.
        r   rA   ==r   )r   r   r_   r9   r	   	false_bitr9  r   rw  r~  or_icmp_unsignedr2  r   subr   rW  rp  )rM   r   r   r9   is_emptyr   r   rn  ro  rx  rU   strideZlower_indexZupper_indexZlower_offsetZupper_offsetZis_downwardsr>   r>   r?   get_offset_bounds  sB   


zFancyIndexer.get_offset_boundsc                 C   s    t dd | jD  \}}||fS )Nc                 s   s    | ]}|  V  qd S r  )r3  rz  r>   r>   r?   r  A  s    z+FancyIndexer.begin_loops.<locals>.<genexpr>)r   rw  )rM   r   countsr>   r>   r?   begin_loops@  s   zFancyIndexer.begin_loopsc                 C   s   t | jD ]}|  qd S r  )reversedrw  r4  )rM   r]   r>   r>   r?   	end_loopsD  s   
zFancyIndexer.end_loopsN)
r`   ra   rb   r5  r:  r-  r1  r  r  r  r>   r>   r>   r?   rs    s    B&rs  c                 C   s  t ||j}t ||j}	|j}
t| |||||}|  |j}| }t	| |||}|j}t 
|| tjd}| \}}t j| ||
||	|j|d| jd	}t| |||}||}|||g}t| |||| t ||}||| |  t| ||| S )Nr   Fr   )r	   r   rU   r   r   rs  r-  r   r1  _empty_nd_implr   r   r   ry   r  get_item_pointer2layoutr
  rs   r:   geprv   r   r   r  r!   r   )rk   r9   rO   r   r   r   r   r   r   r   r   rx  Zout_tyZ
out_shapesr   Zout_dataZout_idx_r[   ru   curZnext_idxr>   r>   r?   r  I  s6   

r  c           	   	   C   s   |j \}}|\}}t|| ||}|jdkr4t| |||\}}t| ||j|||f|f}t| ||j|S t| ||||||f|fS )z3
    Advanced or basic indexing with an array.
    r   )r   rg   r_   r   r  r   r    r  r  r>   r>   r?   fancy_getitem_arrayt  s   



r  c              	   C   s   |j }|d}|d}|jdv r|}	|||j}
|	|
fS |}	|}
t|jD ]-}||| ||| |}|d||}|	||
|
||
}
|	||	|
|	|}	q(|
|
|}
|d|j|}|	|||
}
|	|||	}	|	|
fS )z
    Compute a half-open range [lower, upper) of byte offsets from the
    array's data pointer, that bound the in-memory extent of the array.

    This mimics offset_bounds_from_strides() from
    numpy/core/src/private/mem_overlap.c
    r   rA   CFrH  r  )r   r7   r  r   r   r6   r_   r  r   rp  rW  )rk   r9   arrtyarrr   r   r   r   r   rn  ro  r]   Zmax_axis_offsetZ
is_upwardsr  r>   r>   r?   offset_bounds_from_strides  s2   



r  c                 C   s.   | ||j}|||}|||}||fS )z
    Given [lower, upper) byte offsets and a base data pointer,
    compute the memory pointer bounds as pointer-sized integers.
    )ptrtointr7   rW  )rk   r9   rn  ro  r   Zdata_ptr_as_intr   endr>   r>   r?   compute_memory_extents  s   r  c           	      C   s&   t | |||||\}}t| ||||S )zr
    Compute a half-open range [start, end) of pointer-sized integers
    which fully contain the array data.
    )r  r  )	rk   r9   r  r  r   r   r   rn  ro  r>   r>   r?   get_array_memory_extents  s   
r  c                 C   s$   | |d|||d||}|S )z[
    Whether two memory extents [a_start, a_end) and [b_start, b_end)
    may overlap.
    r   )and_r  )rk   r9   Za_startZa_endZb_startZb_endZmay_overlapr>   r>   r?   extents_may_overlap  s
   r  c                    s@  j dt d  jddc  |j|j}j |}	|	j  	|	}	 
|	 tj}
t |
(}t 	
j|}t |	|} 
 || W d    n1 smw   Y  W d    n1 s|w   Y   	
fdd} fdd}||fS )Nr   Fr!  c                    s   t  } jddT\}}|  t j  | dd| W d    n1 s1w   Y  |  t j 	
j| dd| W d    n1 sUw   Y  W d    n1 sdw   Y  t 
 |S )NFr!  r   )r	   rK   if_elser   r  r:   r  rs   )source_indicessrc_ptrZif_copyZ	otherwise)r9   rk   	copy_datacopy_layoutcopy_shapescopy_stridesptrtysrc_data
src_shapessrc_stridessrctyuse_copyr>   r?   src_getitem  s4   
z&maybe_copy_source.<locals>.src_getitemc                     sX    j dd  }  | } j |  W d    d S 1 s%w   Y  d S )NFr!  )r   r:   bitcastr   freer   )r9   rk   r  r  	voidptrtyr>   r?   src_cleanup  s
   
"z&maybe_copy_source.<locals>.src_cleanup)r7   r	   r   r   r   r   r   r   allocater  r   r   r   ry   	loop_nestr  r  r:   )rk   r9   r  r  srcr  r  r  	allocsizer   r   r   r  dest_ptrr  r  r>   )r9   rk   r  r  r  r  r  r  r  r  r  r  r  r?   maybe_copy_source  s8   

"r  c           
         s  |  tjd}|  tjdt|t|kr0t|t| }g| | }|g| | }||fS t|t|k rt|t| } fdd|d| D }t j|tj} j	 
|dd d}	| j t|	f W d   n1 sww   Y  ||d }||d }||fS )	ae  
    Preprocess dimension for broadcasting.
    Returns (shapes, strides) such that the ndim match *target_shape*.
    When expanding to higher ndim, the returning shapes and strides are
    prepended with ones and zeros, respectively.
    When truncating to lower ndim, the shapes are checked (in runtime).
    All extra dimension must have size of 1.
    r   rA   c                       g | ]	}  d |qS r  )r  r   r  r9   r   r>   r?   r   (      z(_bc_adjust_dimension.<locals>.<listcomp>NFr!  z,cannot broadcast source array for assignment)r   r   rz   r   	functoolsreducer  r	   true_bitr   rf  r"  r#  r   )
rk   r9   r   r   target_shaper   Znd_diffZ
dim_is_oneacceptedr   r>   r  r?   _bc_adjust_dimension  s,   	

r  c           
         s   g }g }|  tjd|  tjd fddt||D } fdd|D } fddt||D }	 fddt|	||D } fddt|	|D }||fS )	z
    Broadcast shapes and strides to target_shape given that their ndim already
    matches.  For each location where the shape is 1 and does not match the
    dim for target, it is set to the value at the target and the stride is
    set to zero.
    r   rA   c                    s   g | ]\}}  d ||qS )r   r   )r   taroldr9   r>   r?   r   C      z,_bc_adjust_shape_strides.<locals>.<listcomp>c                    r  r  r  )r   r  r  r>   r?   r   E      c                    s   g | ]
\}}  ||qS r>   )r  )r   xyr  r>   r?   r   F      c                    s    g | ]\}}}  |||qS r>   rp  )r   pr  r  r  r>   r?   r   G  s    c                    s   g | ]\}}  ||qS r>   r  )r   r  r  )r9   r   r>   r?   r   I  r  )r   r   rz   r   )
rk   r9   r   r   r  Z	bc_shapesZ
bc_stridesmismatchZ
src_is_onepredsr>   )r9   r   r   r?   _bc_adjust_shape_strides7  s    


r  c           	   	   C   s   t ||j}t ||j}t| ||||\}}t| ||||\}}|jt|dd}t|| |}t	||j
t ||t |||j|j|jd ||fS )zX
    Broadcast the given array to the target_shape.
    Returns (array_type, array)
    Ar_   r  r  )r	   r   rU   r   r  r  copyr   rg   r   r   rZ   r   r   r   )	rk   r9   arrtyper  r  r   r   Znew_arrtypeZnew_arrr>   r>   r?   _broadcast_to_shapeN  s&   


r  c                 C   s,   |j |jddd}|||}dd }||fS )Nr  T)r_   r  readonlyc           
   	   S   sz   |\}}|j d }t|| ||}t||}t| ||||\}}t|dt| |j	dd  |
 }	t| ||j|	S )Nr   r   )r   rg   r	   r   r  r   r   r   r   r   r   r    r   )
rk   r9   rO   r   r  Zshape_r  r  destr   r>   r>   r?   codegenm  s   
z$_numpy_broadcast_to.<locals>.codegen)r  r   )	typingctxr   rU   retrO   r  r>   r>   r?   _numpy_broadcast_toh  s   
r  c                 C   s$   |j dd}||}dd }||fS )NTr  c                 S   sH   |\}|j d }t|| ||}t|jj|_| }t| ||j|S r   )	r   rg   r	   Zget_null_valuer   r7   r   r    r   )rk   r9   rO   r   r  r  r  r   r>   r>   r?   r    s   
z#get_readonly_array.<locals>.codegen)r  )r  r  r  rO   r  r>   r>   r?   get_readonly_array  s   	r  c           
      C   s   | j }t|}t|}||krtd|D ]
}|dk rtdqd}|| }||k rM|| }|| }	||	ks:|dkrC|d7 }|d7 }ntd||k s*d S d S )NzDinput operand has more dimensions than allowed by the axis remappingr   z4all elements of broadcast shape must be non-negativerA   z=operands could not be broadcast together with remapped shapes)rU   r   r   )
r   Z
dest_shapeZ	src_shapeZsrc_ndimZ	dest_ndimr}   Z	src_indexZ
dest_indexZsrc_dimZdest_dimr>   r>   r?   _can_broadcast  s&   
r  c                 C   s   t | } t| | t| |S r  )npasarrayr  r  r   rU   r>   r>   r?   _default_broadcast_to_impl  s   


r  c                 C   s   t | s	tdt|tjrdd }|S t|tjr+t|jtjs)d}t|tS t|tj	rL|j
dkrLtdd |D sJd| d	}t|tS t|tj	ru|j
dkrut| tjoa| jdk}t| sh|rnd
d }|S d}t|d| }t|)Nz-The first argument "array" must be array-likec                 S   s   t | |fS r  )r  broadcast_tor  r>   r>   r?   r        z numpy_broadcast_to.<locals>.implz7The second argument "shape" must be a tuple of integersr   c                 S      g | ]}t |tjqS r>   )r   r   IntegerLiteral)r   typr>   r>   r?   r     r   z&numpy_broadcast_to.<locals>.<listcomp>"z," object cannot be interpreted as an integerc                 S   s   t | } t| S r  )r  r  r  r  r>   r>   r?   r     s   
z/Cannot broadcast a non-scalar to a scalar arrayz:The argument "shape" must be a tuple or an integer. Got %s)r   r   r   r   r   r   UniTupleri   r  Tupler   allr   r_   r   )r   rU   r   r   Zis_scalar_arrayr>   r>   r?   numpy_broadcast_to  s4   




r  c                 C   sr   t t|D ]0}|t| | }|| }|dk rtd|dkr!q| | dkr,|| |< q| | |kr6tdqd S )Nr   #negative dimensions are not allowedrA   z=shape mismatch: objects cannot be broadcast to a single shape)r6   r   r   )rmrU   r]   r   tmpr>   r>   r?   numpy_broadcast_shapes_list  s   
r  c                     s   t | D ]7\}}t|tj}t|tjot|jtj}t|tjo't|jdk}|s;|s;|s;d| d| }t	|qd | D ]}t|tjrNt
 d q@t|tjr[t
 t| q@ dkrddd S d   fdd	}|S )
Nr   z	Argument z* must be either an int or tuple[int]. Got rA   c                  W   rU  rV  r>   r   r>   r>   r?   <lambda>	      z+ol_numpy_broadcast_shapes.<locals>.<lambda>rA   c                     sz   dg  }}t | D ] }t|trt|dkrt| | qt|tr+t| |f qt|D ]
\}}t|||}q0|S r^  )r   r   r   r   r  r   	enumerater.   )r   r  r  argr|   elemr  Ztup_initr>   r?   r     s   

z'ol_numpy_broadcast_shapes.<locals>.impl)r  r   r   r   r  ri   r  r   r   r   maxr  )r   r|   r  Zis_intZis_int_tupleZis_empty_tupler   r   r>   r  r?   ol_numpy_broadcast_shapes  s0   
r  c                     s   t | D ]\}}t|std| dqd }d }| D ]$}t|tjtjfr+|j}n|}|d u r4|}q||kr@td|  qd t | D ])\}}t|tj	rXt
 |j qGt|tjtjtjfrit
 d qGtd| d   fdd	}|S )
Nz
Argument "z" must be array-likezTMismatch of argument types. Numba cannot broadcast arrays with different types. Got r   rA   zUnhandled type r   c                     s|   dg  }t | D ]}t| t|j q	}t D ]
}t|||| }qg }t | D ]}|tt|| q-|S rS  )	r   r  r  r  rU   r6   r.   rY   r  )r   rU   r   r  r]   Zoutsr  r>   r?   r   ?  s   
z$numpy_broadcast_arrays.<locals>.impl)r  r   r   r   r   r   r   r  ri   ZArrayCompatibler  r_   Numberru  )r   r|   r  Zunified_dtypedtr   r>   r  r?   numpy_broadcast_arrays  s6   r  c                 C   r+  )zTargets should implement this if they wish to specialize the error
    handling/messages. The overload implementation takes two tuples as arguments
    and should raise a ValueError.r   r  index_shaper>   r>   r?   raise_with_shape_contextV  r0  r   Zgeneric)targetc                 C   N   t | tjrt |tjr!| j|jkr#t | jtjr%dd }|S d S d S d S d S )Nc                 S      t d)Nz0cannot assign slice from input of different sizer   r  r>   r>   r?   r   f  rC  z1ol_raise_with_shape_context_generic.<locals>.implr   r   r  ri   r   r  r  r   r>   r>   r?   #ol_raise_with_shape_context_generic]  s   
r  ZCPUc                 C   r  )Nc                 S   s   t | dkrd| d  d}ndddd | D  d}t |dkr,d|d  d}nddd	d |D  d}d
| d| }t|)NrA   (r   z,), c                 S      g | ]}t |qS r>   strr   r  r>   r>   r?   r   v  r{  zAol_raise_with_shape_context_cpu.<locals>.impl.<locals>.<listcomp>)c                 S   r	  r>   r
  r  r>   r>   r?   r   z  r{  zcannot assign slice of shape z from input of shape )r   joinr   )r  r  Z	shape_strZ	index_strr   r>   r>   r?   r   r  s   z-ol_raise_with_shape_context_cpu.<locals>.implr  r  r>   r>   r?   ol_raise_with_shape_context_cpuk  s   
r  c           '         s:  |j \}}|\}}t| |}t |j}	t |j}
|j}t ||||}|  dd }t	t
jrۈj| }t t |\t j}t j}j}tj}t|t|ksrJ t||D ]\}} | d||}qw j|dd | || W d   n1 sw   Y  t |||\}}||
|j\}}t |||\}}t ||||}t ||||\}}nmt	t
jr<j| }t|dksJ ttt
j}| f} d|d |} j|dd | |f|d f W d   n	1 s(w   Y   fd	d
}dd }nfdd
}dd }t
j d} |! \}!}"t"|"}"|j#D ]	}#|"$|#|  q\dd |"D }$||$}%% |%|j}%tj& ||	|
|j'|!dj(d	}&t) ||%|& |*  |  + S )z
    Implement slice assignment for arrays.  This implementation works for
    basic as well as fancy indexing, since there's no functional difference
    between the two for indexed assignment.
    c                 S   s~   | j t}ttjt|ttjt|f}|| j |i }| ||}||| 	||j
d || 	||j
d |f d S Nr   rA   )typing_contextresolve_value_typer   r   r  int64r   get_call_typerF   
make_tupler   )rk   r9   r  r  fntyZargtysZ	raise_sigfuncr>   r>   r?   raise_shape_mismatch_error  s   
z2fancy_setslice.<locals>.raise_shape_mismatch_errorr   Fr!  NrA   r   c                    s,   | \} tjttj}| |fS r  )rF   operatorgetitemr$   r   ry   )r  r|   getitem_implr9   rk   r  Z	src_dtyper  r>   r?   r    s   z#fancy_setslice.<locals>.src_getitemc                   S   rQ  r  r>   r>   r>   r>   r?   r    rR  z#fancy_setslice.<locals>.src_cleanupc                    s    S r  r>   )r  )r  r>   r?   r    rR  c                   S   rQ  r  r>   r>   r>   r>   r?   r    rR  c                 S   s   g | ]}|d ur|qS r  r>   )r   rb  r>   r>   r?   r     r   z"fancy_setslice.<locals>.<listcomp>r   ),r   rg   r	   r   rU   r   r   rs  r-  r   r   r   ri   r1  r  r  r   r   r  r   r   r  r  r   r  r  r  SequencerF   r$   ry   r   rz   r  r   rt  r|  rx   r  r  r
  rv   r  r'  )'rk   r9   rO   r   r   r   r   r  r   Zdest_shapesdest_strides	dest_datarx  r  r  r  r  r  Zshape_errorur   Z	src_startZsrc_endZ
dest_lowerZ
dest_upperZ
dest_startZdest_endr  r  r  len_implZseq_lenr   Zdest_indicesr  r]   r  ru   r  r>   r  r?   r    s   








r  c                    s   |j d }|j dd  }|d }|dd  } fddt||D }t ||d j}tjtjt|d}	t	
|j||	}
||f}|
|fS )Nr   rA   c                    "   g | ]\}}  ||tjqS r>   rx   r   ry   )r   r  ru   r   r>   r?   r   #      z#vararg_to_tuple.<locals>.<listcomp>ri   r   )r   r   r	   rZ   r7   r   r  ry   r   r   r$   r   )rk   r9   rO   r   r   Zdimtysr   r\   rU   shapetynew_signew_argsr>   r   r?   vararg_to_tuple  s   
r)  zarray.transposec                 C   s   t | ||jd |d S r   )array_Tr   rk   r9   rO   r   r>   r>   r?   array_transpose/  s   r,  c                 C   sn   t | t t| krtdt |}| D ]}||ks t||kr$tdq||  |d d < ||  |d d < d S )Nzrepeated axis in transposez2axis is out of bounds for array of given dimension)r   r   r   abs)r   rU   r   r8  r  r>   r>   r?   permute_arrays4  s   r.  c              
      s  |j d }t| |d }|j d |d }}|j|j}}	tj}
t|
|||j	|j
g} fdd|D }t||D ]
\}} || qBtj|	dddtj|
} fdd|D }t||D ]\}}t| ||
 tj|g|g|d d qo tttjd	d |D  t|j }t||j |d  |d
 |j|j|jd | }t |j|S )Nr   rA   c                       g | ]}t  qS r>   r	   rK   r   r  )r9   ll_ary_sizer>   r?   r   P  r   z)array_transpose_tuple.<locals>.<listcomp>r   ri   r_   r  c                    s   g | ]	}t  qS r>   rg   r1  )r9   rk   	np_ary_tyr>   r?   r   [  r  r   rU   r   r   r   c                 S   ry  r>   r   r   ar>   r>   r?   r   k  r{  r&  r  ) r   rg   r   ri   r   r   ry   r   	ArrayTyperU   r   r   r   r   r   rj   r   r  
as_pointercompile_internalr.  r   r$   voidr   r   r:   r   r   r   r   r    )rk   r9   rO   r   r   r   Zaxistyr   Znum_axisri   r9  ZarysZll_arysr  dstZnp_itemsizeZnp_arysZnp_aryZll_aryr  r   r>   )r9   rk   r2  r5  r?   array_transpose_tupleC  sP   
	r?  c                 C       t | |||\}}t| |||S r  )r)  r?  rk   r9   rO   r   r'  r(  r>   r>   r?   array_transpose_varargz     rB  c                 C   s:   t | tjrtd|d u rddd}|S ddd}|S )Nz#np.transpose does not accept tuplesc                 S      |   S r  	transposer9  axesr>   r>   r?   np_transpose_impl  rC  z*numpy_transpose.<locals>.np_transpose_implc                 S   
   |  |S r  rE  rG  r>   r>   r?   rI    rX  r  )r   r   r  r   r   )r9  rH  rI  r>   r>   r?   numpy_transpose  s   


rK  Tc           	      C   s   |j dkr|}nFt|| ||}t|| |}t||j|j }t||j|j }t||jt||d d d t||d d d |j	|j
|jd | }t| |||S )NrA   r  )r_   rg   r	   r   rU   r   r   r   rZ   r   r   r   r   r    )	rk   r9   r  r   r   r   r  r   r   r>   r>   r?   r*    s    
r*  2   c                 C   sT   t | tjstdt |tjstdt |ttjfs#tdddd}|S )Nz+The first argument "start" must be a numberz+The second argument "stop" must be a numberz+The third argument "num" must be an integerrN  c                 S   s   t | ||}t d|S )Ng      $@)r  linspacepower)r   rq  numr  r>   r>   r?   r     s   znumpy_logspace.<locals>.implrN  )r   r   r  r   r   r   r   )r   rq  rQ  r   r>   r>   r?   numpy_logspace  s   



rS  c                    s   t | tjsd}t|t |tjsd}t|t |ttjfs)d}t|tdd | |fD rJtt	
t| t|d  d
 fdd	}|S d
d	d}|S )Nz%The argument "start" must be a numberz$The argument "stop" must be a number%The argument "num" must be an integerc                 s   r  r  r   r   Complexr   r  r>   r>   r?   r    r  z"numpy_geomspace.<locals>.<genexpr>rN  c           	         s   | dks|dkrt d | }  |}tdk rH| jdk|jdk@ }t| dkt|dk@ }d}|r<| j} |j}d}|rG|  } | }| }nt| }| | } || }t| }t|}t|||}|dkrv| |d< |dkrv||d< || S )Nr   &Geometric sequence cannot include zeror%  rM  rA   y              ?)r   r   realr  signimaglog10logspace)	r   rq  rQ  Zboth_imaginaryboth_negativeout_signlogstartlogstopr   Zresult_dtyper>   r?   r     s8   


znumpy_geomspace.<locals>.implc                 S   s   | dks|dkrt dt| dkt|dk@ }d}|r'|  } | }| }t| }t|}t|||}|dkrH| |d< |dkrH||d< || S )Nr   rX  rM  rA   )r   r  rZ  r\  r]  )r   rq  rQ  r^  r_  r`  ra  r   r>   r>   r?   r     s    

rR  )r   r   r  r   r   r   r   r  r   r  Zresult_typer   )r   rq  rQ  r   r   r>   rb  r?   numpy_geomspace  s"   


8
rc  rA   c                 C   sR   t |ttjfstdt | tjstd| jdk r"tdddd}|S )	Nz*The second argument "k" must be an integerz'The first argument "m" must be an arrayr&  Input must be >= 2-d.rA   c                 S   sp   |d }|dkr| d d  S |dkrt t | ddS |dkr(t t | S |dkr6t t | ddS t)N   r   rA   r&     )r  swapaxesfliplrflipudrv  )r  r   r>   r>   r?   r     s   znumpy_rot90.<locals>.implr  )	r   r   r   r   r   r   r   r_   NumbaValueError)r  r   r   r>   r>   r?   numpy_rot90   s   




rk  c                 C   s   |  tj}| }|  tj}	t|	||||||||	g}
t|j	|
d}||j
}t||ddd}t||ddd}||}t||dd}t||dd}|	d}|||||||||j|g}|S )a  
    Call into Numba_attempt_nocopy_reshape() for the given array type
    and instance, and the specified new shape.

    Return value is non-zero if successful, and the array pointed to
    by *newstrides* will be filled up with the computed results.
    Znumba_attempt_nocopy_reshaperU   r   r   )r   r   ry   r;  Zintcr   FunctionTyper	   Zget_or_insert_functionr8   r_   rX   rW   callr   )rk   r9   r   r   newndnewshape
newstridesr9  Zll_intp_starZll_intcr  fnndrU   r   Z
is_f_orderr   r>   r>   r?   _attempt_nocopy_reshape  s2   	

rs  c           	      C   s   d}d}t |D ]\}}|dk r|d7 }|}q||9 }q|dkr*| |kr(tdd S |dkrO|dkr9d}| dk}n
| | }| | dk}|sItd|||< d S td)Nr   rA   z)total size of new array must be unchangedzmultiple negative shape values)r  r   )	origsizerU   Znum_neg_valueZ
known_sizer  r   Zneg_axinferredokr>   r>   r?   normalize_reshape_value?  s*   

rw  zarray.reshapec              	   C   s  |j d }|j}|j d }|d }| tj}t||j}	t|| ||d }
t	
||	}||| tj|jddd}t|| |}| tj| |}t|||| | tj|jg|g|d d |
j}| |tttjtj||| g |j}t	
||	}t| |||
|||}|d||d}|| d}| j |t!|f W d    n1 sw   Y  t|| |}t||
j"|#||#||
j$|
j%|
j&d | }t'| ||j|S )	Nr   rA   r   r3  r6  r  zincompatible shape for arrayr  )(r   r   r   r   ry   r   r:  r   rg   r	   rK   r   r   ri   r   rj   r   r  r;  r   r<  rw  r   r$   r=  rz   r   rs  r  r7   r   r"  r#  rG   r   r:   r   r   r   r    )rk   r9   rO   r   r   rettyr&  rU   r9  Zll_shaper   ro  Zshape_ary_ty	shape_aryZshape_itemsizer}   rn  rp  rv  failr   r  r   r>   r>   r?   array_reshape]  sb   


r{  c                 C   r@  r  )r)  r{  rA  r>   r>   r?   array_reshape_vararg  rC  r|  )r&  rA   c                 C      dd }|S )Nc                 S   rJ  r  reshape)r9  ro  r>   r>   r?   np_reshape_impl  rX  #np_reshape.<locals>.np_reshape_implr>   )r9  ro  r  r>   r>   r?   
np_reshape     r  c                 C   r}  )Nc                 S   rJ  r  r~  )r9  rU   r>   r>   r?   r    rX  r  r>   )r9  rU   r  r>   r>   r?   r    r  c                 C   sV   t | sd}t|t|tjrt|jtjs%t|tjs%d}t|dd }|S )N#The argument "a" must be array-likezBThe argument "new_shape" must be an integer or a tuple of integersc           	      S   s   t | } t | } t|tr(d}t |D ]}||9 }|dk r&d}t|qn|dk r2d}t||}| jdkrBt || j	S | | j  }| }t
|d D ]	}t || f}qQ|d | }t ||S )NrA   r   z0All elements of `new_shape` must be non-negative)r  r  ravelr   r   r   r}   zerosZastyperi   r6   concatenater  )	r9  	new_shapenew_sizeZ
dim_lengthr   msg2repeatsr   r]   r>   r>   r?   r     s.   



znumpy_resize.<locals>.impl)r   r   r   r   r   r  ri   r   )r9  r  r   r   r>   r>   r?   numpy_resize  s   


r  c                 C   s^   t | s	tdt |stdt|rddd}|S t|tjs(tdddd}|S )Nz+The first argument "arr" must be array-likez/The second argument "values" must be array-likec                 S   s.   t t | } t t |}t | |fS r  )r  r  r  r  r  valuesr   r>   r>   r?   r     s   znp_append.<locals>.implz,The third argument "axis" must be an integerc                 S   s   t j| |f|dS Nr   r  r  r  r>   r>   r?   r        r  )r   r   r   r   r   r   r   )r  r  r   r   r>   r>   r?   	np_append  s   




r  zarray.ravelc                 C   sN   dd }dd }|j d jdkr|}n|}| ||||}t| ||j|}|S )Nc                 S   s   |  | jS )zNo copy version)r  r}   r   r>   r>   r?   
imp_nocopy     zarray_ravel.<locals>.imp_nocopyc                 S   rD  )zCopy version)flattenr  r>   r>   r?   imp_copy	     zarray_ravel.<locals>.imp_copyr   r   )r   r  r<  r!   r   )rk   r9   rO   r   r  r  impr   r>   r>   r?   array_ravel  s   r  c                 C   s   dd }|  ||||S )Nc                 S   rD  r  )r  r9  r>   r>   r?   np_ravel_impl	  rC  znp_ravel.<locals>.np_ravel_impl)r<  )rk   r9   rO   r   r  r>   r>   r?   np_ravel	  s   r  zarray.flattenc                 C   s,   dd }|  ||||}t| ||j|}|S )Nc                 S   s   |   | jS r  )r  r  r}   r  r>   r>   r?   r  	  rm  zarray_flatten.<locals>.imp)r<  r!   r   )rk   r9   rO   r   r  r   r>   r>   r?   array_flatten	  s   r  c                 C   sl   |d u r	t | n|}t | ||\}}}t |jD ]}|| }	|| }
|| }tt|	|
|||< q|S r  )r  
empty_likebroadcast_arraysndindexrU   minr  )r9  a_mina_maxr   r  a_ba_min_ba_max_br   val_aZ	val_a_minZ	val_a_maxr>   r>   r?   _np_clip_impl%	  s   r  c                 C   sH   t | jD ]}| | }|| }|rt||||< qt||||< q|S r  )r  r  rU   r  r  )r9  bZuse_minr   r   r  Zval_br>   r>   r?   _np_clip_impl_none3	  s   r  c                 C   s^  t | s	tdt|tjst |stdt|tjs't |s'tdt|tjs8t|s8d}t||d u pAt|tj}|d u pKt|tj}|rW|rWddd}|S t|tj}t|tj}	|rn|	rnddd}
|
S |r|	s|r{dd	d
}|S ddd}|S |s|	r|rddd}|S ddd}|S |rddd}|S |rddd}|S ddd}|S )Nr  z6The argument "a_min" must be a number or an array-likez6The argument "a_max" must be a number or an array-likez5The argument "out" must be an array if it is providedc                 S   r  )Nz&array_clip: must set either max or minr   r9  r  r  r   r>   r>   r?   
np_clip_nnX	  rC  znp_clip.<locals>.np_clip_nnc                 S   sH   |d u r	t | n|}t | jD ]}| | }tt|||||< q|S r  )r  r  r  rU   r  r  r9  r  r  r   r  r   r  r>   r>   r?   
np_clip_ssa	  s
   znp_clip.<locals>.np_clip_ssc                 S   sB   |d u r	t | n|}t | jD ]}| | }t||||< q|S r  )r  r  r  rU   r  r  r>   r>   r?   
np_clip_sno	  
   znp_clip.<locals>.np_clip_snc                 S   s   t | |}t| |||S r  r  	full_liker  )r9  r  r  r   Z
a_min_fullr>   r>   r?   
np_clip_sa|	     znp_clip.<locals>.np_clip_sac                 S   sB   |d u r	t | n|}t | jD ]}| | }t||||< q|S r  )r  r  r  rU   r  r  r>   r>   r?   
np_clip_ns	  r  znp_clip.<locals>.np_clip_nsc                 S   s   t | |}t| |||S r  r  )r9  r  r  r   Z
a_max_fullr>   r>   r?   
np_clip_as	  r  znp_clip.<locals>.np_clip_asc                 S   s4   |d u r	t | n|}t | |\}}t||d|S )NTr  r  r  r  )r9  r  r  r   r  r  r  r>   r>   r?   
np_clip_na	     znp_clip.<locals>.np_clip_nac                 S   s4   |d u r	t | n|}t | |\}}t||d|S )NFr  )r9  r  r  r   r  r  r  r>   r>   r?   
np_clip_an	  r  znp_clip.<locals>.np_clip_anc                 S      t | |||S r  )r  r  r>   r>   r?   
np_clip_aa	  s   znp_clip.<locals>.np_clip_aar  )	r   r   r   r   r   NoneTyper   r   r  )r9  r  r  r   r   Za_min_is_noneZa_max_is_noner  Za_min_is_scalarZa_max_is_scalarr  r  r  r  r  r  r  r  r>   r>   r?   np_clip?	  sV   












r  clipc                 C   s   ddd}|S )Nc                 S   s   t | |||S r  )r  r  r  r>   r>   r?   r   	  rm  zarray_clip.<locals>.implNNNr>   )r9  r  r  r   r   r>   r>   r?   
array_clip	  s   
r  c              	      s  |j |j ksJ |j|jksJ t|j}td tdtdtj fdd}| tjt| |}| tjt| |}| tj|j }	t	||
ddd}
t	||
ddd}tjtjd	dd
}| |}t|| tj|j g}| | tj}| tj|}t||g}|| |}t||
|||dd || |}t|||||dd | }| }|	||||| tj|g}ttjtj||tjtjtj}| ||||}t|| t| ||j|}|S )a  
    Attempt to fix up *ary* for switching from *oldty* to *newty*.

    See Numpy's array_descr_set()
    (np/core/src/multiarray/getset.c).
    Attempt to fix the array's shape and strides for a new dtype.
    False is returned on failure, True on success.
    r  r   Fc           	         s   | kr|d |kr}n
|d |kr}||kr'| ks%| dkr'dS |kr0| d }nd}||k rP|| dkr>dS || }||  |9  < |||< dS ||krn|| | }|| dkrbdS || ||< |||< dS 	 dS )NrM  r   FrA   Tr>   )	rr  r\   r   old_itemsizenew_itemsizer  r]   newdimZ
bytelengthZ
any_layoutZc_layoutZf_layoutint8r>   r?   r  	  s4   

z_change_dtype.<locals>.imprU   r   r   rA   r3  Nr6  )r_   r  ordr   r  r   ry   rm   r	   rX   rW   r   rg   rZ   rj   rh   r   r   r$   booleanr<  r   r    r   )rk   r9   Zoldtynewtyr   Z
new_layoutr  r  r  rr  Z
shape_dataZstrides_dataZshape_strides_array_typearyclsZshape_constantZsizeof_intpZstrides_constantry  Zstrides_aryrU   r   r   rO   r   r>   r  r?   _change_dtype	  s   	
0



	
r  c                 C      t | s	tddd }|S )Nz+The argument to np.shape must be array-likec                 S      t | jS r  )r  r  rU   r  r>   r>   r?   r   C
  rT  znp_shape.<locals>.implr   r   r   r9  r   r>   r>   r?   np_shape>
     
r  c                 C   r  )Nz*The argument to np.size must be array-likec                 S   r  r  )r  r  r}   r  r>   r>   r?   r   M
  rT  znp_size.<locals>.implr  r  r>   r>   r?   np_sizeH
  r  r  c                 C      dd }|S )Nc                    sJ   t |   t d d } fddt dd  D }t || S )NrA   c                    s    g | ]\}} | |kr|qS r>   r>   )r   r]   r  r  r>   r?   r   Y
       z5np_unique.<locals>.np_unique_impl.<locals>.<listcomp>)r  sortr  r   r  r   )arheadtailr>   r  r?   np_unique_implV
  s   z!np_unique.<locals>.np_unique_implr>   )r  r  r>   r>   r?   	np_uniqueT
  s   r  c                 C   sh   dd }t | tjtjtjtjtjfr2t |tjrtS t |tjtjfr-t |j	tjr-|S t
dd S )Nc           	      S   s   t j|t jd}|jd dkrt| |d S t |dk r!tdt | }| }|jd }|j|jkr9tdt jt 	||j
d}d}t|D ]}|| |||||  < ||| 7 }qJ|S )Nri   r   rA   r  z(operands could not be broadcast together)r  r  r  rU   np_repeat_impl_repeats_scalerr  r   r  emptyr}  ri   r6   )	r9  r  Zrepeats_arrayasaaraveln	to_returnposr]   r>   r>   r?   !np_repeat_impl_repeats_array_likec
  s$   

z4np_repeat.<locals>.np_repeat_impl_repeats_array_likezIThe repeats argument must be an integer or an array-like of integer dtype)r   r   r   Listr  r  ru  r   r  ri   r   r   )r9  r  r  r>   r>   r?   	np_repeat^
  s    r  c                 C   s   |dk rt dt| }| }|jd }|dkr"tjd|jdS |dkr+t|S tj|| |jd}t|D ]}|| ||| |d | < q9|S )Nr   r  r  rA   )	r   r  r  r  rU   r  ri   r  r6   )r9  r  r  r  r  r  r]   r>   r>   r?   r  
  s   


r  repeatc                 C   r}  )Nc                 S      t | |S r  )r  r  )r9  r  r>   r>   r?   array_repeat_impl
  rT  z'array_repeat.<locals>.array_repeat_implr>   )r9  r  r  r>   r>   r?   array_repeat
     r  c                 C      t |}dd }||fS )z"Computes the itemsize of the dtypec                 S   s,   |  |jd j}|  |j}|| |S r   )rh   r   ri   r   rj   )cgctxr9   rO   llargsrl   Zllintpr>   r>   r?   r  
  s   z%_intrin_get_itemsize.<locals>.codegen)r   ry   )tyctxri   rO   r  r>   r>   r?   _intrin_get_itemsize
  s   
r  c                 C   rQ  r  r>   )r9  ri   r>   r>   r?   _compatible_view
  rR  r  c                 C   r}  )zDDetermines if the array and dtype are compatible for forming a view.c                 S   s   t |}|| jkrf| jdkrd}t|	 | jd }| j| dk}| jdk}| j| | jk}|r:|r:|r:d}t||| jk rR|dksJ| j| dkrPd}	t|	d S | j| | j }
|
| dkrhd}t|d S d S )Nr   zOChanging the dtype of a 0d array is only supported if the itemsize is unchangedrA   zJTo change to a dtype of a different size, the last axis must be contiguouszZWhen changing to a smaller dtype, its size must be a divisor of the size of original dtypezuWhen changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.)r  r   r_   r   rU   r}   r   )r9  ri   Z
dtype_sizeZmsg1r   p1p2Zp3r  Zmsg3r  Zmsg4r>   r>   r?   r   
  s0   




z ol_compatible_view.<locals>.implr>   r9  ri   r   r>   r>   r?   ol_compatible_view
  s   #r  z
array.viewc                 C   s<  |j d }|j}t|| ||d }t|| |}t|jj}t|D ]}	t||	}
|	dkr:|jj	}|
|
||_q#t||	|
 q#| j}|t}||g |j R i }| ||}||| t| ||||}|d|t|j	d}|| d}| j|t|f W d    n1 sw   Y  | }t| ||j|S )Nr   r   r  z"new type not compatible with array)r   r   rg   r   r   r   sortedgetattrr   r7   r  r   r  r  r  r  rF   r  r  r   r   r"  r#  r   r   r    )rk   r9   rO   r   r   rx  r   r  fieldsr   ru   r  r  r  Z_compatible_view_sigr   rv  rz  r   r   r>   r>   r?   
array_view
  s0   



r  ri   c                 C   s   |   }t| |||S r  )r'  r"   rk   r9   r  r   r   r>   r>   r?   array_dtype  s   r  rU   c                 C   (   t |}|| ||}|j}t| |||S r  )rg   rU   r"   rk   r9   r  r   rr   r   r   r>   r>   r?   array_shape     r  r   c                 C   r  r  )rg   r   r"   r   r>   r>   r?   array_strides  r  r  r_   c                 C      |  tj|j}t| |||S r  )r   r   ry   r_   r"   r  r>   r>   r?   
array_ndim  s   r  r}   c                 C   r  r  )rg   r   r"   r   r>   r>   r?   
array_size%  s   r  r   c                 C   r  r  )rg   r   r"   r   r>   r>   r?   array_itemsize-  r  r  nbytesc                 C   s2   t |}|| ||}||j|j}t| |||S )z"
    nbytes = size * itemsize
    )rg   r   r   r   r"   r   r>   r>   r?   array_nbytes6  s   r	  
contiguousc                 C   r  r  )r   r   r  	is_contigr"   r  r>   r>   r?   array_contiguousB     r  c_contiguousc                 C   r  r  )r   r   r  Zis_c_contigr"   r  r>   r>   r?   array_c_contiguousH  r  r  f_contiguousc                 C   r  r  )r   r   r  Zis_f_contigr"   r  r>   r>   r?   array_f_contiguousN  r  r  r  c                 C   s    |  tj|j }t| |||S r  )r   r   r  mutabler"   r  r>   r>   r?   array_readonlyT  rC  r  ctypesc           	      C   sP   t |}|| ||}t|}| ||}|j|_|j|_| }t| |||S r  )rg   r   ArrayCTypesr   r   r   r   r    )	rk   r9   r  r   rr   r   Zactctinfor   r>   r>   r?   array_ctypes\  s   
r  r   c                 C   s8   | j |||d}|j}||| tj}t| |||S Nr   )r   r   r  r   r   ry   r"   )rk   r9   r  r   r  r   r>   r>   r?   array_ctypes_datai  s   r  c                 C   s6   | j |||d}|j}||| |}t| |||S r  )r   r   r  r   r"   )rk   r9   fromtytotyru   r  r   r>   r>   r?   array_ctypes_to_pointerr  s   r  c           
      C   sr   t ||||d}ttj|j}|||j}ttj	||tj}|j
|j|tj|g}||| ||}	|	S )a)  Helper to invoke the contiguous checker function on an array

    Args
    ----
    checker :
        ``numba.numpy_supports.is_contiguous``, or
        ``numba.numpy_supports.is_fortran``.
    context : target context
    builder : llvm ir builder
    aryty : numba type
    ary : llvm value
    r   )rg   r   r  ry   r_   rj   r   ri   r$   Zbool_rU   r   r   r<  )
checkerrk   r9   r   r   Ztup_intpr   Z	check_sigZ
check_argsr  r>   r>   r?   _call_contiguous_check{  s   
r  r   c                 C   s>   |  |t|}||_| }| j||| t| |||S r  )r   r   
ArrayFlagsr   r   r   r   r!   )rk   r9   r  r   flagsobjr   r>   r>   r?   array_flags  s
   r!  c                 C   sZ   |j jdkr| j|||d}tt| ||j |j}n|j jdk}| tj|}t	| |||S )Nr   r   )
rS   r  r   r  r   r   r   r   r  r"   )rk   r9   r  r   r   r   ru   r>   r>   r?   array_flags_c_contiguous  s   r"  c                 C   sr   |j jdkr| j|||d}tt| ||j |j}n|j j}|j jdkr'|dkn|dv }| tj	|}t
| |||S )Nr  r   rA   r  )rS   r  r   r  r   r   r_   r   r   r  r"   )rk   r9   r  r   r   r   r  ru   r>   r>   r?   array_flags_f_contiguous  s   r#  rY  c                 C   sH   |j tjv rt| |||ddS |j tjv rt| |||S tdtj )NrY  attrzunsupported .real for {})	ri   r   complex_domainarray_complex_attrnumber_domainr    rG   r   r7   )rk   r9   r  r   r>   r>   r?   array_real_part  s
   r)  r[  c                 C   s   |j tjv rt| |||ddS |j tjv rHt|jdd|}t| |||g\}}t| |||}t	
||j||j|jd t| ||j| S tdtj )Nr[  r$  Tr  r   zunsupported .imag for {})ri   r   r&  r'  r(  r$   r  _parse_empty_like_argsr  r	   memsetr   r   r   r   r!   r   r   rG   r   r7   )rk   r9   r  r   rO   r  r   r   r>   r>   r?   array_imag_part  s   
r,  c                 C   s   |dvs
|j tjvrtd|t|}|| ||}|j j}| | |}|j	
|}	| | }
||j|
}|dkrK||tddg}|j|dd}t|| |}t||	d}t||| t| ||| S )	a  
    Given a complex array, it's memory layout is:

        R C R C R C
        ^   ^   ^

    (`R` indicates a float for the real part;
     `C` indicates a float for the imaginary part;
     the `^` indicates the start of each element)

    To get the real part, we can simply change the dtype and itemsize to that
    of the underlying float type.  The new layout is:

        R x R x R x
        ^   ^   ^

    (`x` indicates unused)

    A load operation will use the dtype to determine the number of bytes to
    load.

    To get the imaginary part, we shift the pointer by 1 float offset and
    change the dtype and itemsize.  The new layout is:

        x C x C x C
          ^   ^   ^
    )rY  r[  zcannot get attribute `{}`r[      rA   r  ri   r  )r   r   )ri   r   r&  rG   r   rg   Zunderlying_floatrj   rh   r   r7   r   r;  r  r   r  r   IntTyper  r   r	   Zcopy_structr    r   )rk   r9   r  r   r%  rr   r   ZfltyZsizeof_fltyr   Z
llfltptrtyr   Zresulttyr   replr>   r>   r?   r'    s    r'  conj	conjugatec                 C   r  )Nc                 S   s
   t | S r  )r  r1  r  r>   r>   r?   r     rX  zarray_conj.<locals>.implr>   r  r   r>   r>   r?   
array_conj     r5  c                 C   rD  r  )r'  )rk   r9   ZdtypetyZdtypevalr>   r>   r?   
dtype_type  r  r7  r7   kindZstatic_getitemc                 C   s<   |j }t|tjr| |d}t| |||S d}t|)zThis handles the "static_getitem" when a Numba type is subscripted e.g:
    var = typed.List.empty_list(float64[::1, :])
    It only allows this on simple numerical types. Compound types, like
    records, are not supported.
    NzlUnreachable; the definition of __getitem__ on the numba.types.abstract.Type metaclass should prevent access.)r   r   r   r   r   r"   r   ZLoweringError)rk   r9   rO   r   rx  r   r   r>   r>   r?   static_getitem_number_clazz(  s   
r9  c              	      s  t |}| ||}|j}t|tjstd||f ||}||}	t|tjr9|j	|j|j
|j
 dd}
n|j	|dd}
t |
}| |} tj|	}tj||j||jjd}t|tjrt||j|j
}| fdd|jD 7 }t||j|j
}| fdd|jD 7 }  |j}n|j}|j}  |}t|||| tj||j|jd	 | }t ||
|S )
zq
    Generic getattr() implementation for record arrays: fetch the given
    record member, i.e. a subarray.
    zattribute %r of %s not definedr  r3  r.  )r   c                       g | ]	}  tj|qS r>   r   r   ry   rz  rk   r>   r?   r   b  r  z(array_record_getattr.<locals>.<listcomp>c                    r:  r>   r;  rz  r<  r>   r?   r   e  r  r  )rg   ri   r   r   RecordrG   typeofr   NestedArrayr  r_   r   ry   r	   r   r   r7   r   rU   r   rj   rh   r   r   r   r   r    )rk   r9   r  r   r%  rr   r   Zrectyperi   r   ZrestyZrarytyZraryZconstoffsetZ
newdataptrrU   r   Zdatasizer   r>   r<  r?   array_record_getattr@  sN   


r@  c                 C   s0   |d }t |tstt| ||jd |d |S r^  )r   r  rG   r@  r   )rk   r9   rO   r   r   r>   r>   r?   array_record_getitemx  s   
rA  c              	      s    || ||}||}t|tjret|}| |}|j}	 fdd|jD }
 fdd|j	D }t
||| |	}t||t
||
t
|| tj|jddd | }t |||S t
||| |}|jrudnd} ||||}t |||S )zT
    Generic getattr() implementation for records: get the given record member.
    c                    r:  r>   r;  r   r   r<  r>   r?   r     r  z"record_getattr.<locals>.<listcomp>c                    r:  r>   r;  rB  r<  r>   r?   r     r  Nr  rA   )sentry_record_alignmentr   r>  r   r   r?  rg   ri   rU   r   r	   get_record_memberrh   r   rZ   r   ry   r}   r   r    rp   rq   )rk   r9   r  r   r%  r   elemtyr   r   ri   ro  rp  newdatar   dptrro   r>   r<  r?   record_getattr  sB   







	
rH  c              	   C   s   |j \}}|\}}| || ||}	||}
t|
tjrHt|| ||d d}|j	}t
|||	|jj}t|||| tj|
j dS t
|||	| |
}| ||||
}|jr`dnd}| j||
|||d dS )zT
    Generic setattr() implementation for records: set the given record member.
    rA   r   Nrn   )r   rC  r   r>  r   r   r?  r	   rf   r   rD  r7   ZpointeeZmemcpyr   ry   r   rh   rx   rp   rt   )rk   r9   rO   r   r%  r  r  r  ru   r   rE  Z
val_structr  r  rG  ro   r>   r>   r?   record_setattr  s,   





rI  c                 C   s4   |  |jd |d }|| ||jd |d |d S )3
    Record.__getitem__ redirects to getattr()
    r   rA   )get_getattrr   )rk   r9   rO   r   r   r>   r>   r?   record_static_getitem_str  s   rL  c                 C   s^   |j d j}t|j d j}| |j|| }| |j d |}|| ||j d |d || S )rJ  rA   r   )r   r   r   r  Zinsert_const_stringr8   rK  )rk   r9   rO   r   r|   r  Zll_fieldr   r>   r>   r?   record_static_getitem_int  s
   rM  Zstatic_setitemc                 C   sJ   |j \}}}|\}}}	t|j||}
| ||
}|dusJ ||||	fS )3
    Record.__setitem__ redirects to setattr()
    N)r   r$   r   get_setattr)rk   r9   rO   r   rectyr  r  recr|   ru   getattr_sigr   r>   r>   r?   record_static_setitem_str  s   
rS  c                 C   s^   |j \}}}|\}}}	t|j||}
t|j d j}| || |
}|dus(J ||||	fS )rN  r   N)r   r$   r   r   r  rO  )rk   r9   rO   r   rP  r  r  rQ  r|   ru   rR  r  r   r>   r>   r?   record_static_setitem_int  s   
rT  c                 C   s   |  |||S )zB
    Create a constant array (mechanism is target-dependent).
    )make_constant_array)rk   r9   r  pyvalr>   r>   r?   constant_array  s   rW  c                 C   s0   t t d|j}|t| }t||S )zG
    Create a record constant as a stack-allocated array of bytes.
       )r   r:  r/  r  	bytearraytostringr	   r   )rk   r9   r  rV  Zltyru   r>   r>   r?   constant_record  s   r[  c                 C   s"   t jt|t jd}| |||S )zM
    Create a constant array from bytes (mechanism is target-dependent).
    r  )r  r   rY  Zuint8rU  )rk   r9   r  rV  bufr>   r>   r?   constant_bytes  s   r]  c                 C   s0   |j \}}||krtjS dd }| ||||S )Nc                 S   s(   | j |j ko| j|jko| jj|jjkS r  )rU   r   r  r   r9  r  r>   r>   r?   array_is_impl  s
   
zarray_is.<locals>.array_is_impl)r   r	   r  r<  )rk   r9   rO   r   atyZbtyr_  r>   r>   r?   array_is  s
   
ra  __hash__c                 C   s   dd S )Nc                 S   rQ  r  r>   r3  r>   r>   r?   r  ,  r  zol_array_hash.<locals>.<lambda>r>   r3  r>   r>   r?   ol_array_hash*  r  rc  c                 C   
   t | dS )zq
    Return the Structure representation of the given *flatiterty* (an
    instance of types.NumpyFlatType).
    flat_make_flattening_iter_cls)
flatitertyr>   r>   r?   make_array_flat_cls2     
ri  c                 C   rd  )zv
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdEnumerateType).
    ndenumeraterf  nditertyr>   r>   r?   make_array_ndenumerate_cls:  rj  rn  c              	   C   s  |  tjd}|d}	|d ur|tj| tt|D ]T}
t	|||
}t
|||}||
 }|d||}t|| ||| |d urO||
 ||	 W d    n1 s^w   Y  ||| |d urq||
 q|d ur}|tj| ||	 ||	 d S )Nr   Zend_incrementr   )r   r   ry   r;  r   r	   
false_byter  r6   rX   r   r:   r   	if_likelyrI  	true_byterJ  )rk   r9   r_   rU   r   end_flagloop_continue
loop_breakr   bbendr8  idxptrr|   r   	in_boundsr>   r>   r?   _increment_indicesB  s.   

rx  c                 C   s*   t ||j|j}t| ||j||| d S r  )r	   r   rU   r_   rx  )rk   r9   r  r  r   rr  rU   r>   r>   r?   _increment_indices_arrayc  s   ry  c                    s   j jtjjrnd	G dd dt}G dd d| G fddd|G dd	 d	|G d
d d|G dd d|G  	f
dddt}|S )zq
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdIterType).
    rA   c                   @   sF   e Zd ZdZdd Zdd Zejdd Zdd	 Z	d
d Z
dd ZdS )z$make_nditer_cls.<locals>.BaseSubIterzF
        Base class for sub-iterators of a nditer() instance.
        c                 S   s&   || _ || _|| _|| _|| | _d S r  )nditermember_name	start_dimend_dimr_   )rM   rz  r{  r|  r}  r>   r>   r?   r:  x  s
   z-make_nditer_cls.<locals>.BaseSubIter.__init__c                 S   s   t | j| j| d S r  )r   rz  r{  )rM   r[   r>   r>   r?   set_member_ptr     z3make_nditer_cls.<locals>.BaseSubIter.set_member_ptrc                 S   s   t | j| jS r  )r  rz  r{  r,  r>   r>   r?   
member_ptr     z/make_nditer_cls.<locals>.BaseSubIter.member_ptrc                 S   rQ  r  r>   rM   rk   r9   r>   r>   r?   init_specific  rR  z2make_nditer_cls.<locals>.BaseSubIter.init_specificc                 S   rQ  r  r>   rM   rk   r9   logical_dimr>   r>   r?   rs    rR  z2make_nditer_cls.<locals>.BaseSubIter.loop_continuec                 S   rQ  r  r>   r  r>   r>   r?   rt    rR  z/make_nditer_cls.<locals>.BaseSubIter.loop_breakN)r`   ra   rb   r5  r:  r~  r  cached_propertyr  r  rs  rt  r>   r>   r>   r?   BaseSubIters  s    
r  c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )z$make_nditer_cls.<locals>.FlatSubIterz
        Sub-iterator walking a contiguous array in physical order, with
        support for broadcasting (the index is reset on the outer dimension).
        c                 S   s$   | tjd}| t|| d S r   )r   r   ry   r~  r	   r   )rM   rk   r9   r   r>   r>   r?   r    s   z2make_nditer_cls.<locals>.FlatSubIter.init_specificc                 S   s   | | j}||j|gS r  )r:   r  r  r   )rM   rk   r9   r   r  r  r   r>   r>   r?   compute_pointer  s   z4make_nditer_cls.<locals>.FlatSubIter.compute_pointerc                 S   s<   || j d kr|| j}t||}||| j d S d S rS  )r_   r:   r  r	   r   r   )rM   rk   r9   r  r   r>   r>   r?   rs    s
   z2make_nditer_cls.<locals>.FlatSubIter.loop_continuec                 S   sd   |dkr| tjd}||| j d S || jd kr0|| j}t||}||| j d S d S r  )	r   r   ry   r   r  r_   r:   r	   r   )rM   rk   r9   r  r   r   r>   r>   r?   rt    s   z/make_nditer_cls.<locals>.FlatSubIter.loop_breakN)r`   ra   rb   r5  r  r  rs  rt  r>   r>   r>   r?   FlatSubIter  s    r  c                       s$   e Zd ZdZ fddZdd ZdS )z+make_nditer_cls.<locals>.TrivialFlatSubIterzx
        Sub-iterator walking a contiguous array in physical order,
        *without* support for broadcasting.
        c                    s    j rJ d S r  )need_shaped_indexingr  rl  r>   r?   r    r  z9make_nditer_cls.<locals>.TrivialFlatSubIter.init_specificc                 S   s&   t |dksJ t |||j|S rS  )r   r  r   rM   rk   r9   r   r  r  r>   r>   r?   r    s   z;make_nditer_cls.<locals>.TrivialFlatSubIter.compute_pointerN)r`   ra   rb   r5  r  r  r>   rl  r>   r?   TrivialFlatSubIter  s    r  c                   @      e Zd ZdZdd ZdS )z'make_nditer_cls.<locals>.IndexedSubIterzA
        Sub-iterator walking an array in logical order.
        c                 S   s(   t || jks	J tj|||||ddS NFr  )r   r_   r	   r   r  r>   r>   r?   r    s   z7make_nditer_cls.<locals>.IndexedSubIter.compute_pointerNr`   ra   rb   r5  r  r>   r>   r>   r?   IndexedSubIter      r  c                   @   r  )z'make_nditer_cls.<locals>.ZeroDimSubIterz5
        Sub-iterator "walking" a 0-d array.
        c                 S   s   |j S r  r  r  r>   r>   r?   r    rA  z7make_nditer_cls.<locals>.ZeroDimSubIter.compute_pointerNr  r>   r>   r>   r?   ZeroDimSubIter  r  r  c                   @   r  )z&make_nditer_cls.<locals>.ScalarSubIterz8
        Sub-iterator "walking" a scalar value.
        c                 S   s   |S r  r>   r  r>   r>   r?   r    rR  z6make_nditer_cls.<locals>.ScalarSubIter.compute_pointerNr  r>   r>   r>   r?   ScalarSubIter  r  r  c                       s|   e Zd ZdZej fddZ	fddZfddZdd	 Z	d
d Z
	fddZdd Zdd ZdS )zmake_nditer_cls.<locals>.NdIterz
        .nditer() implementation.

        Note: 'F' layout means the shape is iterated in reverse logical order,
        so indices and shapes arrays have to be reversed as well.
        c                    sd   g }j r nd}tjD ]\}}|\}}}}d| }	|| }
||
| |	|| q|S )N)re  ZindexedZ0dZscalarzindex%d)r  r  rw  rY   )rM   lZ	factoriesr]   r  r8  r|  r}  r  r{  factory)r  r  r  r  r  rm  r>   r?   subiters  s   
z(make_nditer_cls.<locals>.NdIter.subitersc                    s2  | tjd}||t||| _t|D ]\}}t|tjs2d| }t	
||| }	t| ||	 q| ||||}ttj}
d}d}t|D ]\}}t|tjre|jkre|| j}|| j} nqJdkslJ |||
d}| tjd}dd }t||D ]'\}}t|tjr|jdkrttjttj|j|
}|||||j|f qt	||} dkr|ddd	 }|d
||}||t	jt	j}js|f}t|ksJ t	j||jd}tD ]}t	|||}| || q|| _!t	"|||j| _t	
||| _#| j$D ]	}|%|| qdS )zY
            Initialize the nditer() instance for the specific array inputs.
            r   scalar%dNr>   rA   c                 S   s>   t | }t|D ]}| | |t || |  krtdqd S )Nz2nditer(): operands could not be broadcast together)r   r6   r   )rU   
main_shaper  r]   r>   r>   r?   check_shape  s   zBmake_nditer_cls.<locals>.NdIter.init_specific.<locals>.check_shaper  rM  r  r@  )&r   r   ry   r  r  arraysr  r   r   r	   r   r   _arrays_or_scalarsr  r_   rU   r   r   r$   noner<  r   r   rp  rq  ro  r  r   rK   r7   r6   rX   r   r   rZ   	exhaustedr  r  )rM   rk   r9   arrtysr  r   r]   r  r{  slotZmain_shape_tyr  Zmain_nitemsr  r  r  rO   r   Zshape_is_emptyr  r   r8  rv  subiter)r  r_   rm  nshapesr>   r?   r    sl   




z-make_nditer_cls.<locals>.NdIter.init_specificc                    s>  | d}t||| j}t|| |d || W d   n1 s*w   Y   j}t	|| j}| 
||||}| j}|d | |||||}	dd |	D }	t|	dkrg||	d  n||| j|	 t	|| j}
t||t|
|
|| jt| j||t| j|| || || dS )	zJ
            Compute next iteration of the nditer() instance.
            r  FNTc                 S   ry  r>   r7  r   r   r>   r>   r?   r   R  r{  zEmake_nditer_cls.<locals>.NdIter.iternext_specific.<locals>.<listcomp>rA   r   )r;  r	   as_bool_bitr:   r  if_unlikelyr   rI  r  r   r  r   _make_viewsr   r   r  r   rU   rx  r  partial_loop_continue_loop_breakrJ  )rM   rk   r9   r   ru  r  r  r  r   viewsrU   rl  r>   r?   iternext_specific=  sD   





z1make_nditer_cls.<locals>.NdIter.iternext_specificc                 S   @   | j D ]}|j|  kr|jk rn q|||||j  qd S r  )r  r|  r}  rs  rM   rk   r9   r8  r  r>   r>   r?   r  g  
   
z.make_nditer_cls.<locals>.NdIter._loop_continuec                 S   r  r  )r  r|  r}  rt  r  r>   r>   r?   r  l  r  z+make_nditer_cls.<locals>.NdIter._loop_breakc                    s   dg }j }| j}j}	t|	tjrt|	}	n|	g}	 fddtD t||D ]=\}
}|
\}}}}|j	|j
 }dkrJ|ddd }|D ]}|| du sVJ | | ||	| || || |||< qLq-tdd |D svJ |S )z:
            Compute the views to be yielded.
            Nc              	          g | ]}  t |qS r>   r:   r	   rX   rz  r9   r   r>   r?   r   }  s    z?make_nditer_cls.<locals>.NdIter._make_views.<locals>.<listcomp>r  rM  c                 s   s    | ]}|V  qd S r  r>   r  r>   r>   r?   r    s    z>make_nditer_cls.<locals>.NdIter._make_views.<locals>.<genexpr>)rw  r  r   r   r   r  r   r6   r   r|  r}  
_make_viewr  )rM   rk   r9   r   r  r  r  rw  r  rettysr  r  r  Zarray_indicesZsub_indicesr]   )r  narraysrm  r  r  r?   r  q  s0   



z+make_nditer_cls.<locals>.NdIter._make_viewsc                 S   s   t |tjr|jdksJ ||||||}||||}	t||}
||ttj	dd}||ttj	dd}t
|	||||
dd |	S )zD
            Compute a 0d view for a given input array.
            r   r>   N)r   )r   r   r   r_   r  rg   rm   r  r  ry   r   )rM   rk   r9   r   rx  r  r  r  r[   viewr   rU   r   r>   r>   r?   r    s   
z*make_nditer_cls.<locals>.NdIter._make_viewc           	      S   s`   g }t t||D ]$\}\}}t|tjr#||||||d q	|t| d|  q	|S )Nr   r  )r  r   r   r   r   rY   rg   r  )	rM   rk   r9   r  r  r  r]   r  r  r>   r>   r?   r    s   
z2make_nditer_cls.<locals>.NdIter._arrays_or_scalarsN)r`   ra   rb   r5  r  r  r  r  r  r  r  r  r  r  r>   
r  r  r  r  r  r  r  r_   rm  r  r>   r?   NdIter  s    O*r  )r_   r  r   r  r  objectr	   rf   )rm  r  r  r>   r  r?   make_nditer_clsi  s   
 
, Yr  c                    s$   | j  G  fdddt| }|S )zr
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdIndexType).
    c                       s(   e Zd ZdZ fddZ fddZdS )z%make_ndindex_cls.<locals>.NdIndexIterz,
        .ndindex() implementation.
        c              	      s   | tjd}tj||j| tj d}t|tj}t D ]7}t	|||}|
|| || }	|d|	|}
t||
 |
tj| W d    n1 sRw   Y  q || _|| _t|||j| _d S Nr   r@  r  )r   r   ry   r	   rK   r7   r   ro  r6   rX   r   r  r  rq  r   r  rZ   rU   )rM   rk   r9   r   r   r   r  r8  rv  rj  dim_is_emptyr_   r>   r?   r    s&   
z3make_ndindex_cls.<locals>.NdIndexIter.init_specificc           
         s   | tjd} d}t  j}t | |	d  
| W d    n1 s1w   Y   fddtD }|D ]}t | qD|t ||j |	d t j}	t| |	jj  
|  | d S )Nr   r  Fc              	      s"   g | ]}  t j|qS r>   )r:   r	   rX   r   r   r8  r9   rM   r>   r?   r     s    

zKmake_ndindex_cls.<locals>.NdIndexIter.iternext_specific.<locals>.<listcomp>T)r   r   ry   r;  r	   r  r:   r  r  r   rI  r6   rC   r   rZ   r7   r   rU   rx  r   rJ  )
rM   rk   r9   r   r   ru  r  r   r:   rU   r  r  r?   r    s,   





z7make_ndindex_cls.<locals>.NdIndexIter.iternext_specificN)r`   ra   rb   r5  r  r  r>   r  r>   r?   NdIndexIter  s    r  )r_   r	   rf   )rm  r  r>   r  r?   make_ndindex_cls  s   7r  c                    sX    dv sJ | j }|jdkrG  fdddt| }|S G  fdddt| }|S )N)re  rk  r   c                       s8   e Zd ZdZ fddZ fddZdd Zdd	 Zd
S )z6_make_flattening_iter_cls.<locals>.CContiguousFlatIterzZ
            .flat() / .ndenumerate() implementation for C-contiguous arrays.
            c           	         s   | tjd}t||| _|j| _ dkr?tj||j	| tj|j
d}t|j
D ]}t|||}||| q*|| _d S d S )Nr   rk  r@  )r   r   ry   r	   r   r   r   r  rK   r7   r_   r6   rX   r   r   )	rM   rk   r9   r  r  r   r   r8  rv  r8  r>   r?   r    s   
zD_make_flattening_iter_cls.<locals>.CContiguousFlatIter.init_specificc                    s   |j }|j} | j} d||}	||	 t |	W  |j	|g}
t
| ||
}dkr8|| n(| j fddt|D }t |}|t ||g t| || t |} || j W d    d S 1 sxw   Y  d S )Nr   re  c              	      r  r>   r  r  r  r>   r?   r   &      

z\_make_flattening_iter_cls.<locals>.CContiguousFlatIter.iternext_specific.<locals>.<listcomp>)r_   r   r:   r   r   r   r	   rp  r  r   rs   r   r   r6   rZ   make_anonymous_structry  r   r   )rM   rk   r9   r  r  r   r_   r   r   r   r[   r   idxvalsidxtupler  r  r?   r    s4   
"zH_make_flattening_iter_cls.<locals>.CContiguousFlatIter.iternext_specificc                 S   s   | |j|g}t||||S r  )r  r   rs   rM   rk   r9   r  r  r   r[   r>   r>   r?   r  4  s   z>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.getitemc                 S   s$   | |j|g}t||||| d S r  )r  r   rv   rM   rk   r9   r  r  r   r   r[   r>   r>   r?   setitem8  s   z>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.setitemN)r`   ra   rb   r5  r  r  r  r  r>   r  r>   r?   CContiguousFlatIter  s    r  c                       s<   e Zd ZdZdd Z fddZdd Zdd	 Zd
d ZdS )z+_make_flattening_iter_cls.<locals>.FlatIterz
            Generic .flat() / .ndenumerate() implementation for
            non-contiguous arrays.
            It keeps track of pointers along each dimension in order to
            minimize computations.
            c              	   S   s  | tjd}|j}|j}t||j|}tj||j	| tj|jd}	tj||j	| tj|jd}
t
|tj}t|D ]D}t||	|}t||
|}||| ||| || }|d||}t|| |tj| W d    n1 s}w   Y  q>|	| _|
| _|| _d S r  )r   r   ry   r   r_   r	   r   rU   rK   r7   r   ro  r6   rX   r   r  r  rq  r   pointersr  )rM   rk   r9   r  r  r   r   r_   r   r   r  r  r8  rv  ptrptrrj  r  r>   r>   r?   r  G  s>   
z9_make_flattening_iter_cls.<locals>.FlatIter.init_specificc              	      sH  |j }t |j|}t |j|}| j| j}	|tj	d}
 
d}t  | j}t | |d  | W d    n1 sJw   Y  |d t |	|d } |}t| ||}dkrs|| n fddt|D }t |}|t ||g tt|D ]y}t |}t  |}|| }|| } d	||}t |C  || t |	|} |}t ||} || t|d |D ]}t |	|} || q | W d    n	1 sw   Y   |
| q tj| j  |  | d S )
Nr   r  FTrA   re  c              	      r  r>   r  r  r  r>   r?   r     r  zQ_make_flattening_iter_cls.<locals>.FlatIter.iternext_specific.<locals>.<listcomp>r   )r_   r	   r   rU   r   r   r  r   r   ry   r;  r  r:   r  r  r   rI  rX   rs   r   r6   rZ   r  r  r   r   rp  r   r   rq  rJ  )rM   rk   r9   r  r  r   r_   r   r   r  r   ru  is_exhaustedZlast_ptrr[   r   r  r  r8  rv  r|   r   r  rw  r  Z	inner_dimr  r  r?   r  h  sn   





z=_make_flattening_iter_cls.<locals>.FlatIter.iternext_specificc              	   S   s   |j }tj||j|d}tj||j|d}g }	tt|D ]}
|	||||
  |	|||
 }q|	
  t|||j|||j|	}|S )Nr   )r_   r	   r   rU   r   r  r6   rY   ZuremZudivreverser  r   r  )rM   rk   r9   r  r  r   r_   r   r   r   r8  r[   r>   r>   r?   _ptr_for_index  s   z:_make_flattening_iter_cls.<locals>.FlatIter._ptr_for_indexc                 S   s    |  |||||}t||||S r  )r  rs   r  r>   r>   r?   r    s   z3_make_flattening_iter_cls.<locals>.FlatIter.getitemc                 S   s&   |  |||||}t||||| d S r  )r  rv   r  r>   r>   r?   r    s   z3_make_flattening_iter_cls.<locals>.FlatIter.setitemN)	r`   ra   rb   r5  r  r  r  r  r  r>   r  r>   r?   FlatIter?  s    !Er  )rS   r  r	   rf   )rh  r8  rS   r  r  r>   r  r?   rg    s   
D rg  re  c                 C   sh   t t|}|| |}||_| |}|| ||dd}|| ||| | }t| |t||S Nr   )rN   )	ri  r   NumpyFlatTyper   rg   rW   r  r   r    )rk   r9   r  r  flatiterclsflatiterarrclsr   r>   r>   r?   make_array_flatiter  s   

r  c                 C   Z   |j \}|\}t|}|| ||d}|j}| |}	|	| ||jd}
|| |||
| d S r  )r   ri  rS   rg   r   r  )rk   r9   rO   r   r   rh  r  r  r  r  r  r>   r>   r?   iternext_numpy_flatiter     
r  c                 C   sj   |j d }|\}}t|}|| ||d}|j}| |}	|	| ||jd}
|| |||
|}t| ||j|S Nr   r   )r   ri  rS   rg   r   r  r    r   )rk   r9   rO   r   rh  r  r   r  r  r  r  r   r>   r>   r?   iternext_numpy_getitem  s   

r  c                 C   sf   |j d }|\}}}t|}|| ||d}|j}	| |	}
|
| ||jd}|| ||	||| |  S r  )r   ri  rS   rg   r   r  r'  )rk   r9   rO   r   rh  r  r   r   r  r  r  r  r>   r>   r?   iternext_numpy_getitem_any  s   


r  c           	      C   sF   |j d }t|}|| ||d d}| |j}|| ||jd}|jS r  )r   ri  rg   rS   r   r   )	rk   r9   rO   r   rh  r  r  r  r  r>   r>   r?   iternext_numpy_getitem_flat
  s   
r  c           
      C   sr   |j \}|\}tt|}|| |}||_| |}|| ||dd}|| ||| | }	t	| ||j
|	S r  )r   rn  r   NumpyNdEnumerateTyper   rg   rW   r  r   r    r   )
rk   r9   rO   r   r  r  	nditerclsrz  r  r   r>   r>   r?   make_array_ndenumerate  s   

r  c                 C   r  r  )r   rn  rS   rg   r   r  )rk   r9   rO   r   r   rm  rz  r  r  r  r  r>   r>   r?   iternext_numpy_nditer'  r  r  c                    s^    fddt |j|D }ttt|}| }| | | }t |j	|S )zndindex(*shape)c                    r"  r>   r#  )r   Zargtyr  r   r>   r?   r   ;  r$  z&make_array_ndindex.<locals>.<listcomp>)
r   r   r  r   NumpyNdIndexTyper   r  r   r    r   )rk   r9   rO   r   rU   r  rz  r   r>   r   r?   make_array_ndindex7  s   

r  c           
         s   |j j}|dkr%|jd j|d }t ||} fdd|D }ng }ttt	|}| }|
 | | }	t |j |	S )zndindex(shape)r   c                    s   g | ]}  |tjqS r>   r#  r   r9   rk   r{   r>   r?   r   P      z,make_array_ndindex_tuple.<locals>.<listcomp>)r   r_   r   ri   r	   r   r  r   r  r   r  r   r    )
rk   r9   rO   r   r_   r  rU   r  rz  r   r>   r  r?   make_array_ndindex_tupleF  s   
r  c                 C   s6   |j \}|\}t|}|| ||d}|| || d S r  )r   r  r  )rk   r9   rO   r   r   rm  rz  r  r>   r>   r?   iternext_numpy_ndindex]  s
   r  c           	      C   sn   |j }|j}t|jd tjrt||d }n|d g}t|| |}|	| ||| |
 }t| |||S )z
    nditer(...)
    r   )r   r  r   r   r   r  r	   r   r  r  r   r    )	rk   r9   rO   r   rm  r  r  rz  r   r>   r>   r?   make_array_nditeri  s   
r  c                 C   s2   |j \}|\}t|| ||d}|| || d S r  )r   r  r  )rk   r9   rO   r   r   rm  rz  r>   r>   r?   iternext_numpy_nditer2}  s   r  c                 C   s4   |j \}}ttdt||k}t| ||j|S rS  )r   r   r   r/  r   r"   r   )rk   r9   rO   r   Zarg1Zarg2r   r>   r>   r?   dtype_eq_impl  s   
r  c                 C   sb  t |}|| |}| |j}| tjt| |}| tjd}tt	dd}	|D ]}
|
||
}||d}||	||d}	q*|jdkrKd}nN|jdkrp|g}t|dd D ]}|||d | q[tt|}n)|jdkr|g}|dd D ]}|||d | q~t|}ntd|j|
||}||d}||	||d}	|j|	d	d
 | j|td W d   n1 sw   Y  |j}| |}| tj|}|  ||f}ttj}tt|}t ||tjtj}| !|t"||}| j#$||}| %tj}t&j'|||d}t&j'|||d}t(||)||* ||||d |S )a	  Utility function used for allocating a new array during LLVM code
    generation (lowering).  Given a target context, builder, array
    type, and a tuple or list of lowered dimension sizes, returns a
    LLVM value pointing at a Numba runtime allocated array.
    rA   r   r>   r   NrM  r  z3Don't know how to allocate array with layout '{0}'.Fr!  )z[array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.)r  r6  )+rg   rh   ri   r   r   ry   rm   r   r   r/  Zsmul_with_overflowr  r  r_   r  r  rY   r   r   rG   r   r   r"  r#  r   Zget_preferred_array_alignmentZuint32r'  MemInfoPointervoidptrZTypeRefr7   r$   r<  _call_allocatorr   Zmeminfo_datar   r	   rZ   r   r  r;  )rk   r9   r  r   r  r   datatyper   Zarrlenoverflowr   Zarrlen_multr   Zdimension_sizeZallocsize_multr  ri   Z	align_valro   r   mipZarytypeclassargtypesr   r   r   Zshape_arrayZstrides_arrayr>   r>   r?   r    st   




	
r  	_allocatec                 C   s   dd }|S )zTImplements a Numba-only default target (cpu) classmethod on the array
    type.
    c                 S   s
   t ||S r  )intrin_alloc)clsr  ro   r>   r>   r?   r     rX  z _ol_array_allocate.<locals>.implr>   )r  r  ro   r   r>   r>   r?   _ol_array_allocate  s   r  c                 C   s   |  ||S )z9Trampoline to call the intrinsic used for allocation
    )r  )r  r}   ro   r>   r>   r?   r    s   r  c                 C   s(   dd }t t j}t|||}||fS )z3Intrinsic to call into the allocator for Array
    c                 S   s   |\}}| j |||}|S r  )r   Zmeminfo_alloc_aligned)rk   r9   r$   r   r  ro   r   r>   r>   r?   r    s   zintrin_alloc.<locals>.codegen)r   r  r  r$   )r  r  ro   r  r  rO   r>   r>   r?   r    s   r  c              	   C   s   dd }t |tjrd}| |||tjg}nt |tjsJ |j}tj|||d}g }|D ]}|	|| ||j
| q.| |tjd}	t|D ])}
|d||
 |	}t|| | j|td W d   n1 slw   Y  qH|S )	z;
    Parse the shape argument to an array constructor.
    c           
      S   s   |  tj}|j}t|}t|d|d > d }|j|k r&|||}|S |j|kr`|d||}	|j	|	dd | j
|td W d   n1 sLw   Y  |j|kr^|||}|S |}|S )z0Cast src to intp only if value can be maintainedrA   >Fr!  )z#Cannot safely convert value to intpN)r   r   ry   rB   r   r/  r   Zsextr   r   r"  r#  r   trunc)
rk   r9   Zsrc_tr  r   Z
intp_widthZintp_irmaxvalr   Z	is_largerr>   r>   r?   safecast_intp  s(   



z#_parse_shape.<locals>.safecast_intprA   r   r   r   )znegative dimensions not allowedN)r   r   r   rx   ry   r  r   r	   r   rY   r7   get_constant_genericr6   r   r  r"  r#  r   )rk   r9   r  ru   r  r_   Zpassed_shapesr   r   r   r8  Zis_negr>   r>   r?   _parse_shape  s(   r  c                 C   s*   |j d }|d }|j}|t| |||fS )zL
    Parse the arguments of a np.empty(), np.zeros() or np.ones() call.
    r   )r   r   r  )rk   r9   rO   r   ZarrshapetypeZarrshaper  r>   r>   r?   _parse_empty_args.  s   
r  c                 C   sT   |j d }t|tjr%t|| ||d d}tj||j|jd}|j	|fS |j	dfS )z_
    Parse the arguments of a np.empty_like(), np.zeros_like() or
    np.ones_like() call.
    r   r   r   r>   )
r   r   r   r   rg   r	   r   rU   r_   r   )rk   r9   rO   r   arytyper   r   r>   r>   r?   r*  8  s   


r*  c                 C   s&   t |tjrd|  d}t|d S )NzIf np.z0 dtype is a string it must be a string constant.)r   r   ZUnicodeTyper   r   )fnameri   r   r>   r>   r?   _check_const_str_dtypeF  s   
r  c                 C   "   |j }||||}dd }||fS )Nc                 S   (   t | |||\}}t| |||}| S r  )r  r  r   r  r9   rO   r  r  r   r   r>   r>   r?   r  Q     znumpy_empty_nd.<locals>.codegenZinstance_type)r  Zty_shapety_dtypety_retty_refty_rettyrO   r  r>   r>   r?   numpy_empty_ndL     r  c                    s   t d| |tu st|tjr|jtu st|rtj}nt|}t	| }|d ur>|d ur>tj
||dd tf fdd	}|S d|  d| d}t|)	Nr  r   r3  c                       t | | S r  )r  )rU   ri   rx  r>   r?   r   f  rT  zol_np_empty.<locals>.implz.Cannot parse input types to function np.empty(r  r  )r  floatr   r   Function
typing_keyr   doublety_parse_dtypety_parse_shaper   r   r   )rU   ri   nb_dtyper_   r   r   r>   r	  r?   ol_np_emptyX  s    



r  c                 C   r  )Nc                 S   r  r  )r*  r  r   r   r>   r>   r?   r  s  r  z$numpy_empty_like_nd.<locals>.codegenr  )r  Zty_prototyper  r  r  rO   r  r>   r>   r?   numpy_empty_like_ndn  r  r  c                    s   t d| t|st|}nt| tjr| j}n| }|d ur?t| tjr7| jdkr,| jnd}| j||dd nt|dd nd|  d| d	}t	
|d fd
d	}|S )Nr  r  r   F)ri   r  r  r   z3Cannot parse input types to function np.empty_like(r  r  c                    r  r  )r  )r  ri   r	  r>   r?   r     rT  zol_np_empty_like.<locals>.implr  )r  r   r  r   r   r   ri   r  r  r   r   )r  ri   r  r  r   r   r>   r	  r?   ol_np_empty_likez  s&   


r  c                 C   r  )Nc                 S   s<   t |jd | ||d }t||j||j|jd d S r   )rg   r   r	   r+  r   r   r   r   )r  r9   rO   r  r   r>   r>   r?   r    s   z(_zero_fill_array_method.<locals>.codegen)r   r  )r  rM   rO   r  r>   r>   r?   _zero_fill_array_method  s   
r  
_zero_fillc                 C   r  )z?Adds a `._zero_fill` method to zero fill an array using memset.c                 S   s   t |  d S r  )r  r,  r>   r>   r?   r     rT  z ol_array_zero_fill.<locals>.implr>   )rM   r   r>   r>   r?   ol_array_zero_fill  r6  r  c                 C   s   t d| tfdd}|S )Nr  c                 S      t j| |d}|  |S Nr  )r  r  r  )rU   ri   r  r>   r>   r?   r        zol_np_zeros.<locals>.impl)r  r
  rU   ri   r   r>   r>   r?   ol_np_zeros  s   
r  c                 C      t d| ddd}|S )N
zeros_likec                 S   r  r  )r  r  r  )r9  ri   r  r>   r>   r?   r     r  zol_np_zeros_like.<locals>.implr  r  r  r>   r>   r?   ol_np_zeros_like  s   

r  c                 C   r  )N	ones_likec                 S   2   t j| |d}|j}tt|D ]}d||< q|S Nr  rA   r  r  re  r6   r   )r9  ri   r  arr_flatr|   r>   r>   r?   r     
   
zol_np_ones_like.<locals>.implr  r  r  r>   r>   r?   ol_np_ones_like  s   

r&  c                    s2   t d| t|st| n| d fdd	}|S )Nfullc                    s0   t |  }|j}tt|D ]}|||< q|S r  r  r  re  r6   r   )rU   
fill_valueri   r  r$  r|   r  r>   r?   r'    
   
zimpl_np_full.<locals>.fullr  )r  r   r  )rU   r)  ri   r'  r>   r*  r?   impl_np_full  s   

r,  c                 C   s   t d| ddd}|S )Nr  c                 S   s0   t | |}|j}tt|D ]}|||< q|S r  r#  )r9  r)  ri   r  r$  r|   r>   r>   r?   r    r+  z$impl_np_full_like.<locals>.full_liker  r  )r9  r)  ri   r  r>   r>   r?   impl_np_full_like  s   

r-  c                 C   r  )Nonesc                 S   r!  r"  r(  )rU   ri   r  r$  r|   r>   r>   r?   r     r%  zol_np_ones.<locals>.implr  r  r  r>   r>   r?   
ol_np_ones  s   

r/  c                    s4   t d| t|st| ntj d fdd	}|S )Nidentityc                    s.   t | | f }t| D ]}d|||f< q|S rS  )r  r  r6   )r  ri   r  r]   r*  r>   r?   r0    s   z"impl_np_identity.<locals>.identityr  )r  r   r  r   r  )r  ri   r0  r>   r*  r?   impl_np_identity  s   

r1  c                 C   rQ  r  r>   NMr>   r>   r?   _eye_none_handler	  rR  r5  c                 C   s$   t |tjrdd }|S dd }|S )Nc                 S      | S r  r>   r2  r>   r>   r?   r     rR  z$_eye_none_handler_impl.<locals>.implc                 S      |S r  r>   r2  r>   r>   r?   r     rR  r   r   r  )r3  r4  r   r>   r>   r?   _eye_none_handler_impl  s
   r9  c                    sf   |d u s
t |tjrtt nt |tjtjfr"tt	|d| nt| d dtf fdd	}|S )Nri   r   c                    s   t | |}t| |f }|dkr)t| || }t|D ]
}d|||| f< q|S t| | |}t|D ]
}d||| |f< q4|S r  )r5  r  r  r  r6   )r3  r4  r   ri   Z_Mr  dr]   r  r>   r?   r   #  s   
znumpy_eye.<locals>.impl)
r   r   r  r  ri   r
  	DTypeSpecr  r   r  )r3  r4  r   ri   r   r>   r;  r?   	numpy_eye  s   
r=  c                 C   sD   t | s	tdt| tjr | jdvrtdddd}|S d S )N#The argument "v" must be array-like)rA   r&  zInput must be 1- or 2-d.r   c                 S   s*  | j dkrG| j}|d t| }t||f| j}|dkr2t|| D ]}| | |||| f< q#|S t|| D ]}| | ||| |f< q8|S | j\}}|dk rT|| }|dkr\|| }tt||d}t	|| j}|dkrt|D ]}| ||| f ||< qs|S t|D ]}| || |f ||< q|S r^  )
r_   rU   r-  r  r  ri   r6   r  r  r  )r   r   r   r  r  r]   rowscolsr>   r>   r?   	diag_impl;  s2   

zimpl_np_diag.<locals>.diag_implr  )r   r   r   r   r   r   r_   NumbaTypeError)r   r   rA  r>   r>   r?   impl_np_diag2  s   



rC  c                    sX   t | tjsd}t|t | jtjsd}t|t|  d   fdd}|S )Nz5The argument "dimensions" must be a tuple of integersr  c                    sV   t j f|  t jd}d}| D ]}t j|t jdt||}|||< |d7 }q|S )Nr  r   rA   )r  r  r  aranger  r.   )
dimensionsr   r]   r8  r|   r3  rU   r>   r?   r   f  s   

znumpy_indices.<locals>.impl)r   r   r  r   r   ri   r   r   )rE  r   r   r>   rF  r?   numpy_indicesY  s   

rG  c                 C   sB   t | sd}t|t|ttjfsd}t|ddd}|S )Nr>  z#The argument "k" must be an integerr   c           	      S   s   t | } |  } t| }t|}|| }t ||f| j}t d| }t d|}t|D ]}| | ||| || f< q/|S r   )	r  r  r  r   r-  r  ri   maximumr6   )	r   r   r   Zabs_kr  r   r]   jtr>   r>   r?   r     s   
znumpy_diagflat.<locals>.implr  )r   r   r   r   r   r   r   )r   r   r   r   r>   r>   r?   numpy_diagflatu  s   


rK  c                 C   s   |dv sJ |dkr'd}t d| D ]}d| }|d| dd| d	7 }qnd
}t d| D ]}d| }|d| dd| d7 }q.t|}t|t  t d|  }t|S )N)r  r  r  zv
            def _getitem(a, idx, axis):
                if axis == 0:
                    return a[idx, ...]
        rA   ):z
                elif axis == z:
                    return a[r  z, idx, ...]
            z|
            def _setitem(a, idx, axis, vals):
                if axis == 0:
                    a[idx, ...] = vals
        z:
                    a[z, idx, ...] = vals
            r  )r6   r  textwrapdedentexecglobalsr&   )r_   r8  rq  r]   lstr>   r>   r?   "generate_getitem_setitem_with_axis  s.   
rR  takec                    s8  t |rLt| tjrt|tjrddd}|S t| tjr2t|tjr2|jdk d fdd	}|S t| tjrHt|tjtjfrJddd}|S d S d S t| tjrpt|tjrpd| j	d  t
fdd	dfd
d	}|S t| tjrt|tjtjtjfr| j	}t|dt|ddfdd	}|S d S d S )Nc                 S   s.   || j d ks|| j  k rtd|  | S )NrA   Index out of bounds)r}   
IndexErrorr  )r9  r   r   r>   r>   r?   	take_impl  s   znumpy_take.<locals>.take_implr  c           	         s   t j|j| jd} r| }n|}t |}d}|  }|D ]}|| jd ks.|| j k r2td|| ||< |d }q||j	S )Nr  r   rA   rT  )
r  r  r}   ri   r  rz  r  rU  r  rU   )	r9  r   r   r  Zwalkeritr]   re  r  )F_orderr>   r?   rV    s   


c                 S   s   t |}t | |S r  )r  r   rS  )r9  r   r   convertr>   r>   r?   rV    s   
r  rA   c                    sv   t  }d}|t| jk r| j| dksJ | jtt| jD ]}| j| }||kr5t|||}|d7 }q | |S r  )r   r   rU   r6   r.   r  )r  r   r  rI  r|   r   )rJ  r>   r?   _squeeze  s   &

znumpy_take.<locals>._squeezec                    s@   t j| |f|d}| jdkr|d S |dk r|| j7 } ||S )Nr  rA   r   )r  rS  r_   )r9  r   r   r  )rZ  r>   r?   rV    s   


r  r  c                    s   |dk r	|| j 7 }|dk s|| j krd| d| j  }t|t| j|t|}tj|| jd}tt|D ]} | || |}|||| q6|S )Nr   zaxis z) is out of bounds for array of dimension r  )	r_   r   r.   rU   r   r  r  ri   r6   )r9  r   r   r   rU   r   r]   r  )_getitem_setitemr>   r?   rV    s   
r  )r	   r   r   r   r   r   r  r  r  r_   r&   rR  )r9  r   r   rV  r_   r>   )rX  r[  r\  rZ  rJ  r?   
numpy_take  s:   





r]  c                  G   s   dd | D }t dd |D rtj}|S t dd |D r#tj}|S ttddttj  }dd |D }t	||g }|S )	Nc                 S   s   g | ]
}t |tjs|qS r>   r8  r8  r>   r>   r?   r     r  z!_arange_dtype.<locals>.<listcomp>c                 s   r  r  rU  r8  r>   r>   r?   r    r  z _arange_dtype.<locals>.<genexpr>c                 s   r  r  )r   r   Floatr8  r>   r>   r?   r    r  zint%srX  c                 S   s   g | ]}t |qS r>   )r   Z	unliteralr  r>   r>   r?   r   #      )
r  r   
complex128r   r  r  ri   r   r   r  )r   Zboundsri   ZNPY_TYZunliteral_boundsr>   r>   r?   _arange_dtype  s   ra  c                   s  t |tjr	|j}t |tjr|j}t |tjr|j}|d u r"tj}|d u r)tj}|d u r0tj}t | tjrQt |tjtjfrQt |tjtjfrQt |tjtjfsSd S t |tjr`t| ||n|j	t
dd | ||fD t| dd  t|dd t|dd d fdd	}|S )Nc                 S   r  r>   rU  r  r>   r>   r?   r   E      znp_arange.<locals>.<listcomp>r   c                   s    d ur n| }d urn|}d urn|}|d ur|nd}|d u r*d|}}	n||}}	|dkr7t d|	| | }
tt|
j}du rZtt|
j}tt||d}nt|d}t	|}|}t
|D ]
}|||  ||< qk|S )NrA   r   zMaximum allowed size exceededT)r   r   mathceilrY  r[  r  r  r  r  r6   )r   rq  rk  ri   Z	lit_startZlit_stopZlit_stepZ_step_start_stopZnitems_cZnitems_rZnitems_ir   r  ru   r]   Zstart_valueZ
step_valueZ
stop_valueZ
true_dtypeZuse_complexr>   r?   r   L  s(   

znp_arange.<locals>.implr  )r   r   Optionalr7   r  r  r  r<  ra  ri   r  r  )r   rq  rk  ri   r   r>   rg  r?   	np_arange)  s>   ri  c                    s|   t dd | |fD sd S t|ttjfsd}t|tdd | |fD r2tj	r.tj
 ntj ntj d fdd	}|S )	Nc                 s   r  r  )r   r   r  rW  r>   r>   r?   r  o  r  z!numpy_linspace.<locals>.<genexpr>rT  c                 s   r  r  rU  rW  r>   r>   r?   r  v  r  rN  c                    s   t | }| d } |d }|dkr|S |d }|dkr7||  }t ||}td|D ]
}| ||  ||< q+n| |d< |dkrC||d< |S )Ng      ?r   rA   rM  )r  r  divider6   )r   rq  rQ  r  divdeltark  r]   r  r>   r?   rO    s    z numpy_linspace.<locals>.linspacerR  )r  r   r   r   r   r   r   r  r   ZUSE_LEGACY_TYPE_SYSTEMr`  Znp_complex128r   )r   rq  rQ  r   rO  r>   r  r?   numpy_linspacem  s   
rm  c              
   C   s0  |j d }t|| ||d d}t||j}|j}t| |||}|j}	|j}
|jdv s.J |j|jkrBtj	||
|	|j
|jdd nLt||j}t||j}| tj}t|||)}t| ||	|||j|}t| ||
|||j|}|||| W d   n1 sw   Y  t| ||j| S )z
    Array copy.
    r   r   r  rA   rn   N)r   rg   r	   r   rU   r   r  r   r  Z
raw_memcpyr   r   r   r   r   ry   r  r  r   r:   r!   r   )rk   r9   rO   r   r  r   r   rettyper  r  r  r  r  r   r   r  r  r>   r>   r?   _array_copy  s6   


	ro  c                 C   s@   t |tjsJ |jdkrdnd}|j|dd}||}|tfS )Nr  r   F)r  r  )r   r   r   r  r  ro  )r  r9  r  r  rO   r>   r>   r?   _array_copy_intrinsic  s
   rp  z
array.copyc                 C   r  r  )ro  r+  r>   r>   r?   
array_copy  r  rq  c                 C   s   t | tjr
dd }|S )Nc                 S      t | S r  )rp  r  r>   r>   r?   
numpy_copy  rC  z#impl_numpy_copy.<locals>.numpy_copyr  )r9  rs  r>   r>   r?   impl_numpy_copy  s   rt  c              	   C   s  |j }|jd }|j|ksJ d|jdkr`|jdksJ t|| ||d d}t|| |}| |ttjdd}	| 	|ttjd|j
f}
t||j|	|
|j
|j|j t| ||| S |j|jksp|jdkry|jdv ryt| |||d S |jdkr|dv sJ |dkrtnt}t|| |||d }||D\}}| t| |||d }|j}W d	   n1 sw   Y  | t| |||}|j}W d	   n1 sw   Y  W d	   n1 sw   Y  ||j}||| ||| |S t| |||S )
zd
    Common logic for layout conversion function;
    e.g. ascontiguousarray and asfortranarray
    r   z return-type has incorrect layoutrA   r   r  r  r  r   N)r   r   r  r_   rg   r  r   r  ry   r  r   r   r   r   r   r    r   r   r   r  r  blockro  phir7   Zadd_incoming)rk   r9   rO   r   output_layoutrx  r   r   r  rU   r   Z
check_funcr  ZthenorelseZout_thenZthen_blkZ
out_orelseZ
orelse_blkZret_phir>   r>   r?   _as_layout_array  s`   


ry  c                    sH   t  tjst |j jt|jdd}|| }| fddfS )NrA   )r  r_   c                    s   t | ||| jdS )Nrw  )ry  r   )rb  r  r   r9  rz  r>   r?   r    s    z,_as_layout_array_intrinsic.<locals>.<lambda>)	r   r   r%   r   RequireLiteralValuer  r   r  r_   )r  r9  rw  r  rO   r>   rz  r?   _as_layout_array_intrinsic  s
   

r|  c                 C   sH   t | s	tdt| tjtjfrdd }|S t| tjr"dd }|S )Nr  c                 S      t t | S r  )r  ascontiguousarrayr   r  r>   r>   r?   r   &  rm  z%array_ascontiguousarray.<locals>.implc                 S   rd  Nr   r|  r  r>   r>   r?   r   )  rX  r   r   r   r   r   r  ru  r   r  r>   r>   r?   array_ascontiguousarray   s   
r  c                 C   sL   t | s	tdt| tjtjfrdd }|S t| tjr$dd }|S d S )Nr  c                 S   r}  r  )r  asfortranarrayr   r  r>   r>   r?   r   4  rm  z"array_asfortranarray.<locals>.implc                 S   rd  )Nr  r  r  r>   r>   r?   r   8  rX  r  r  r>   r>   r?   array_asfortranarray.  s   
r  zarray.astypec              
   C   s  |j d }t|| ||d d}t||j}|j}t| |||}|j}	|j}
t||j}t||j}| 	t
j}t|||9}t| ||	|||j|}t| ||
|||j|}t| |||}| |||j|j}t| |||| W d    n1 s~w   Y  t| ||j| S r  )r   rg   r	   r   rU   r   r  r   r   r   r   ry   r  r  r  rs   rx   ri   rv   r!   r   )rk   r9   rO   r   r  r   r   rn  r  r  r  r  r  r   r   r  r  itemr>   r>   r?   array_astype=  s0   


r  c                 C   r  )Nc              	   S   s2  |j d }|j}t|| ||d d}t|}|| |}|j}	t| |}
t|jj|
}||j	|j}|
||}t||}|j|dd d}| j|t|f W d    n1 s\w   Y  t||||g}t||g}||j| |	d}t||||||j|jd | }t| ||j|S )Nr   r   Fr!  z.buffer size must be a multiple of element sizer   r  )r   r   rg   r   rm   r   r   r7   r   r   Zsremr	   Zis_not_nullr   r"  r#  r   rZ   Zsdivr  r   r   r   r   r   r   r   r    )rk   r9   rO   r   Zbuftyr   r\  Z
out_ary_tyout_aryZout_datamodelr   ll_itemsizer  remZis_incompatibler   rU   r   r   r   r>   r>   r?   r  a  s<   


znp_frombuffer.<locals>.codegenr  )r  bufferri   rx  r  rO   r  r>   r>   r?   np_frombuffer\  s   $r  c                    s   t d| t| tjr| jdkrd|  }t||tu s-t|tjr)|j	tu s-t
|r1tj}nt|}|d urEtj|dd| j d nd|  d| d}t|tf fd	d
	}|S )N
frombufferr   z+Argument "buffer" must be buffer-like. Got rA   )ri   r_   r  r  z3Cannot parse input types to function np.frombuffer(r  r  c                    r  r  )r  )r  ri   r	  r>   r?   r     rT  z impl_np_frombuffer.<locals>.impl)r  r   r   r   r  r   r   r
  r  r  r   r  r  r   r  )r  ri   r   r  r   r>   r	  r?   impl_np_frombuffer  s0   






r  c                    P   t |rtdd  d fdd	}|S t|tjr&td| d fdd	}|S d S )Nr   c                    
    | |S r  r>   r[   rU   ri   intrinsic_cfarrayr>   r?   r     rX  zimpl_carray.<locals>.implc                    r  r  r>   r  r  r>   r?   r     rX  r  r   get_cfarray_intrinsicr   r   r<  r[   rU   ri   r   r>   r  r?   impl_carray     

r  c                    r  )Nr  c                    r  r  r>   r  r  r>   r?   r     rX  zimpl_farray.<locals>.implc                    r  r  r>   r  r  r>   r?   r     rX  r  r  r  r>   r  r?   impl_farray  r  r  c                    s   t  fdd}|S )Nc           	         s   |t ju rd }nt|t jr|j}nd| d}t| d u r/|d u r,d}t||}n+t t jrO j}|d urN||krNd| d| d}t|nd  d}t|t|}|d u rmd| d}t|t 	||}t
|||}|tfS )Nz pointer argument expected, got ''z*explicit dtype required for void* argumentzmismatching dtype 'z' for pointer type 'zinvalid dtype spec 'zinvalid shape ')r   r  r   CPointerri   r   rB  r<  r  r   r$   
np_cfarray)	r  r[   rU   Z	ptr_dtyper   ri   r_   rx  rO   dtype_r  r>   r?   r    s4   





z0get_cfarray_intrinsic.<locals>.intrinsic_cfarrayr)   )r  r  r  r>   r  r?   r    s   r  c                    s<  |j dd \}}|dd \}}|j}|jdv sJ t| }	t|}
t|
}t|tj	r9t
 |}n|f}|f} fddt||D }|}g }|jdkrf|D ]}||  ||}qWnt|D ]}||  ||}qj|   ||j }t|	||||dd |	 }t |j|S )zR
    numba.numpy_support.carray(...) and
    numba.numpy_support.farray(...).
    Nr&  r  c                    r"  r>   r#  )r   r  r   r   r>   r?   r     r$  znp_cfarray.<locals>.<listcomp>r  r6  )r   r   r  rg   rm   r	   r   r   r   r  r   r   rY   r   r  r  r  rh   ri   r;  r   r   r!   )rk   r9   rO   r   r  r&  r[   rU   r   r  r   r  r   offr   r   r   r   r>   r   r?   r    sJ   




	r  c                 C   sN   t |tjr| tjt|S t |tjr%| tttj|}|||fS J r  )	r   r   r  r   ry   r   r  rF   r$   )rk   r9   seqtyseqr!  r>   r>   r?   _get_seq_size  s   r  c                    s2   |j  tjt|tj fdd}|S )zK
    Return a getitem() implementation that doesn't incref its result.
    c                    s$   | |} j r j| | |S r  )r   r   Zdecref)r9   r   r  rk   r  rx  r>   r?   wrap.  s   
z$_get_borrowing_getitem.<locals>.wrap)ri   rF   r  r  r$   r   ry   )rk   r  r  r>   r  r?   _get_borrowing_getitem&  s   r  c                    st    tj}t|d fdd}g }||}}	t|D ]}
|
dkr+|||	\}}	|t ||	 qt|S )zF
    Compute the likely shape of a nested sequence (possibly 0d).
    r   c                    sN   t | tjrt| dkrdS | d  |dfS t| }| j| |ffS )Nr   NN)r   r   r  r   r  r  ri   )r  r  r  r9   rk   r   r>   r?   get_first_item>  s   
z.compute_sequence_shape.<locals>.get_first_item)r   r   ry   r   r6   rY   r  r   )rk   r9   r_   r  r  r   r  r   innertyinnerr]   r>   r  r?   compute_sequence_shape7  s   

r  c                    s0   fdd  fdd||| dS )z?
    Check the nested sequence matches the given *shapes*.
    c                      s   j  td d S )N)zincompatible sequence shape)r"  r#  r   r>   r   r>   r?   _failZ  s   
z#check_sequence_shape.<locals>._failc                    s<  t |dkrd S t| |}|d }d||}j|dd    W d    n1 s/w   Y  t |dkr<d S t| tjrut| }t	|}| j
}|||jf}	||	|dd   W d    d S 1 snw   Y  d S t| tjrtt | D ]}
| |
 }||
}	||	|dd   qd S J | )Nr   r   Fr!  rA   )r   r  r   r   r   r   r  r  r	   r`  ri   r   r  r6   r  )r  r  r   r}   expectedr  r  ra  r  r  r]   r  r9   check_seq_sizerk   r>   r?   r  ^  s0   
"z,check_sequence_shape.<locals>.check_seq_sizeNr>   )rk   r9   r  r  r   r>   r  r?   check_sequence_shapeU  s   r  c                    s:    fddfdd||d dS )zl
    Assign a nested sequence contents to an array.  The shape must match
    the sequence's structure.
    c              
      sB   t j j| dd}|| j}t || d S r  )r	   r  r  rx   ri   rv   )r   r  ru   r[   )r  r9   rk   r   r   r   r>   r?   assign_item  s
   z-assign_sequence_to_array.<locals>.assign_itemc                    s  t |dkrt| tjtjfrJ || | d S |d }t| tjr[t| }t|#}| j}|||j	f} |||dd  ||j	f  W d    d S 1 sTw   Y  d S t| tjrt
t | D ]!}	| |	 }||	}tj|	}
 |||dd  ||
f  qgd S J | r  )r   r   r   r  r  r  r	   r`  ri   r   r6   r  r   ry   )r  r  r   r   r}   r  ra  r  r  r]   r   )assignr  r9   rk   r>   r?   r    s(   
 "z(assign_sequence_to_array.<locals>.assignr>   Nr>   )rk   r9   r   r   r   r  r  r  r>   )r  r  r  r9   rk   r   r   r   r?   assign_sequence_to_array~  s   r  c                 C   s>   t | |\}}t|r|}n
t|}|d u rd S t||dS r  )r3   r   r  r   r   )r  r  ri   r_   Z	seq_dtyper>   r>   r?   np_array_typer  s   r  c                 C   s0   t d| t| ||}|||}dd }||fS )Nr   c           
   	   S   s   |j }|j}|jd }|d }t| ||||}t||ksJ t| |||| t| |||}	t| ||	j||	j	||| t
| ||j |	 S r   )r   r_   r   r  r   r  r  r  r   r   r!   r   )
rk   r9   rO   r   r  r_   r  r  r   r  r>   r>   r?   r    s   


znp_array.<locals>.codegen)r  r  )r  objri   r  rO   r  r>   r>   r?   np_array  s
   

r  c                 C   sL   t d| t| stdt|st|d u rd}t|ddd}|S )Nr   z(The argument "object" must be array-likez:The argument "dtype" must be a data-type if it is providedc                 S   
   t | |S r  )r  )r  ri   r>   r>   r?   r     rX  zimpl_np_array.<locals>.implr  )r  r   r   r   r   r  )r  ri   r   r   r>   r>   r?   impl_np_array  s   



r  c           
      C   s   | d}| |}|d||}||||||}||d|||d||}|j|dd d| }	| j|t|	f W d    |S 1 sLw   Y  |S )Nr   r   rH  Fr!  z%s(): axis out of bounds)	r7   r   rp  rW  r  r   r"  r#  rU  )
rk   r9   r   r_   r   r   Zll_ndimZis_neg_axisZaxis_out_of_boundsr   r>   r>   r?   _normalize_axis  s   


r  c              
   C   s   t ||d ks
J ttj|}t||}td}t|d D ])}t|}	|d|	|}
|| }||
|	|	||	}|
|t||d| q"|
|t||d| t|||S )z
    Compute shape with the new axis inserted
    e.g. given original shape (2, 3, 4) and axis=2,
    the returned new shape is (2, 3, 1, 4).
    rA   rH  r   r   r   r:  r	   r   rK   r6   r   rp  rW  r   rX   r   r:   )rk   r9   
orig_shaper_   r   ll_shtyr   r   r8  ll_dim
after_axisr  r|   r>   r>   r?   _insert_axis_in_shape  s   


r  c              
   C   s   t ||d ks
J ttj|}t||}td}td}t|d D ]'}	t|	}
|d|
|}|||	|
||
}|
||	 t||d| q'|
|t||d| t|||S )zD
    Same as _insert_axis_in_shape(), but with a strides array.
    rA   r   rH  r  )rk   r9   orig_stridesr_   r   r  r   r   r   r8  r  r  r|   r>   r>   r?   _insert_axis_in_strides  s"   




r  c              	   C   s   |j }|j}|jd }t|| ||d d}t|| |}	t||j}
t||j}t| ||
||}t	| ||||}t
|	|j|||j|j|jd |	 S )z/
    np.expand_dims() with the given axis.
    r   r   r  )r   r_   r   rg   r	   r   rU   r   r  r  r   r   r   r   r   r   )rk   r9   rO   r   r   rx  r_   r  r  r  r   r   Z
new_shapesZnew_stridesr>   r>   r?   expand_dims(  s$   
r  c                 C   sB   |j dkr|jnd}|j|j d |d}|||}dd }||fS )NrA   r  r  c                 S   sP   |  ||d |jd tj}t| |d|jj|}t| ||||}t| ||j|S )NrA   znp.expand_dims)	rx   r   r   ry   r  r   r_   r  r    )rk   r9   rO   r   r   r  r>   r>   r?   r  J  s   znp_expand_dims.<locals>.codegen)r_   r  r  )r  r9  r   r  r  rO   r  r>   r>   r?   np_expand_dimsD  s
   
r  c                 C   sL   t | tjsd|  }t|t |tjs d| }t|dd }|S )Nz)First argument "a" must be an array. Got z(Argument "axis" must be an integer. Got c                 S   r  r  )r  )r9  r   r>   r>   r?   r   _  rX  z!impl_np_expand_dims.<locals>.impl)r   r   r   r   r   r   )r9  r   r   r   r>   r>   r?   impl_np_expand_dimsU  s   



r  c                    s   t  fddfddS )Nc                    sX   | fdd|D  fdd}t tdkr tnd tj||fS )Nc                    s    g | ]}|j t|j d qS )r  )r  r  r_   rW  )minimumr>   r?   r   h  r  z-_atleast_nd.<locals>.impl.<locals>.<listcomp>c                    sn   t t |d } fddt|D }t|dkr+ |j|}n|d }t |j|S )Nr   c                    s"   g | ]\}}} |||qS r>   r>   )r   r  r  rx  r9   rk   	transformr>   r?   r   n  s    z>_atleast_nd.<locals>.impl.<locals>.codegen.<locals>.<listcomp>rA   )_atleast_nd_transformr	   r   r   r   r  r   r    )rk   r9   rO   r   arrsZretsr  )r  rH  r  r  r  r?   r  j  s   

z*_atleast_nd.<locals>.impl.<locals>.codegenrA   r   )r$   r   r   r  ZStarArgTupleZ
from_types)Ztypingcontextr   r  )rH  r  )r  r  r?   r   e  s   
z_atleast_nd.<locals>.implc                     s    |  S r  r>   r  )r   r>   r?   r  z  s    z_atleast_nd.<locals>.<lambda>r  )r  rH  r>   )rH  r   r  r?   _atleast_ndd  s   r  c                    s"   t  ksJ  fdd}|S )z`
    Return a callback successively inserting 1-sized dimensions at the
    following axes.
    c           	         sb   t D ]*}|d }|j|k r.t | }|j|jd d}t| |t|||f|}|}q|S )NrA   r  )r6   r_   r	   r   r  r  r   r$   )	rk   r9   r  r  rx  r]   r_   r   ZnewarrtyrH  min_ndimr>   r?   r    s   
z(_atleast_nd_transform.<locals>.transform)r   )r  rH  r  r>   r  r?   r  }  s   r  c                  G   s"   t dd | D rtddgS d S )Nc                 s   r  r  r  rW  r>   r>   r?   r    r  z np_atleast_1d.<locals>.<genexpr>rA   r   r  r  r  r>   r>   r?   np_atleast_1d  s   r  c                  G   s$   t dd | D rtdddgS d S )Nc                 s   r  r  r  rW  r>   r>   r?   r    r  z np_atleast_2d.<locals>.<genexpr>r&  r   r  r  r>   r>   r?   np_atleast_2d     r  c                  G   s$   t dd | D rtdg dS d S )Nc                 s   r  r  r  rW  r>   r>   r?   r    r  z np_atleast_3d.<locals>.<genexpr>rf  )r   r   r&  r  r  r>   r>   r?   np_atleast_3d  r  r  c	                 C   s  t |t |  krt |  krt |ksJ  J td}	t| |||}
t||
j}g }|D ]2}|	}tt||D ]!\}\}}|d|	||}|
||}||||||}q=|| q2|
j}t|||||D ]_\}}}}}|j}tj||tj|jd}|9}t| |||||j|}t| |||}| |||j|j}t| |||||j|}t| |||| W d   n1 sw   Y  t|||}qp|
S )z2
    Concatenate arrays along the given axis.
    r   r  )orderN)r   r	   r   r  r   r   r  r   r   r7   r   rp  rW  rY   r   r  r  r  rs   rx   ri   rv   r   )rk   r9   r   r  r  
arr_shapesarr_stridesrx  
ret_shapesr   r  Zret_stridesZcopy_offsetsZarr_shr   r8  r}   r  is_axisaddendZret_datar  r  Zarr_stZarr_datar  r   r  ru   r  r>   r>   r?   _do_concatenate  sL   6



r  c                    s  |j } fddt||D }t d||} fdd|D } fdd|D } fdd|d D }	t|D ] d||}
|	 } |}fd	d|d
d  D } |
v\}}| t	 j
||g } || W d    n1 sw   Y  |@ tj}|D ]} | d||}q j |dd j td f W d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  q9 fdd|	D }	t |||||||		}t || S )Nc                    "   g | ]\}}t | |d qS r   r4  r   r`  r9  r   r>   r?   r     r$  z#_np_concatenate.<locals>.<listcomp>np.concatenatec                       g | ]	}t  |jqS r>   )r	   r   rU   r   r  r  r>   r?   r     r  c                    r  r>   r	   r   r   r  r  r>   r?   r     r  c                    s   g | ]}t  |qS r>   )r	   r   r  r  r>   r?   r     rb  r   r  c                    s   g | ]}|  qS r>   r>   r  )r8  r>   r?   r     r{  rA   Fr!  z<np.concatenate(): input sizes over dimension %d do not matchc                    s   g | ]}  |qS r>   )r:   r  r  r>   r?   r     r_  )r_   r   r  r6   r   r7   r:   r  r  r  rW  r   r	   r  r  r   rf  r"  r#  r   r  r!   r   )rk   r9   r  r  rx  r   r_   r  r  r  r  Zret_shape_ptrZret_shZother_shapesZon_axisZon_other_dimr  is_okr  r>   )r9   rk   r8  r?   _np_concatenate  s`   

r  c                    s  |j }td}td}tt|}	 fddt||D }t d||}t |d j}
|dd  D ]A}tj}tt |j|
D ]1\}} 	| 
d||} j |dd j td	 W d    n1 ssw   Y  qGq8 fd
d|D }ttj|t }t }t|d D ]5}t|} 
d||}|
| } | |||} |t |d|  |t |d| q |t |d|  |	t |d| t  |}|gt| }t  |} fddtt|D }t|d D ]6}t|} 
d||} | |||}tt|D ]} || | t || d| q6qtt|D ]} |t || d| qT fdd|D }t |||||||	}t || S )Nr   rA   c                    r  r  r4  r  r   r>   r?   r     r$  z_np_stack.<locals>.<listcomp>np.stackr  Fr!  )z5np.stack(): all input arrays must have the same shapec                    r  r>   r  r  r  r>   r?   r   .  r  rH  c                    r/  r>   r0  rz  )r9   r  r>   r?   r   O  rb  c                    s   g | ]}t   |qS r>   )r	   r   r:   )r   r  r  r>   r?   r   d  r  )r_   r	   r   r   r   r  r   rU   r  r  r   r   rf  r"  r#  r   r   r:  rK   r6   rp  rW  r   rX   r:   r  r!   r   )rk   r9   r  r  rx  r   r_   r   r   Z
ll_narraysr  r  r  r  Zorig_shr  Zinput_shapesr  r8  r  r  r|   Zinput_stridesr]   r  r>   )r9   rk   r  r?   	_np_stack  s   








r  c                 C   sT   |d urt |tjsd S t| d|\}}|dkrd}t|t|}t|||S )Nr  r   z.zero-dimensional arrays cannot be concatenated)r   r   r   r4   r   rB  r5   r   )r  r  r   ri   r_   r   r  r>   r>   r?   np_concatenate_typern  s   
r  c                 C   s6   t | ||}t|tjsJ |||}dd }||fS )Nc              	   S   sF   |  ||d |jd tj}t| |t|jd t||d |j|S r^  )	rx   r   r   ry   r  r   r	   r   r   rk   r9   rO   r   r   r>   r>   r?   r    s   znp_concatenate.<locals>.codegen)r  r   r   r   )r  r  r   r  rO   r  r>   r>   r?   np_concatenate  s
   
r  c                 C      t | tjrddd}|S d S )Nr   c                 S   r  r  )r  r  r   r>   r>   r?   r     rX  z!impl_np_concatenate.<locals>.implr  r   r   r  r  r   r   r>   r>   r?   impl_np_concatenate     
r  c                 C   s0   |D ]}|j dk s|j dkrd}t|qdS )NrA   r&  z7np.column_stack() is only defined on 1-d and 2-d arrays)r_   r   rB  )rk   r   r  r9  r   r>   r>   r?   _column_stack_dims  s   
r  c                 C   sB   t | d|td\}}t|}t|||}||}dd }||fS )Nznp.column_stack)Zdim_chooserc                 S   s   t |jd }t||d }g }g }| tjd}t||D ]:\}	}
|	jdkr3|	|	 |	|
 q|	jdks:J |	j
dd}t||	}t| |||
f|}|	| |	| qt| ||||j|S )Nr   rA   r&  r  )r   r   r	   r   r   r   ry   r   r_   rY   r  r   r$   r  r  r   )rk   r9   rO   r   Zorig_arrtysZ	orig_arrsr  r  r   r  r  r  
expand_sigZnewarrr>   r>   r?   r    s$   



z np_column_stack.<locals>.codegen)r4   r  r5   r   r   )r  r  ri   r_   r  r  rO   r  r>   r>   r?   np_column_stack  s   
r  c                 C      t | tjrdd }|S d S )Nc                 S   rr  r  )r  r  r>   r>   r?   r     rC  zimpl_column_stack.<locals>.implr  r  r   r>   r>   r?   impl_column_stack     r  c              	   C   s*   t | |t|jd t||d |j|S )z/
    np.stack() with the given axis value.
    r   )r  r   r   r	   r   r   r  r>   r>   r?   _np_stack_common  s   r  c           	      C   sV   t | d|\}}tdd |D rdnd}t||d |}|||}dd }||fS )	Nr  c                 s   s    | ]}|j d kV  qdS )r  N)r  r8  r>   r>   r?   r    s    z"np_stack_common.<locals>.<genexpr>r  r   rA   c                 S   s,   |  ||d |jd tj}t| ||||S rS  )rx   r   r   ry   r  r  r>   r>   r?   r    s   z np_stack_common.<locals>.codegen)r4   r  r   r   )	r  r  r   ri   r_   r  r  rO   r  r>   r>   r?   np_stack_common  s   
r  c                 C   r  )Nr   c                 S   r  r  )r  r  r>   r>   r?   r     rX  zimpl_np_stack.<locals>.implr  r  r  r>   r>   r?   impl_np_stack  r  r  c                 C   s4   t | ||\}}t||}t|}t|||}|S r  )r4   r  r5   r   r   )r  r   r  Zndim_minri   r_   r  r  r>   r>   r?   NdStack_typer  s
   
r  c                 C   &   t | d|d}||}dd }||fS )Nz	np.hstackrA   c                    sf   |j d }|d j}|dkr| tjd t| ||| S |dkr#dnd  fdd}| ||||S )Nr   rA   c                    s   t j|  dS r  r  r  r  r>   r?   np_hstack_impl  r  z3_np_hstack.<locals>.codegen.<locals>.np_hstack_implr   r_   r   r   ry   r  r<  )rk   r9   rO   r   r  r_   r  r>   r  r?   r    s   

z_np_hstack.<locals>.codegenr  r  r  r  rO   r  r>   r>   r?   
_np_hstack     r  c                 C   r  )Nc                 S   rr  r  )r  r  r>   r>   r?   r     rC  zimpl_np_hstack.<locals>.implr  r  r>   r>   r?   impl_np_hstack  r  r  c                 C   r  )Nz	np.vstackr&  c                 S   sd   |j d }|d j}|dkrdd }n|dkr&| tjd}t| ||||S dd }| ||||S )Nr   c                 S   s   t t | dS rS  )r  r  hstackr  r>   r>   r?   np_vstack_impl)  r  z3_np_vstack.<locals>.codegen.<locals>.np_vstack_implrA   c                 S      t j| ddS )Nr   r  r  r  r>   r>   r?   r  2  r  r  )rk   r9   rO   r   r  r_   r  r   r>   r>   r?   r  $  s   


z_np_vstack.<locals>.codegenr  r  r>   r>   r?   
_np_vstack  r   r  c                 C   r  )Nc                 S   rr  r  )r  r  r>   r>   r?   r   =  rC  zimpl_np_vstack.<locals>.implr  r  r>   r>   r?   impl_np_vstack:  r  r  c                 C   r  )Nz	np.dstackrf  c                 S   s   |j d }|j}|d j}|dkrdd }| ||||S |dkrY| tjd}|j|jd d}	tj	|	g|j R  }
t
| ||
||}| tjd}t	||	}t| |||f|S |dkrl| tjd}t
| ||||S dd }| ||||S )Nr   c                 S   s   t | dddS )NrA   rM  )r  r  r  r  r>   r>   r?   r  Q  r  z3_np_dstack.<locals>.codegen.<locals>.np_vstack_implrA   r  r&  c                 S   r  )Nr&  r  r  r  r>   r>   r?   r  h  r  )r   r   r_   r<  r   r   ry   r  r   r$   r  r  )rk   r9   rO   r   r  rx  r_   r  r   Zstack_rettyZ	stack_sigZ	stack_retr  r>   r>   r?   r  K  s*   


z_np_dstack.<locals>.codegenr  r  r>   r>   r?   
_np_dstackF  s   "r  c                 C   r  )Nc                 S   rr  r  )r  r  r>   r>   r?   r   s  rC  zimpl_np_dstack.<locals>.implr  r  r>   r>   r?   impl_np_dstackp  r  r  fillc                 C   r}  )Nc                 S   s   || d d < d S r  r>   )r  ru   r>   r>   r?   	fill_impl{  s   zarr_fill.<locals>.fill_implr>   )r  ru   r
  r>   r>   r?   arr_fillx  s   r  dotc                 C   r}  )Nc                 S   r  r  )r  r  )r  otherr>   r>   r?   dot_impl  rT  zarray_dot.<locals>.dot_implr>   )r  r  r  r>   r>   r?   	array_dot  r  r  c                 C   "   t | std|  dd }|S )NzCannot np.fliplr on %s typec                 S   s4   t | }|jdk rtd|d d d d ddf S )Nr&  rd  rM  .r  r  r_   r   r  r  r>   r>   r?   r     s   

znp_flip_lr.<locals>.implr  r  r   r>   r>   r?   
np_flip_lr     r  c                 C   r  )NzCannot np.flipud on %s typec                 S   s.   t | }|jdk rtd|d d ddf S )NrA   zInput must be >= 1-d.rM  .r  r  r>   r>   r?   r     s   

znp_flip_ud.<locals>.implr  r  r>   r>   r?   
np_flip_ud  r  r  c                    sN   t |tjst|t|j tjtj d|} fdd}||fS )zY Creates a tuple of slices for np.flip indexing like
    `(slice(None, None, -1),) * sz` r%  c                    sZ   dd }t jg}tjg|R  }| t j}| }| |g}	| ||||	}
|
S )Nc                 S   s*   |}t | D ]}t||td d d}q|S )NrM  )r6   r.   r  )lengthempty_tupler   r]   r>   r>   r?   r     s   z6_build_flip_slice_tuple.<locals>.codegen.<locals>.impl)r   ry   r   r$   r   Zget_constant_undefr<  )rk   r9   r$   r   r   Zinner_argtypesZ	inner_sigZll_idx_typer  Z
inner_argsr   r}   Z
tuple_typer>   r?   r    s   

z(_build_flip_slice_tuple.<locals>.codegen)	r   r   r  r   r{  r   r   r  Zslice3_type)r  szrO   r  r>   r  r?   _build_flip_slice_tuple  s   

r  c                 C   s&   t | tjstd|  dd }|S )NzCannot np.flip on %s typec                 S   s   t | j}| | S r  )r  r_   )r  slr>   r>   r?   r     s   
znp_flip.<locals>.impl)r   r   r   r   r   r  r>   r>   r?   np_flip  s   r  c                 C   s   t | tjtjtjfrd	dd}|S t |tjrd	dd}|S t |tjr4t |jjtjr4d	dd}|S t |tj	rKt
dd |jD rMd	dd}|S d S d S )
Nr   c                 S      t jt | ||dS r  )r  array_splitr  r   indices_or_sectionsr   r>   r>   r?   r     s
   znp_array_split.<locals>.implc                 S   sP   t | j| |\}}tt|d g| |g|| d   }tj| ||dS )NrA   r  )divmodrU   r  Zcumsumr   r  )r   r!  r   r  r  r   r>   r>   r?   r     s   c              	   S   sp   t | j}tdd| j|}g }d}|D ]}t||t||}|| |  |}q|| t||t|d   |S Nznp.splitr   r   )r/   r_   r   r.   r  rY   r   r!  r   Z	slice_tupr   prevr  r|   r>   r>   r?   r     s   
c                 s   r  r  r   r   r   )r   rJ  r>   r>   r?   r    r  z!np_array_split.<locals>.<genexpr>c              	   S   st   t | j}tdd| j|}g }d}t|D ]}t||t||}|| |  |}q|| t||t|d   |S r#  )r/   r_   r   r   r.   r  rY   r$  r>   r>   r?   r     s   
r  )r   r   r  ListTyper  r   ZIterableTypeZiterator_typer   r  r  r   r!  r   r   r>   r>   r?   np_array_split  s,   





r)  c                 C   sL   t | tjtjtjfrddd}|S t |tjrddd}|S t| ||dS )Nr   c                 S   r  r  )r  splitr  r   r>   r>   r?   r     s   znp_split.<locals>.implc                 S   s4   t | j| |\}}|dkrtdtj| ||dS )Nr   z0array split does not result in an equal divisionr  )r"  rU   r   r  r  )r   r!  r   r  r  r>   r>   r?   r   "  s   r  r  )r   r   r  r'  r  r   r)  r(  r>   r>   r?   np_split  s   


r+  c                 C   N   t | tjsd}t|t |tjtjtjtjfs!d}t|dd }|S )N#The argument "ary" must be an array:The argument "indices_or_sections" must be int or 1d-arrayc                 S   "   | j dk r	tdtj| |ddS )Nr&  z3vsplit only works on arrays of 2 or more dimensionsr   r  r_   r   r  r*  r   r!  r>   r>   r?   r   =     
znumpy_vsplit.<locals>.implr   r   r   r   r   r   r  r  r   r!  r   r   r>   r>   r?   numpy_vsplit2     

r5  c                 C   r,  )Nr-  r.  c                 S   s<   | j dkr	td| j dkrtj| |ddS tj| |ddS )Nr   z3hsplit only works on arrays of 1 or more dimensionsrA   r  r0  r1  r>   r>   r?   r   Q  s
   

znumpy_hsplit.<locals>.implr3  r4  r>   r>   r?   numpy_hsplitF  s   

r7  c                 C   r,  )Nr-  r.  c                 S   r/  )Nrf  z3dsplit only works on arrays of 3 or more dimensionsr&  r  r0  r1  r>   r>   r?   r   g  r2  znumpy_dsplit.<locals>.implr3  r4  r>   r>   r?   numpy_dsplit\  r6  r8  c                 C   s   | |k S )z7
    Trivial comparison function between two keys.
    r>   r^  r>   r>   r?   
default_ltv  s   r9  Fc                 C   sr   | |j |f}zt| W S  ty8   | dkr"tj||dd}|j}n| dkr0tj||d}|j}|t|< | Y S w )z6
    Get a sort implementation of the given kind.
    r+   T)lt
is_argsortZis_np_arrayr,   )r:  r;  )	r`   _sortsKeyErrorr+   Zmake_jit_quicksortZrun_quicksortr,   Zmake_jit_mergesortZrun_mergesort)r8  lt_implr;  keyr  r  r>   r>   r?   get_sort_func}  s(   
r@  c                 C   s$   t | tjrtS t | tjrtS tS r  )r   r   r^  r   rV  r   r9  r  r>   r>   r?   lt_implementation  s
   rA  z
array.sortc                    s8   |j d }tdt|jd  fdd}| ||||S )Nr   r+   )r8  r>  c                    s    |  d S r  r>   r3  Z	sort_funcr>   r?   array_sort_impl  r  z#array_sort.<locals>.array_sort_impl)r   r@  rA  ri   r<  )rk   r9   rO   r   r  rC  r>   rB  r?   
array_sort  s   
rD  c                 C   r  )NzArgument "a" must be array-likec                 S   s   |   }|  |S r  )r  r  )r9  r   r>   r>   r?   np_sort_impl  s   z"impl_np_sort.<locals>.np_sort_implr  )r9  rE  r>   r>   r?   impl_np_sort  s   
rF  zarray.argsortc           	         s^   |j \}}t|jt|jdd  fdd}|j|j d d d}|d d }| ||||S )NT)r8  r>  r;  c                    s    | S r  r>   r3  rB  r>   r?   array_argsort_impl  rC  z)array_argsort.<locals>.array_argsort_implrA   r  )r   r@  r   rA  ri   replacer<  )	rk   r9   rO   r   r  r8  rG  ZinnersigZ	innerargsr>   rB  r?   array_argsort  s   
rI  c                 C   s   |j |j ks|jdksJ |S )Nr  )r  r  )rk   r9   r  r  ru   r>   r>   r?   array_to_array  s   rJ  c                 C   4   dd }t ||}| ||||g}t| ||j|S )Nc                 S   s
   |  dS r   )rS  r  r>   r>   r?   r     s   
zarray0d_to_scalar.<locals>.impl)r$   r<  r"   r   rk   r9   r  r  ru   r   rO   r   r>   r>   r?   array0d_to_scalar  s   
rM  c                 C   rK  )Nc                 S   s   t | d S rV  r
  r  r>   r>   r?   r     rT  z array_to_unichrseq.<locals>.impl)r$   r<  r    r   rL  r>   r>   r?   array_to_unichrseq  s   
rN  c                 C   r+  )zR
    An intrinsic returning a derived array with the given shape and strides.
    r   r9  rU   r   r>   r>   r?   reshape_unchecked  r0  rP  c                    s   dd   fdd}|S )Nc                 S   s   t | tjotdd | D S )Nc                 s   r  r  r&  r  r>   r>   r?   r    r  z>type_reshape_unchecked.<locals>.check_shape.<locals>.<genexpr>)r   r   r  r  rU   r>   r>   r?   r    s   z+type_reshape_unchecked.<locals>.check_shapec                    sJ   t | tjsd S  |r |sd S t|t|krd S | jt|ddS )Nr  r  )r   r   r   r   r  rO  r  r>   r?   typer   s   z%type_reshape_unchecked.<locals>.typerr>   )rk   rS  r>   rR  r?   type_reshape_unchecked  s   	rT  c                 C   s   |j d }|j}t|| ||d }t|| |}t||d }t||d }	t||j||	|j|jd |	 }
t
| |||
S )Nr   rA   r&  r6  )r   r   rg   r	   r   r   r   r   r   r   r    )rk   r9   rO   r   r   rx  r   r   rU   r   r   r>   r>   r?   impl_shape_unchecked  s   
rU  c                    s`   |d t jfv rtdd  ntdd  |d t jfv r tdtdd d	 fdd	}|S )
Nc                 S   r?  r  rQ  r  rU   r>   r>   r?   r1  %  r   zas_strided.<locals>.get_shapec                 S   r7  r  r>   rV  r>   r>   r?   r1  )     z,as_strided() strides argument cannot be Nonec                 S   r7  r  r>   )r  r   r>   r>   r?   get_strides4  rW  zas_strided.<locals>.get_stridesc                    s   t |  | || |} | S r  )rP  )r  rU   r   r1  rX  r>   r?   as_strided_impl8  s   z#as_strided.<locals>.as_strided_implr  )r   r  r&   r   r   )r  rU   r   rZ  r>   rY  r?   
as_strided"  s   


r[  c                    s  t |tjrtt| jd tt| jd tdd n/t |tjrIt |jtjrItt| jt	| tt| jt	| tdd nt
dt|rYtdd  n&t |tjrftdd  nt |tjrzt |jtjrztd	d  nt
d
d fdd	}|S )NrA   c                 S   s   | fS r  r>   window_shaper>   r>   r?   get_window_shapeI  r   z-sliding_window_view.<locals>.get_window_shapec                 S   r6  r  r>   r\  r>   r>   r?   r^  R  rW  z4window_shape must be an integer or tuple of integersc                 S   s   t t|S r  )r   r6   r]  r   r_   r>   r>   r?   get_axis]  r  z%sliding_window_view.<locals>.get_axisc                 S   s   t dd||gS )Nsliding_window_viewr   r   r_  r>   r>   r?   r`  b  s   c                    s    fdd|D S )Nc                    s   g | ]	}t d d |qS )ra  r   rb  r8  r  r>   r?   r   l  r  z9sliding_window_view.<locals>.get_axis.<locals>.<listcomp>r>   r_  r>   r  r?   r`  j  s   
z2axis must be None, an integer or tuple of integersc           
         s   |} ||| j }t|t|krtd}}t| j D ]}t||| j| }t||| j| }q | j }t||D ]7\}}|dk rItd|| |k rStd|| | d }t|||}t|||}t||| j| }|d7 }q=t| ||}	|	S )Nz2Must provide matching length window_shape and axisr   z-`window_shape` cannot contain negative valuesz4window_shape cannot be larger than input array shaperA   )	r_   r   r   r6   r.   rU   r   r   rP  )
r  r]  r   Z	out_shapeZout_stridesr]   r  r8  Ztrimmedr  r`  r^  Zshape_bufferZstride_bufferr>   r?   sliding_window_view_implt  s8   
z5sliding_window_view.<locals>.sliding_window_view_implr  )r   r   r   r   r6   r_   r&   r  ri   r   r   r   r   )r  r]  r   rd  r>   rc  r?   ra  ?  s>   'ra  c                 C   r  )Nc                 S   s>   | j dkrtdk rdS td| j dkrt| dS td)Nr   )r&  r&  FziThe truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty.rA   z[The truth value of an array with more than one element is ambiguous. Use a.any() or a.all())r}   r   r   r  rS  r3  r>   r>   r?   r     s   

zol_bool.<locals>.implr  r4  r>   r>   r?   ol_bool  s   re  c                    sn   t |ttjfstdt |ttjfstdt | tjs%td| jtt	  fdd}|S )Nz.The second argument "axis1" must be an integerz-The third argument "axis2" must be an integerz'The first argument "a" must be an arrayc                    s`   t dd|}t dd|}|dk r|7 }|dk r|7 }t ||}t|||}t| |S )Nznp.swapaxesaxis1axis2r   )r   r.   r  rF  )r9  rf  rg  Z
axes_tupleZ	axes_listr_   r>   r?   r     s   znumpy_swapaxes.<locals>.impl)
r   r   r   r   r   r   r   r_   r   r6   )r9  rf  rg  r   r>   rh  r?   numpy_swapaxes  s   


ri  c                 C   s  t dd| j|}t| j}d||< tt||jD ]$\}\}}	|dkr&|	}
n|	dkr-|}
n
||	kr5td|}
t|||
}qt||| j| }t	| |} t	||}|}t
|dkrmtt
|D ]}t||| j| }qa|}t
|dkrtt
|D ]}t||| j|d |  }q{|j| }t||f | | j}td d d f}t|D ]1}t|D ])}| || |  }||| |  }||| |  }t|D ]
}|||  ||< qqq|S )Nznp.take_along_axisr   rA   z*`arr` and `indices` dimensions don't matchr   )r   r_   r   rU   r  r   r   r.   r  r  r   r6   r  ri   r  r  )r  r   r   ZNi_origZNk_origindices_broadcast_shapeZ	arr_shaper]   Zd1Zd2new_valZarr_broadcast_shapeNiNkJr   Znp_s_iikkZa_1dZ
indices_1dZout_1drI  r>   r>   r?   _take_along_axis_impl  sT   

rq  c                    s  t | tjstdt |tjstdt |jtjs"tdt|r)d}n| j}||jkr6tdt	t
|jt|rIfdd}|S t|d t |tjsYtd	|j}|d
k re| j| }|d
k sn|| jkrstdt	t
| t	t
|d | j fdd}|S )Nz)The first argument "arr" must be an arrayz.The second argument "indices" must be an arrayz'The indices array must contain integersrA   z;`indices` and `arr` must have the same number of dimensionsc                    s   t |  |ddd S )Nr   r>   )rq  r  r  r   r   )rj  r>   r?   take_along_axis_impl#  s   z1arr_take_along_axis.<locals>.take_along_axis_implr   zaxis must be a literal valuer   zaxis is out of boundsc                    s   t | || S r  )rq  rr  rl  rm  rj  r>   r?   rs  4  s   )r   r   r   r   r   ri   r   r   r_   r   r6   r   r  rj  r   )r  r   r   Zarr_ndimrs  r>   rt  r?   arr_take_along_axis  s>   






ru  T        c                 C   s   t | tjr2t | tjrddd}|S t | tjr ddd}|S t | tjr-ddd}|S tdt| ret | j	tjrDddd}|S t | j	tjrRdd	d}|S t | j	tjr`dd
d}|S tdtd)NTrv  c                 S   r6  r  r>   r  r  nanr>   r>   r?   r   ?  rR  znan_to_num_impl.<locals>.implc                 S   sF   t | r|S t | rt t| jS t | r!t t| jS | S r  )r  isnanisneginffinfor7   r  isposinfr  rw  r>   r>   r?   r   C  s   


c                 S   s*   t j| j|d}t j| j|d}t||S )N)rx  )r  
nan_to_numrY  r[  complex)r  r  rx  r  rb  r>   r>   r?   r   L  s   
z4Only Integer, Float, and Complex values are acceptedc                 S   r6  r  r>   rw  r>   r>   r?   r   X  rR  c           	      S   s   t | jj}t | jj}t | }|rt |n|}|j}t|j	D ]%}t 
|| r2|||< q$t || r>|||< q$t || rI|||< q$|S r  )r  r{  ri   r  r  r  r  re  r6   r}   ry  rz  r|  )	r  r  rx  Zmin_infZmax_infx_outputZoutput_flatr]   r>   r>   r?   r   [  s   


c                 S   sD   t | }|rt |n|}t j|jd|d t j|jd|d |S )NF)r  rx  )r  r  r  r}  rY  r[  )r  r  rx  r  r  r>   r>   r?   r   l  s
   
z4The first argument must be a scalar or an array-likeTrv  )
r   r   r  r   r^  rV  r   r   r   ri   )r  r  rx  r   r>   r>   r?   nan_to_num_impl:  s6   
;
7
.
"


r  r  rR  r  r  r  )Fr  r  (  r5  r  rc  r  rM  Zllvmliter   Zllvmlite.irr   numpyr  Znumbar   r   Z
numba.corer   r   r   r	   r
   r   Znumba.np.numpy_supportr   r   r   r   r   r   r   r   r   r   r   r   r   Znumba.core.imputilsr   r   r   r   r   r   r   r    r!   r"   r#   Znumba.core.typingr$   Znumba.core.typesr%   Znumba.core.extendingr&   r'   r(   r)   r*   Z
numba.miscr+   r,   Znumba.cpythonr-   Znumba.cpython.unsafe.tupler.   r/   r0   Znumba.core.typing.npydeclr1   r  r2   r  r3   r4   r5   r@   rC   rg   rm   rs   rv   r   r   r   r   r   r   r   r   r   r   ZArrayIteratorZBORROWEDr   r  r   r  r  r   r   r  r  r  r  Anyr  r   r  r   r$  r(  r  r*  r7  rP  rY  r]  ri  rs  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Zbroadcast_shapesr  r  r  r   r  r  r  r)  r,  r.  r?  ZVarArgrB  rF  rK  r*  r]  rS  Z	geomspacerc  Zrot90rk  rs  rw  r{  r|  r  r  resizer  rY   r  r  r  r  r  r  r  r  r  r  r  rU   r  r}   r  uniquer  r  r  r  r  r  r  r  r<  r  r  Z
MemoryViewr  r  r  r  r  r	  r  r  r  r  r  r  r  r  r  r  r  r!  r  r"  r#  r)  r,  r'  r5  r7  ZDTypeZNumberClassr9  r@  rA  r=  rH  rI  rL  r  rM  rS  rT  rW  r[  Bytesr]  is_ra  rc  ri  rn  rx  ry  r  r  rg  r  r  r  r  r  r  rk  r  r  r  r  r  r  r  r  rz  r  ZNumpyNdIterTyper  eqr  r  r  r  r  r  r  r*  r  r  r  r
  r  r  r  r  r  r  r  r  r  r  r   r&  r'  r,  r  r-  r.  r/  r0  r1  r5  r9  eyer=  ZdiagrC  r   rG  ZdiagflatrK  rR  rS  r]  ra  rD  ri  rO  rm  ro  rp  rq  r  rt  ry  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  Z
atleast_1dr  Z
atleast_2dr  Z
atleast_3dr  r  r  r  r  r  r  r  r  r  Zcolumn_stackr  r  r  stackr  r  r  r  r  r  Zvstackr  Z	row_stackr  Zdstackr  r  r  rh  r  ri  r  r  flipr  r  r)  r*  r+  Zvsplitr5  Zhsplitr7  Zdsplitr8  r<  r9  r@  rA  rD  r  rF  ZargsortrI  rJ  ZUnicodeCharSeqr^  rV  ru  ZNPTimedeltaZ
NPDatetimerM  rN  rP  Ztype_callablerT  rU  libZstride_tricksr[  ra  r  re  rg  ri  rq  Ztake_along_axisru  r}  r  r>   r>   r>   r?   <module>   s    04<	E



D


(





22=QE +
*=%



*

(
9



 


6


L$
@



.








y~
	

	
,




+

$





























7	7'	"  JA X




	O	0















&

#Z

C*%
A


+$4
))




=2Y
	
%
	



)	




>


	

^

;
+