o
    8ήcZ                 	   @   s  d 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 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*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z: ddl,m;Z; ddl<m=Z>m?Z@ dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGd d! ZHd"d# ZI	dd$d%ZJd&d' ZKed(ejLd)d* ZMd+d, ZNed-ejOe%e)jPd.d/ ZQ	dd0d1ZRd2d3 ZSd4d5 ZTeejUejLejVeejUejLejWd6d7 ZXeejUejLejYd8d9 ZZeej[ejLej\ej\d:d; Z]ee^ejLd<d= Z_ed>ej`d?d@ ZaedAej`ej\dBdC ZbG dDdE dEecZdG dFdG dGedZeG dHdI dIedZfG dJdK dKedZgG dLdM dMedZhG dNdO dOedZiG dPdQ dQecZjdRdS ZkeejUejLej`dTdU ZldVdW ZmdXdY ZndZd[ Zod\d] Zpd^d_ Zqd`da Zrdbdc Zsddde Zte0dfdg Zue-dhdi Zve.e	jwdjdk Zxe-dldm Zydndo Zzedpkre.e	j{ez e.e	j|dqdr Z}dsdt Z~dudv Zedwej`dxdy Zdzd{ Zedwej`ejYd|d} Zedwej`eej\d~d Ze.e	jdddZe ej`ddd Ze.e	jdddZe.e	jdddZdd Zdd Zedej`ejYdd Zedej`eej\dd Ze.e	jdd Ze.e	jdddZedej`dd Zee	jej`dd Zedej`dd Ze-dd Ze-dd Ze.e	jdddZe/ej`ddddZdd Ze.e	jdd Ze.e	jdd Ze.e	jdd Ze-dd Ze/ej`ddd Ze0dd Zdd Ze.edddd Zedej`ejdd Ze ej`dddÄ Ze ej`dăe ejdăddƄ Ze ej`dǃe ejdǃddɄ Ze ej`dʃe ejdʃdd̄ Ze ej`d̓ddτ Ze ej`dЃe ejdЃdd҄ Ze ejdӃddՄ Ze ejdփdd؄ Ze ejdكddۄ Ze ejd܃ddބ Ze ejd߃dd Ze ej`ddd Ze ejddd Ze#ejeje#ejejdd Zdd Ze ej`ddd Ze ejdփe ejdكdd Ze ejd܃dd Ze ej`ddd Ze ej`ddd Zdd Ze/ej`de/ej`ddd Zdd  Ze ejǐdeƃ e ejǐdeƃ e!ej`dd Zedej`ejɃdd Ze!ej˃dd	 Ze"ej˃d
d ZedejejɃdd Zedejejσdd Zedejejej\dd Zedejejej\dd Ze$ej`dd Ze$ej˃dd Ze$ejՃdd Zeejej`ej`dd Zؐdd Zِdd  Z		dd!d"Z	dd#d$Zܐd%d& Zݐd'd( Zސd)d* Ze ej`d+d,d- Zed-eje%e)jPd.d/ ZeejUejejVd0d1 Zeej[ejejVej\d2d3 Zee^ejd4d5 Zee	jej`d6d7 Zed-eje%e)jPd8d9 ZeeeejVee	jeejVd:d; ZeeejYee	jejYd<d= Zed-eje%e)jPd>d? Zee	jej\d@dA Zed-eje%e)jPdBdC ZdDdE Ze;ej`dFdGdH ZdIdJ Ze0dKdL ZdMdN ZdOdP ZdQdR ZdSdT Ze0dUdV Ze.e	jefdWdXZe0dYdZ Ze.e	j dd[d\Ze0d]d^ Ze/ej`d_d`da Ze.e	jefdbdcZe.e	jddddeZe.e	jddfdgZ	e:e	j
ej\ej\dhdi Ze:e	j
ej\ej\eje:e	j
ej\ej\ejɃdjdk Ze:e	jej\ej\dldm Ze:e	jej\ej\eje:e	jej\ej\ejɃdndo Ze.e	jddpdqZe:e	jejVdrds Ze:e	jejVeje:e	jejVejɃdtdu Zdvdw Ze.edxdy Ze.e	jddefdzd{Ze:e	jej`d|d} Ze:e	jej`ejVd~d Zedej`ejVe:e	jej`ejVdd Zedej`ej`e:e	jej`ej`dd Zedej`eje:e	jej`ejedej`ejYe:e	jej`ejYdd Z dd Z!e.e	j"dddZ#e:e	j$ej%ej%dd Z&e:e	j$ej%ej%ejVdd Z'dd Z(edej`dd Z)e:e	j*ej`dd Z+dd Z,e:e	j-ej`dd Z.e:e	j/ej`dd Z0e.e	j/dd Z1e.e	j-dd Z2edej`ejedej`ejɃdd Z3e:e	j4ejLe:e	j4ejLeje:e	j4ejLejɃdd Z5e:eej\ej\e:eej\ej\eje:eej\ej\e:eej\ej\ejdd Z6dd Z7dd Z8dd Z9dd Z:dd Z;e:e	j<ej\e:e	j<ej\eje:e	j<ej\ejɃdd Z=dd Z>dd Z?dd Z@dd ZAe:e	jAej`ejVdd ZBdd ZCdd ZDe:e	jEeej`dd ZFe:e	jGeej`dÐdĄ ZHe:e	jIeej`dŐdƄ ZJdǐdȄ ZKdɐdʄ ZLdːd̄ ZMe:e	jNejYd͐d΄ ZOe:e	jNejYejVdϐdЄ ZPe:e	jQejYdѐd҄ ZRdӐdԄ ZSe:e	jTejYdՐdք ZUe:e	jTejYejVdאd؄ ZVe:e	jWejYdِdڄ ZXe:e	jYejYdېd܄ ZZe:e	j[ejYdݐdބ Z\e/ej`dߡdd Z]e/ej`ddd Z^e.e	j_dd Z`e.e	jadd Zbe0dd Zce.e	jddd Zee.e	jfdddZge.e	jhdddZii Zjdd ZkdddZledej`dd Zme:e	jnej`dd Zoedej`ejɃee	jpej`ejɃdd Zqe#ej`ej`dd Zre#ej`ejse#ej`ejte#ej`ejVe#ej`ejue#ej`ejve#ej`ejwe#ej`ejxd d Zye#ej`ejsdd Zzdd Z{e|e{dd Z}ee{ej`ejYejYdd	 Z~e.e	jjjdd
dZe.edd Ze.e	jdd Ze-dd Ze.e	jdd ZdS (  z[
Implementation of operations on Array objects and objects supporting
the buffer protocol.
    N)ir)Constant)pndindexliteral_unroll)typesutilstypingerrorscgutils	extending)as_dtypecarrayfarrayis_contiguous
is_fortrancheck_is_integer)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)register_jitableoverloadoverload_method	intrinsic)	quicksort	mergesort)slicing)tuple_setitembuild_full_slice_tuple)glue_lowering)overload_classmethod)parse_dtypeparse_shapec                 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moduleadd_metadataset_metadata)builderloadlower_boundupper_boundrange_operandsmd r9   8/tmp/pip-target-vg8gfxp4/lib/python/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)r/   widthr;   )r3   r4   r6   r9   r9   r:   mark_positive2   s   r>   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 )N	__array__T)zfill)r    _contextget_functionNotImplementedErrorsuper
_make_refsdata_model_manager_get_be_typer
   alloca_once_builder)selfrefsig
array_impl	datamodelbe_type	outer_ref)ArrayStruct	__class__
array_typereal_array_typer9   r:   rE   H   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)
rI   __getattr___get_ptr_by_namer.   r
   gep_inboundsr4   appendr>   
pack_array)rJ   r3   ptrdimsidimptrr4   )basendimr9   r:   rU   \   s   


z%make_array.<locals>.ArrayStruct.shape)__name__
__module____qualname__rE   propertyrU   __classcell__r9   rQ   rS   r_   r`   rT   )rR   r:   rQ   F   s    rQ   )as_arrayr
   create_struct_proxyr`   )rS   r9   rf   r:   
make_array:   s
   
-ri   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   lltyr9   r9   r:   get_itemsizev   s   
ro   c                 C   s"   |j rdnd}| j||j||dS )z3
    Load the item at the given array pointer.
    Nr<   align)alignedunpack_valuerk   )rm   r3   arraytyr[   rq   r9   r9   r:   	load_item~   s   ru   c                 C   s$   |j rdnd}| j||j|||dS )z4
    Store the item at the given array pointer.
    Nr<   rp   )rr   
pack_valuerk   )rm   r3   rt   valr[   rq   r9   r9   r:   
store_item   s   rx   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'   	fix_indexuintp)rm   r3   idxtyidxsizeindr9   r9   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`   rk   Integerri   ru   data)rm   r3   r~   r   idxaryidxvalr9   r9   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 r9   )r   ).0r~   r   r3   rm   r9   r:   
<listcomp>   s
    z%normalize_indices.<locals>.<listcomp>)lenzip)rm   r3   index_typesindicesr9   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.
    r<   CzThe datamodel for type z is missing fields  .Nmeminfo)rU   stridesr   itemsizer   parentnswflagsnitemszmissing {0}) rA   rI   
_datamodelr   r   float64rF   set_fields_fe_typer   
ValueErrorr   get_value_typeget_typer{   r   tuplelistr
   rZ   intdictget_constantunpack_tupler/   countmulkeysformatitemssetattr)arrayr   rU   r   r   r   r   rm   r3   rN   standard_arraystandard_array_type_datamodelrequired_fieldsdatamodel_fieldsmissingmsgintp_tattrsr   unpacked_shapeaxlen
got_fieldskvr9   r9   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.
    r<   r   r   N)rA   rI   r   r   r{   r
   r   rU   r`   r   r   ro   r   )arytyr   rm   r3   r   r   r   r9   r9   r:   update_array_info   s   
r   getiterc                 C   st   |j \}|\}| ||j}| tjd}t||}||_||_	| j
r,| j||| | }	t| ||j|	}
|
S Nr   )argsmake_helperreturn_typer   r   r{   r
   alloca_once_valueindexr   
enable_nrtnrtincref	_getvaluer   )rm   r3   rL   r   rt   r   iterobjzeroindexptrresoutr9   r9   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   r<   N)r
   r   rU   r`   r   r   pointer_addr   r   r   Buffer	make_viewr   ru   )rm   r3   r   r   aryr   shapesr   offsetdataptrview_shapesview_stridesretaryr9   r9   r:   _getitem_array_single_int%  s   r   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valuer<   r   <)r   rS   r   ri   r   r
   r   rU   r4   r   icmp_signed	set_validif_thenr   
yield_typeyield_increment_indexstore)rm   r3   rL   r   resultitertyiterrt   r   r   r   r   is_validr   nindexr9   r9   r:   iternext_array:  s"   

"r   c              	   C   s  |  tjd}t||j|j}t||j|j}	g }
g }g }d}t||D ]\}}|tj	u rW|jt
| d }t|D ]}|
| |||  ||	|  |d7 }q<q&t|tjr| j|||d}t| ||| t||||  |
|j t||}t|||	| }|| || n*t|tjrt| ||||| }|rt| |||| | |
| ntd|f |d7 }q&||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   r<   r   unexpected index type: %sF
wraparoundboundscheck)r   r   r{   r
   r   rU   r`   r   r   ellipsisr   r.   rY   r   	SliceTyper   r'   guard_invalid_slice	fix_slicestartget_slice_length
fix_strider   r   do_boundscheckrC   get_item_pointer)rm   r3   r   r   r   r   r   r   r   r   output_indicesoutput_shapesoutput_stridesaxindexvalr~   	n_missingr]   sliceshstr   r   r9   r9   r:   basic_indexingV  sZ   








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   )ri   r   r   r   r   )	rm   r3   r   r   r   r   r   r   r   r9   r9   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   ru   )rm   r3   r   r   r   r   r   r   r   r   r   r9   r9   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.
    r<   )r   r`   ri   r  r   r   	rm   r3   rL   r   r   r~   r   r   r   r9   r9   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   tyr9   r9   r:   	<genexpr>      z&getitem_array_tuple.<locals>.<genexpr>)r   ri   r   r
   r   r   r   anyfancy_getitemr  r   r   )rm   r3   rL   r   r   tuptyr   tupr   r   r   r9   r9   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   ri   r   r  r  rC   boolfancy_setslicerz   rk   rx   )rm   r3   rL   r   r   r~   valtyr   r   rw   r   r   r   r   r   use_fancy_indexingr9   r9   r:   setitem_array  s4   

r  c           	      C   sD   |j \}|\}t|}|| ||}|j}||d}t| ||j|S r   )r   ri   rU   extract_valuer   r   )	rm   r3   rL   r   r   r   arysttyshapearyr   r9   r9   r:   	array_len  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!=r<   Flikelyz>item(): can only convert an array of size 1 to a Python scalar)r   ri   r   r   r   r/   	call_convreturn_user_excr   ru   r   )rm   r3   rL   r   r   r   r   r   r9   r9   r:   
array_item  s   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$  r<   Fr%  z/itemset(): can only write to an array of size 1)r   rk   ri   r   r   r   r/   r'  r(  r   rx   r   get_dummy_value)
rm   r3   rL   r   r   r  r   rw   r   r   r9   r9   r:   array_itemset&  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...
        rC   rJ   r9   r9   r:   prepareA     zIndexer.preparec                 C   r.  )z=
        Return this dimension's size as an integer.
        r/  r0  r9   r9   r:   get_sizeH     zIndexer.get_sizec                 C   r.  )z;
        Return this dimension's shape as a tuple.
        r/  r0  r9   r9   r:   	get_shapeN  r4  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/  r0  r9   r9   r:   get_index_boundsT  r2  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/  r0  r9   r9   r:   	loop_head[  s   	zIndexer.loop_headc                 C   r.  )z)
        Finish indexation loop.
        r/  r0  r9   r9   r:   	loop_tailf  r4  zIndexer.loop_tailN)
ra   rb   rc   __doc__r1  r3  r5  r6  r7  r8  r9   r9   r9   r:   r-  ;  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  )	rm   r3   r   r   dimr   r   r{   ll_intp)rJ   rm   r3   r   r   r<  r9   r9   r:   __init__r  s   zEntireIndexer.__init__c                 C   sB   | j }|| jj| j| _t|| j| _	|
 | _|
 | _d S r  )r3   r   r   rU   r<  r   r
   rH   r=  r   append_basic_blockbb_startbb_endrJ   r3   r9   r9   r:   r1  z  s
   
zEntireIndexer.preparec                 C      | j S r  r   r0  r9   r9   r:   r3       zEntireIndexer.get_sizec                 C      | j fS r  rD  r0  r9   r9   r:   r5       zEntireIndexer.get_shapec                 C      |  d| jfS r   r=  r   r0  r9   r9   r:   r6       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%  )r3   r   r   r=  r   branchr@  position_at_endr4   r   r   r   rA  )rJ   r3   	cur_indexr9   r9   r:   r7    s   
zEntireIndexer.loop_headc                 C   D   | j }t||| j}||| j || j || j	 d S r  )
r3   r
   r   r4   r   r   rM  r@  rN  rA  rJ   r3   
next_indexr9   r9   r:   r8    s
   zEntireIndexer.loop_tailNra   rb   rc   r9  r>  r1  r3  r5  r6  r7  r8  r9   r9   r9   r:   r;  m  s    r;  c                   @   r:  )IntegerIndexerz0
    Compute indices from a single integer.
    c                 C   s&   || _ || _|| _| j tj| _d S r  )rm   r3   r   r   r   r{   r=  )rJ   rm   r3   r   r9   r9   r:   r>    s   zIntegerIndexer.__init__c                 C      d S r  r9   r0  r9   r9   r:   r1       zIntegerIndexer.preparec                 C   s   t | jdS Nr<   )r   r=  r0  r9   r9   r:   r3       zIntegerIndexer.get_sizec                 C      dS Nr9   r9   r0  r9   r9   r:   r5    rV  zIntegerIndexer.get_shapec                 C   s   | j | j| j |  fS r  )r   r3   addr3  r0  r9   r9   r:   r6    s   zIntegerIndexer.get_index_boundsc                 C   s
   | j d fS r  )r   r0  r9   r9   r:   r7       
zIntegerIndexer.loop_headc                 C   rU  r  r9   r0  r9   r9   r:   r8    rV  zIntegerIndexer.loop_tailNrS  r9   r9   r9   r:   rT    s    rT  c                   @   r:  )IntegerArrayIndexerz;
    Compute indices from an array of integer indices.
    c                 C   s@   || _ || _|| _|| _|| _|jdksJ | j tj| _	d S rW  )
rm   r3   r~   r   r   r`   r   r   r{   r=  )rJ   rm   r3   r~   r   r   r9   r9   r:   r>    s   zIntegerArrayIndexer.__init__c                 C   sD   | j }t|| jjd | _t|| j| _|	 | _
|	 | _d S r   )r3   r
   r   r   rU   idx_sizerH   r=  	idx_indexr?  r@  rA  rB  r9   r9   r:   r1    s
   
zIntegerArrayIndexer.preparec                 C   rC  r  r^  r0  r9   r9   r:   r3    rE  zIntegerArrayIndexer.get_sizec                 C   rF  r  r`  r0  r9   r9   r:   r5    rG  zIntegerArrayIndexer.get_shapec                 C   rH  r   rI  r0  r9   r9   r:   r6    rJ  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 rK  )r3   r   r   r=  r_  rM  r@  rN  r4   r   r   r^  rA  r   rm   r~   rk   r   r   r   )rJ   r3   rO  r   r9   r9   r:   r7    s&   zIntegerArrayIndexer.loop_headc                 C   rP  r  )
r3   r
   r   r4   r_  r   rM  r@  rN  rA  rQ  r9   r9   r:   r8    s   
zIntegerArrayIndexer.loop_tailNrS  r9   r9   r9   r:   r]    s    	r]  c                   @   r:  )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 Nr<   r   )rm   r3   r~   r   r`   r   r   r{   r=  r   r   )rJ   rm   r3   r~   r   r9   r9   r:   r>     s   zBooleanArrayIndexer.__init__c                 C   s^   | j }t|| jjd | _t|| j| _t|| j| _	|
 | _|
 | _|
 | _d S r   )r3   r
   r   r   rU   r   rH   r=  r_  r   r?  r@  bb_tailrA  rB  r9   r9   r:   r1  	  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  )r3   r
   r   r   	for_ranger   r4   r   rm   r~   rk   r   r   r[  zextr/   r   )rJ   r3   r   loopcpredr9   r9   r:   r3    s   

	zBooleanArrayIndexer.get_sizec                 C   
   |   fS r  r3  r0  r9   r9   r:   r5  !  r\  zBooleanArrayIndexer.get_shapec                 C   rH  r   rI  r0  r9   r9   r:   r6  $  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 )NrL  Fr%  )r3   r   r   r_  r   rM  r@  rN  r4   r   r   r   rA  r   rm   r~   rk   r   not_rc  r
   r   )rJ   r3   rO  	cur_countrh  
next_countr9   r9   r:   r7  )  s,   zBooleanArrayIndexer.loop_headc                 C   s\   | j }|| j || j t||| j}||| j || j	 || j
 d S r  )r3   rM  rc  rN  r
   r   r4   r_  r   r@  rA  rQ  r9   r9   r:   r8  A  s   
zBooleanArrayIndexer.loop_tailNrS  r9   r9   r9   r:   ra    s    		ra  c                   @   r:  )SliceIndexerz(
    Compute indices along a slice.
    c                 C   sL   || _ || _|| _|| _|| _|| _|| _| j tj	| _
t| j
d| _d S r   )rm   r3   r   r   r<  r~   r  r   r   r{   r=  r   r   )rJ   rm   r3   r   r   r<  r~   r  r9   r9   r:   r>  Q  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  )r3   r   r   rU   r<  dim_sizer'   r   rm   r~   r  r   r
   
is_neg_intstepis_step_negativerH   r=  r   r   r?  r@  rA  rB  r9   r9   r:   r1  \  s   
zSliceIndexer.preparec                 C   s   t | j| jS r  )r'   r   r3   r  r0  r9   r9   r:   r3  j     zSliceIndexer.get_sizec                 C   ri  r  rj  r0  r9   r9   r:   r5  m  r\  zSliceIndexer.get_shapec                 C   s   t | j| j\}}||fS r  )r'   get_slice_boundsr3   r  )rJ   lowerupperr9   r9   r:   r6  p  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<=rL  Fr%  )r3   r   r  r   r   r   r   rM  r@  rN  r4   selectrr  r   stopr   rA  )rJ   r3   rO  rl  is_finishedr9   r9   r:   r7  t  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   )r3   r[  r4   r   r  rq  r   r
   r   r   rM  r@  rN  rA  )rJ   r3   rR  rm  r9   r9   r:   r8    s   zSliceIndexer.loop_tailNrS  r9   r9   r9   r:   rn  L  s    rn  c                   @   r,  )FancyIndexerz4
    Perform fancy indexing on the given array.
    c              	   C   s(  || _ || _|| _t||j|j| _t||j|j| _| j 	t
j| _g }d}t||D ]\}	}
|
t
ju rY|jt| d }t|D ]}t|||||}|| |d7 }qDq.t|
t
jrv|||
|	}t||||||
|}|| n\t|
t
jrt|||
|	| j| }t|||}|| n?t|
t
jrt|
|||	}t|
jt
jrt|||
|| j| }nt|
jt
jrt|||
|}nJ || nt d|
f |d7 }q.||jksJ ||jf||jk rt|||||}|| |d7 }||jk st||jksJ t||jf|| _!d S )Nr   r<   r   )"rm   r3   r   r
   r   rU   r`   r   r   r   r   r{   r=  r   r   r   r.   r;  rY   r   r   r   rn  r   r   rT  r   ri   rk   r]  Booleanra  AssertionErrorindexers)rJ   rm   r3   r   r   r   r   r}  r  r  r~   r  r]   indexerr  r   r   r9   r9   r:   r>    sf   







"
zFancyIndexer.__init__c                 C   s0   | j D ]}|  qtdd | j D d| _d S )Nc                 S      g | ]}|  qS r9   )r5  r   r]   r9   r9   r:   r         z(FancyIndexer.prepare.<locals>.<listcomp>r9   )r}  r1  sumindexers_shaperJ   r]   r9   r9   r:   r1    s   

zFancyIndexer.preparec                 C   rC  )z?
        Get the resulting data shape as Python tuple.
        )r  r0  r9   r9   r:   r5    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   r<   ==r   )r   r   r`   r3   r
   	false_bitr=  r   r}  r  or_icmp_unsignedr6  r   subr   r[  rw  )rJ   r   r   r3   is_emptyr   oneru  rv  r~  rU   stridelower_indexupper_indexlower_offsetupper_offsetis_downwardsr9   r9   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  )r7  r  r9   r9   r:   r    s    z+FancyIndexer.begin_loops.<locals>.<genexpr>)r   r}  )rJ   r   countsr9   r9   r:   begin_loops  s   zFancyIndexer.begin_loopsc                 C   s   t | jD ]}|  qd S r  )reversedr}  r8  r  r9   r9   r:   	end_loops  s   
zFancyIndexer.end_loopsN)
ra   rb   rc   r9  r>  r1  r5  r  r  r  r9   r9   r9   r:   rz    s    :&rz  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   rz  r1  r   r5  _empty_nd_implr   r   r   r{   r  get_item_pointer2layoutr  ru   r4   geprx   r   r   r  r   r   )rm   r3   rL   r   r   r   r   r   r   r   r   r~  out_ty
out_shapesr   out_dataout_idx_r[   rw   curnext_idxr9   r9   r:   r    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   ri   r`   r   r  r   r   r  r  r9   r9   r:   fancy_getitem_array6  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   r<   CFrL  r  )r   r/   r  r   r   r.   r`   r  r   rw  r[  )rm   r3   arrtyarrr   r   r   r   r  ru  rv  r]   max_axis_offset
is_upwardsr  r9   r9   r:   offset_bounds_from_stridesJ  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.
    )ptrtointr/   r[  )rm   r3   ru  rv  r   data_ptr_as_intr   endr9   r9   r:   compute_memory_extentst  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  )	rm   r3   r  r  r   r   r   ru  rv  r9   r9   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  )rm   r3   a_starta_endb_startb_endmay_overlapr9   r9   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ks	J t } jddT\}}|  tj  | dd| W d    n1 s:w   Y  |  tj 	
j| dd| W d    n1 s^w   Y  W d    n1 smw   Y  t	 
 |S )NFr%  r   )
r   r`   r
   rH   if_elser   r  r4   r  ru   )source_indicessrc_ptrif_copy	otherwise)r3   rm   	copy_datacopy_layoutcopy_shapescopy_stridesptrtysrc_data
src_shapessrc_stridessrctyuse_copyr9   r:   src_getitem  s6   
z&maybe_copy_source.<locals>.src_getitemc                     sX    j dd  }  | } j |  W d    d S 1 s%w   Y  d S )NFr%  )r   r4   bitcastr   freer   )r3   rm   r  r  	voidptrtyr9   r:   src_cleanup  s
   
"z&maybe_copy_source.<locals>.src_cleanup)r/   r
   r   r   r   r   r   r   allocater  r   r   r   r{   	loop_nestr  r  r4   )rm   r3   r  r  srcr  r  r  	allocsizer   r   r   r  dest_ptrr  r  r9   )r3   rm   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   r<   c                       g | ]	}  d |qS r  )r  r   r  r3   r  r9   r:   r     s    z(_bc_adjust_dimension.<locals>.<listcomp>NFr%  z,cannot broadcast source array for assignment)r   r   r}   r   	functoolsreducer  r
   true_bitr   rk  r'  r(  r   )
rm   r3   r   r   target_shaper   nd_diff
dim_is_oneacceptedr   r9   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   r<   c                    s   g | ]\}}  d ||qS )r$  r   )r   taroldr3   r9   r:   r         z,_bc_adjust_shape_strides.<locals>.<listcomp>c                    r  r  r  )r   r  r  r9   r:   r         c                    s   g | ]
\}}  ||qS r9   )r  )r   xyr  r9   r:   r   	      c                    s    g | ]\}}}  |||qS r9   rw  )r   pr  r  r  r9   r:   r   
  s    c                    s   g | ]\}}  ||qS r9   r  )r   r  r  )r3   r   r9   r:   r     r  )r   r   r}   r   )
rm   r3   r   r   r  	bc_shapes
bc_stridesmismatch
src_is_onepredsr9   )r3   r  r   r:   _bc_adjust_shape_strides  s    


r  c           
      C   s   t ||j}t ||j}t| ||||\}}t| ||||\}}|jt|dd}t|| |}t	t 
||t 
||d}	t |||	 ||fS )zX
    Broadcast the given array to the target_shape.
    Returns (array_type, array)
    Ar`   r  )rU   r   )r
   r   rU   r   r  r  copyr   ri   r   rZ   copy_struct)
rm   r3   arrtyper  r  r   r   new_arrtypenew_arrreplr9   r9   r:   _broadcast_to_shape  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   ri   r
   r   r  r   r   r   r   r   r   r   r   )
rm   r3   rL   r   r  shape_r  r  destr   r9   r9   r:   codegen,  s   
z$_numpy_broadcast_to.<locals>.codegen)r  r   )	typingctxr   rU   retrL   r  r9   r9   r:   _numpy_broadcast_to'  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-negativer<   z=operands could not be broadcast together with remapped shapes)rU   r   r   )
r   
dest_shape	src_shapesrc_ndim	dest_ndimr   	src_index
dest_indexsrc_dimdest_dimr9   r9   r:   _can_broadcast>  s&   
r  c                 C   sl   t | s	tdt|tjr!t|jtjstddd }|S t|tjr-dd }|S d| }t|)Nz-The first argument "array" must be array-likez7The second argument "shape" must be a tuple of integersc                 S   s   t | } t| | t| |S r  )npasarrayr  r  r   rU   r9   r9   r:   impli  s   


z numpy_broadcast_to.<locals>.implc                 S   s   t | |fS r  )r  broadcast_tor	  r9   r9   r:   r
  n     z:The argument "shape" must be a tuple or an integer. Got %s)r   r	   TypingErrorr   r   UniTuplerk   r   )r   rU   r
  r   r9   r9   r:   numpy_broadcast_to^  s   


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 allowedr<   z=shape mismatch: objects cannot be broadcast to a single shape)r.   r   r   )rmrU   r]   r   tmpr9   r9   r:   numpy_broadcast_shapes_listw  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 r<   c                  W   rY  rZ  r9   r   r9   r9   r:   <lambda>  s    z+ol_numpy_broadcast_shapes.<locals>.<lambda>r<   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 rb  )r   r   r   r   r  r   	enumerater(   )r   r  r  argr   elemr  tup_initr9   r:   r
    s   

z'ol_numpy_broadcast_shapes.<locals>.impl)r  r   r   r   r  rk   Tupler   r	   r  maxr  )r   r   r  is_intis_int_tupleis_empty_tupler   r
  r9   r  r:   ol_numpy_broadcast_shapes  s0   
r"  )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   r<   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 rW  )	r   r  r  r  rU   r.   r(   rY   r  )r   rU   r   r  r]   outsr  r9   r:   r
    s   
z$numpy_broadcast_arrays.<locals>.impl)r  r   r	   r  r   r   r   r  rk   ArrayCompatibler  r`   Numberr{  )r   r   r  unified_dtypedtr
  r9   r  r:   numpy_broadcast_arrays  s6   r*  c           %   
      s
  |j \}}|\}}t| |}t |j}	t |j}
|j}t ||||}|  t	t
jrۈj| }t t |\t j}t j}j}tj}t|t|ksnJ t||D ]\}} | d||}qs j|dd d}j t|f 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 d}j t|f W d   n	1 s(w   Y   fdd	}d
d }nfdd	}dd }|" \} }!t#dd |!D }"||"}#$ |#|j}#tj% ||	|
|j&| d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.
    r$  Fr%  z0cannot assign slice from input of different sizeNr<   r   c                    s,   | \} tjttj}| |fS r  )rB   operatorgetitemr    r   r{   )r  r   getitem_implr3   rm   r  	src_dtyper  r9   r:   r  9  s   z#fancy_setslice.<locals>.src_getitemc                   S   rU  r  r9   r9   r9   r9   r:   r  A  rV  z#fancy_setslice.<locals>.src_cleanupc                    s    S r  r9   )r  )r  r9   r:   r  I  rV  c                   S   rU  r  r9   r9   r9   r9   r:   r  L  rV  c                 s   s    | ]	}|d ur|V  qd S r  r9   )r   rg  r9   r9   r:   r  S  r  z!fancy_setslice.<locals>.<genexpr>r  )*r   ri   r
   r   rU   r   r   rz  r1  r   r   r   rk   r5  r  r  r   r   r  r   r   r'  r(  r   r  r  r   r  r  r  SequencerB   r    r{   r  r   rz   r  r  rx   r  r*  )%rm   r3   rL   r   r   r   r   r  r   dest_shapesdest_strides	dest_datar~  index_shaper  r  r  shape_errorur   r   	src_startsrc_end
dest_lower
dest_upper
dest_startdest_endr  r  r  len_implseq_lendest_indicesr  r  rw   r  r9   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   r<   c                    "   g | ]\}}  ||tjqS r9   rz   r   r{   )r   r  rw   r   r9   r:   r   r      z#vararg_to_tuple.<locals>.<listcomp>rk   r   )r   r   r
   rZ   r/   r   r  r{   r   r   r    r   )rm   r3   rL   r   r   dimtysr   r\   rU   shapetynew_signew_argsr9   r   r:   vararg_to_tuplek  s   
rH  zarray.transposec                 C   s   t | ||jd |d S r   )array_Tr   rm   r3   rL   r   r9   r9   r:   array_transpose~  s   rK  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)axisrU   r   r<  r  r9   r9   r:   permute_arrays  s   rN  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   r<   c                       g | ]}t  qS r9   r
   rH   r   r  )r3   ll_ary_sizer9   r:   r     s    z)array_transpose_tuple.<locals>.<listcomp>r   rk   r`   r  c                    s   g | ]	}t  qS r9   ri   rQ  )r3   rm   	np_ary_tyr9   r:   r     r  r   rU   r   r   r   c                 S   r  r9   r   r   ar9   r9   r:   r     r     r	  ) r   ri   r   rk   r   r   r{   r   	ArrayTyperU   r   r   r   r   r   rl   r   r  
as_pointercompile_internalrN  r   r    voidr   r   r4   r   r   r   r   r   )rm   r3   rL   r   r   r   axistyrM  num_axisrk   r=  arysll_arysr  dstnp_itemsizenp_arysnp_aryll_aryr  r   r9   )r3   rm   rR  rU  r:   array_transpose_tuple  sP   
	rh  c                 C       t | |||\}}t| |||S r  )rH  rh  rm   r3   rL   r   rF  rG  r9   r9   r:   array_transpose_vararg     rk  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rY  axesr9   r9   r:   np_transpose_impl  rG  z*numpy_transpose.<locals>.np_transpose_implc                 S   
   |  |S r  rn  rp  r9   r9   r:   rr    r\  r  )r   r   r  r	   UnsupportedError)rY  rq  rr  r9   r9   r:   numpy_transpose  s   


ru  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 )Nr<   r	  )r`   ri   r
   r   rU   r   r   r   rZ   r   r   r   r   r   )	rm   r3   typr   r   r   r  r   r   r9   r9   r:   rI    s    
rI  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 integerry  c                 S   s   t | ||}t d|S )Ng      $@)r  linspacepower)r   rx  numr  r9   r9   r:   r
    s   znumpy_logspace.<locals>.implry  )r   r   r'  r	   r  r   r   )r   rx  r|  r
  r9   r9   r:   numpy_logspace  s   



r~  r<   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 integer)The first argument "arr" must be an arrayrZ  Input must be >= 2-d.r<   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   r<   rZ     )r  swapaxesfliplrflipudr|  )r  r   r9   r9   r:   r
    s   znumpy_rot90.<locals>.implr  )	r   r   r   r   r	   r  r   r`   NumbaValueError)r  r   r
  r9   r9   r:   numpy_rot90  s   




r  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.
    numba_attempt_nocopy_reshaperU   r   r   )r   r   r{   r\  intcr   FunctionTyper
   get_or_insert_functionr0   r`   rX   rW   callr   )rm   r3   r   r   newndnewshape
newstridesr=  ll_intp_starll_intcfntyfnndrU   r   
is_f_orderr   r9   r9   r:   _attempt_nocopy_reshape  s2   	

r  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   r<   z)total size of new array must be unchangedzmultiple negative shape values)r  r   )	origsizerU   num_neg_value
known_sizer  r   neg_axinferredokr9   r9   r:   normalize_reshape_valueA  s*   

r  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   r<   r   rS  rV  r  zincompatible shape for arrayr	  )(r   r   r   r   r{   r   r[  r   ri   r
   rH   r   r   rk   r   rl   r   r  r\  r   r]  r  r   r    r^  r}   r   r  r  r/   r   r'  r(  rC   r   r4   r   r   r   r   )rm   r3   rL   r   r   rettyrE  rU   r=  ll_shaper   r  shape_ary_ty	shape_aryshape_itemsizer   r  r  r  failr   r  r   r9   r9   r:   array_reshape_  sb   


r  c                 C   ri  r  )rH  r  rj  r9   r9   r:   array_reshape_vararg  rl  r  c                 C      dd }|S )Nc                 S   rs  r  )reshape)rY  rU   r9   r9   r:   np_reshape_impl  r\  z#np_reshape.<locals>.np_reshape_implr9   )rY  rU   r  r9   r9   r:   
np_reshape  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  ravelr  concatenater  valuesrM  r9   r9   r:   r
    s   znp_append.<locals>.implz,The third argument "axis" must be an integerc                 S   s   t j| |f|dS NrM  r  r  r  r9   r9   r:   r
       r  )r   r	   r  r   r   r   r   )r  r  rM  r
  r9   r9   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   r9   r9   r:   
imp_nocopy     zarray_ravel.<locals>.imp_nocopyc                 S   rm  )zCopy version)flattenr  r9   r9   r:   imp_copy     zarray_ravel.<locals>.imp_copyr   r   r   r  r]  r   r   )rm   r3   rL   r   r  r  impr   r9   r9   r:   array_ravel  s   r  c                 C      dd }|  ||||S )Nc                 S   rm  r  )r  rY  r9   r9   r:   np_ravel_impl  rG  znp_ravel.<locals>.np_ravel_implr]  )rm   r3   rL   r   r  r9   r9   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  r9   r9   r:   r    rs  zarray_flatten.<locals>.impr]  r   r   )rm   r3   rL   r   r  r   r9   r9   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  )rY  a_mina_maxr   r  a_ba_min_ba_max_br   val_a	val_a_min	val_a_maxr9   r9   r:   _np_clip_impl  s   r  c                 C   sH   t | jD ]}| | }|| }|rt||||< qt||||< q|S r  )r  r  rU   r  r  )rY  buse_minr   r   r  val_br9   r9   r:   _np_clip_impl_none  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 )Nz#The argument "a" must be array-likez6The 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   s   t d)Nz&array_clip: must set either max or min)r   rY  r  r  r   r9   r9   r:   
np_clip_nn$  rG  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  rY  r  r  r   r  r   r  r9   r9   r:   
np_clip_ss-  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  r9   r9   r:   
np_clip_sn;  
   znp_clip.<locals>.np_clip_snc                 S   s   t | |}t| |||S r  r  	full_liker  )rY  r  r  r   
a_min_fullr9   r9   r:   
np_clip_saH     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  r9   r9   r:   
np_clip_nsS  r  znp_clip.<locals>.np_clip_nsc                 S   s   t | |}t| |||S r  r  )rY  r  r  r   
a_max_fullr9   r9   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  )rY  r  r  r   r  r  r  r9   r9   r:   
np_clip_nal     znp_clip.<locals>.np_clip_nac                 S   s4   |d u r	t | n|}t | |\}}t||d|S )NFr  )rY  r  r  r   r  r  r  r9   r9   r:   
np_clip_ant  r  znp_clip.<locals>.np_clip_anc                 S      t | |||S r  )r  r  r9   r9   r:   
np_clip_aa|  s   znp_clip.<locals>.np_clip_aar  )	r   r	   r  r   r   NoneTyper   r   r'  )rY  r  r  r   r   a_min_is_nonea_max_is_noner  a_min_is_scalara_max_is_scalarr  r  r  r  r  r  r  r  r9   r9   r:   np_clip  sV   












r  clipc                 C   s   ddd}|S )Nc                 S   s   t | |||S r  )r  r  r  r9   r9   r:   r
    rs  zarray_clip.<locals>.implNNNr9   )rY  r  r  r   r
  r9   r9   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 )Nrw  r   Fr<   Tr9   )	r  r\   r   old_itemsizenew_itemsizer  r]   newdim
bytelength
any_layoutc_layoutf_layoutint8r9   r:   r    s4   

z_change_dtype.<locals>.imprU   r   r   r<   rS  NrV  )r`   r  ordr   r  r   r{   ro   r
   rX   rW   r   ri   rZ   rl   rj   r   r   r    booleanr]  r   r   r   )rm   r3   oldtynewtyr   
new_layoutr  r  r  r  
shape_datastrides_datashape_strides_array_typearyclsshape_constantsizeof_intpstrides_constantr  strides_aryrU   r   r   rL   r   r9   r  r:   _change_dtype  s   	
0



	
r  c                 C   s   t | s	tddd }|S )Nz+The argument to np.shape must be array-likec                 S   s   t | jS r  )r  r  rU   r  r9   r9   r:   r
  	  rX  znp_shape.<locals>.implr   r	   r  rY  r
  r9   r9   r:   np_shape
	  s   
r  c                 C      dd }|S )Nc                    sJ   t |   t d d } fddt dd  D }t || S )Nr<   c                    s    g | ]\}} | |kr|qS r9   r9   )r   r]   r  r  r9   r:   r   	  s     z5np_unique.<locals>.np_unique_impl.<locals>.<listcomp>)r  sortr  r   r  r   )rY  headtailr9   r  r:   np_unique_impl	  s   z!np_unique.<locals>.np_unique_implr9   )rY  r  r9   r9   r:   	np_unique	  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rk   r   r<   r  z(operands could not be broadcast together)r  r  int64rU   np_repeat_impl_repeats_scalerr  r   r  emptyr  rk   r.   )	rY  repeatsrepeats_arrayasaaraveln	to_returnposr]   r9   r9   r:   !np_repeat_impl_repeats_array_like%	  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'  r{  r   r  rk   r	   r  )rY  r  r  r9   r9   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  r<   )	r   r  r  r  rU   r  rk   r  r.   )rY  r  r  r  r  r  r]   r9   r9   r:   r  M	  s   


r  repeatc                 C   r  )Nc                 S      t | |S r  )r  r!  )rY  r  r9   r9   r:   array_repeat_impla	  rX  z'array_repeat.<locals>.array_repeat_implr9   )rY  r  r#  r9   r9   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   )rj   r   rk   r   rl   )cgctxr3   rL   llargsrn   llintpr9   r9   r:   r  l	  s   z%_intrin_get_itemsize.<locals>.codegen)r   r{   )tyctxrk   rL   r  r9   r9   r:   _intrin_get_itemsizeg	  s   
r+  c                 C   rU  r  r9   )rY  rk   r9   r9   r:   _compatible_views	  rV  r,  generic)targetc                 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 unchangedr<   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   )rY  rk   
dtype_sizemsg1rM  p1p2p3msg2msg3r  msg4r9   r9   r:   r
  }	  s0   




z ol_compatible_view.<locals>.implr9   rY  rk   r
  r9   r9   r:   ol_compatible_vieww	  s   #r8  z
array.viewc                 C   sD  |j d }|j}t|| ||d }t|| |}t|jj}t|D ]}	t||	}
|	dkr:|jj	}|
|
||_q#t||	|
 q#tdkrc| 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<      r  z"new type not compatible with array)r   r   ri   r   r   r   sortedgetattrr   r/   r  r   r   typing_contextresolve_value_typer,  get_call_typerB   r  r  r   r   r'  r(  r   r   r   )rm   r3   rL   r   r   r  r   r  fieldsr   rw   r  r*  r  _compatible_view_sigr
  r  r  r   r   r9   r9   r:   
array_view	  s2   



rA  rk   c                 C   s   |   }t| |||S r  )r*  r   rm   r3   rx  r   r   r9   r9   r:   array_dtype	  s   rC  rU   c                 C   (   t |}|| ||}|j}t| |||S r  )ri   rU   r   rm   r3   rx  r   rt   r   r   r9   r9   r:   array_shape	     rF  r   c                 C   rD  r  )ri   r   r   rE  r9   r9   r:   array_strides	  rG  rH  r`   c                 C      |  tj|j}t| |||S r  )r   r   r{   r`   r   rB  r9   r9   r:   
array_ndim	  s   rJ  r   c                 C   rD  r  )ri   r   r   rE  r9   r9   r:   
array_size	  s   rK  r   c                 C   rD  r  )ri   r   r   rE  r9   r9   r:   array_itemsize	  rG  rL  nbytesc                 C   s2   t |}|| ||}||j|j}t| |||S )z"
    nbytes = size * itemsize
    )ri   r   r   r   r   rE  r9   r9   r:   array_nbytes	  s   rN  
contiguousc                 C   rI  r  )r   r   r  	is_contigr   rB  r9   r9   r:   array_contiguous	
     rQ  c_contiguousc                 C   rI  r  )r   r   r  is_c_contigr   rB  r9   r9   r:   array_c_contiguous
  rR  rU  f_contiguousc                 C   rI  r  )r   r   r  is_f_contigr   rB  r9   r9   r:   array_f_contiguous
  rR  rX  r  c                 C   s    |  tj|j }t| |||S r  )r   r   r  mutabler   rB  r9   r9   r:   array_readonly
  rl  rZ  ctypesc           	      C   sP   t |}|| ||}t|}| ||}|j|_|j|_| }t| |||S r  )ri   r   ArrayCTypesr   r   r   r   r   )	rm   r3   rx  r   rt   r   actctinfor   r9   r9   r:   array_ctypes#
  s   
r_  r   c                 C   s8   | j |||d}|j}||| tj}t| |||S Nr   )r   r   r  r   r   r{   r   )rm   r3   rx  r   r^  r   r9   r9   r:   array_ctypes_data0
  s   ra  c                 C   s6   | j |||d}|j}||| |}t| |||S r`  )r   r   r  r   r   )rm   r3   fromtytotyrw   r^  r   r9   r9   r:   array_ctypes_to_pointer9
  s   rd  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   )ri   r   r  r{   r`   rl   r   rk   r    bool_rU   r   r   r]  )
checkerrm   r3   r   r   tup_intpr   	check_sig
check_argsrP  r9   r9   r:   _call_contiguous_checkB
  s   
rj  r   c                 C   s>   |  |t|}||_| }| j||| t| |||S r  )r   r   
ArrayFlagsr   r   r   r   r   )rm   r3   rx  r   flagsobjr   r9   r9   r:   array_flags\
  s
   rm  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   rj  r   r   r   r   r  r   )rm   r3   rx  r   rl  r   rw   r9   r9   r:   array_flags_c_contiguouse
  s   rn  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   r<   r  )rS   r  r   rj  r   r   r`   r   r   r  r   )rm   r3   rx  r   rl  r   r  rw   r9   r9   r:   array_flags_f_contiguouss
  s   ro  realc                 C   sH   |j tjv rt| |||ddS |j tjv rt| |||S tdtj )Nrp  attrzunsupported .real for {})	rk   r   complex_domainarray_complex_attrnumber_domainr   rC   r   r/   )rm   r3   rx  r   r9   r9   r:   array_real_part
  s
   rv  imagc                 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 )Nrw  rq  T)r  r   zunsupported .imag for {})rk   r   rs  rt  ru  r    r  _parse_empty_like_argsr  r
   memsetr   r   r   r   r   r   r   rC   r   r/   )rm   r3   rx  r   rL   r  r   r   r9   r9   r:   array_imag_part
  s   
rz  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
          ^   ^   ^
    )rp  rw  zcannot get attribute `{}`rw      r<   r  rk   r  )r   r   )rk   r   rs  rC   r   ri   underlying_floatrl   rj   r   r/   r   r\  r  r   r  r   IntTyper  r   r
   r  r   r   )rm   r3   rx  r   rr  rt   r   fltysizeof_fltyr   
llfltptrtyr   resulttyr   r  r9   r9   r:   rt  
  s    rt  conj	conjugatec                 C   r  )Nc                 S   s
   t | S r  )r  r  r  r9   r9   r:   r
  
  r\  zarray_conj.<locals>.implr9   r  r
  r9   r9   r:   
array_conj
     r  c                 C   rm  r  )r*  )rm   r3   dtypetydtypevalr9   r9   r:   
dtype_type
  r  r  r/   kindc              	      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  rS  r|  )r   c                       g | ]	}  tj|qS r9   r   r   r{   r  rm   r9   r:   r     r  z(array_record_getattr.<locals>.<listcomp>c                    r  r9   r  r  r  r9   r:   r     r  r	  )ri   rk   r   r   RecordrC   typeofr   NestedArrayr  r`   r   r{   r
   r   r   r/   r   rU   r   rl   rj   r   r   r   r   r   )rm   r3   rx  r   rr  rt   r   rectyperk   r   restyrarytyraryconstoffset
newdataptrrU   r   datasizer   r9   r  r:   array_record_getattr
  sN   


r  static_getitemc                 C   s0   |d }t |tstt| ||jd |d |S rb  )r   strrC   r  r   )rm   r3   rL   r   r   r9   r9   r:   array_record_getitem&  s   
r  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  r9   r  r   r   r  r9   r:   r   >  r  z"record_getattr.<locals>.<listcomp>c                    r  r9   r  r  r  r9   r:   r   @  r  Nr	  r<   )sentry_record_alignmentr   r  r   r   r  ri   rk   rU   r   r
   get_record_memberrj   r   rZ   r   r{   r   r   r   rr   rs   )rm   r3   rx  r   rr  r   elemtyr   r   rk   r  r  newdatar   dptrrq   r9   r  r:   record_getattr/  sB   







	
r  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.
    r<   r   Nrp   )r   r  r   r  r   r   r  r
   rh   r   r  r/   pointeememcpyr   r{   r   rj   rz   rr   rv   )rm   r3   rL   r   rr  rx  r  r.  rw   r   r  
val_structr  r  r  rq   r9   r9   r:   record_setattrW  s,   





r  c                 C   s4   |  |jd |d }|| ||jd |d |d S )3
    Record.__getitem__ redirects to getattr()
    r   r<   )get_getattrr   )rm   r3   rL   r   r
  r9   r9   r:   record_static_getitem_stru  s   r  c                 C   s^   |j d j}t|j d j}| |j|| }| |j d |}|| ||j d |d || S )r  r<   r   )r   literal_valuer   r?  insert_const_stringr0   r  )rm   r3   rL   r   r   r?  ll_fieldr
  r9   r9   r:   record_static_getitem_int~  s
   r  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)rm   r3   rL   r   rectyr  r  recr   rw   getattr_sigr
  r9   r9   r:   record_static_setitem_str  s   
r  c                 C   s^   |j \}}}|\}}}	t|j||}
t|j d j}| || |
}|dus(J ||||	fS )r  r   N)r   r    r   r   r?  r  )rm   r3   rL   r   r  r  r  r  r   rw   r  r?  r
  r9   r9   r:   record_static_setitem_int  s   
r  c                 C   s   |  |||S )zB
    Create a constant array (mechanism is target-dependent).
    )make_constant_array)rm   r3   r  pyvalr9   r9   r:   constant_array  s   r  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~  rM  	bytearraytostringr
   r   )rm   r3   r  r  ltyrw   r9   r9   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   r  uint8r  )rm   r3   r  r  bufr9   r9   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   rY  r  r9   r9   r:   array_is_impl  s
   
zarray_is.<locals>.array_is_impl)r   r
   r  r]  )rm   r3   rL   r   atybtyr  r9   r9   r:   array_is  s
   
r  c                 C   
   t | dS )zq
    Return the Structure representation of the given *flatiterty* (an
    instance of types.NumpyFlatType).
    flat_make_flattening_iter_cls)
flatitertyr9   r9   r:   make_array_flat_cls     
r  c                 C   r  )zv
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdEnumerateType).
    ndenumerater  nditertyr9   r9   r:   make_array_ndenumerate_cls  r  r  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   end_incrementr   )r   r   r{   r?  r   r
   
false_byter  r.   rX   r   r4   r   	if_likelyrM  	true_byterN  )rm   r3   r`   rU   r   end_flagloop_continue
loop_breakr   bbendr<  idxptrr   r   	in_boundsr9   r9   r:   _increment_indices  s.   

r  c                 C   s*   t ||j|j}t| ||j||| d S r  )r
   r   rU   r`   r  )rm   r3   r  r  r   r  rU   r9   r9   r:   _increment_indices_array	  s   r  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).
    r<   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`   )rJ   r  r  r  r  r9   r9   r:   r>    s
   z-make_nditer_cls.<locals>.BaseSubIter.__init__c                 S   s   t | j| j| d S r  )r   r  r  )rJ   r[   r9   r9   r:   set_member_ptr%     z3make_nditer_cls.<locals>.BaseSubIter.set_member_ptrc                 S   s   t | j| jS r  )r;  r  r  r0  r9   r9   r:   
member_ptr(     z/make_nditer_cls.<locals>.BaseSubIter.member_ptrc                 S   rU  r  r9   rJ   rm   r3   r9   r9   r:   init_specific,  rV  z2make_nditer_cls.<locals>.BaseSubIter.init_specificc                 S   rU  r  r9   rJ   rm   r3   logical_dimr9   r9   r:   r  /  rV  z2make_nditer_cls.<locals>.BaseSubIter.loop_continuec                 S   rU  r  r9   r  r9   r9   r:   r  2  rV  z/make_nditer_cls.<locals>.BaseSubIter.loop_breakN)ra   rb   rc   r9  r>  r  r   cached_propertyr  r  r  r  r9   r9   r9   r:   BaseSubIter  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   r{   r  r
   r   )rJ   rm   r3   r   r9   r9   r:   r  ;  s   z2make_nditer_cls.<locals>.FlatSubIter.init_specificc                 S   s   | | j}||j|gS r  )r4   r  r  r   )rJ   rm   r3   r   r  r  r   r9   r9   r:   compute_pointer?  s   z4make_nditer_cls.<locals>.FlatSubIter.compute_pointerc                 S   s<   || j d kr|| j}t||}||| j d S d S rW  )r`   r4   r  r
   r   r   )rJ   rm   r3   r  r   r9   r9   r:   r  C  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 Nr   r<   )	r   r   r{   r   r  r`   r4   r
   r   )rJ   rm   r3   r  r   r   r9   r9   r:   r  J  s   z/make_nditer_cls.<locals>.FlatSubIter.loop_breakN)ra   rb   rc   r9  r  r  r  r  r9   r9   r9   r:   FlatSubIter5  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  r  r9   r:   r  [  r  z9make_nditer_cls.<locals>.TrivialFlatSubIter.init_specificc                 S   s&   t |dksJ t |||j|S rW  )r   r  r   rJ   rm   r3   r   r  r  r9   r9   r:   r  ^  s   z;make_nditer_cls.<locals>.TrivialFlatSubIter.compute_pointerN)ra   rb   rc   r9  r  r  r9   r  r9   r:   TrivialFlatSubIterU  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  r9   r9   r:   r  g  s   z7make_nditer_cls.<locals>.IndexedSubIter.compute_pointerNra   rb   rc   r9  r  r9   r9   r9   r:   IndexedSubIterb      r  c                   @   r  )z'make_nditer_cls.<locals>.ZeroDimSubIterz5
        Sub-iterator "walking" a 0-d array.
        c                 S   s   |j S r  r  r  r9   r9   r:   r  q  rE  z7make_nditer_cls.<locals>.ZeroDimSubIter.compute_pointerNr  r9   r9   r9   r:   ZeroDimSubIterl  r  r  c                   @   r  )z&make_nditer_cls.<locals>.ScalarSubIterz8
        Sub-iterator "walking" a scalar value.
        c                 S   s   |S r  r9   r  r9   r9   r:   r  y  rV  z6make_nditer_cls.<locals>.ScalarSubIter.compute_pointerNr  r9   r9   r9   r:   ScalarSubItert  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)r  indexed0dscalarzindex%d)r  r  r}  rY   )rJ   l	factoriesr]   r  r  r  r  r  r  factory)r  r  r  r  r  r  r9   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%dNr9   r<   c                 S   s>   t | }t|D ]}| | |t || |  krtdqd S )Nz2nditer(): operands could not be broadcast together)r   r.   r   )rU   
main_shaper  r]   r9   r9   r:   check_shape  s   zBmake_nditer_cls.<locals>.NdIter.init_specific.<locals>.check_shaper  rw  r  rD  )&r   r   r{   
make_tupler  arraysr  r   r   r
   r   r   _arrays_or_scalarsr  r`   rU   r   r   r    noner]  r   r   rw  r  r  r  r   rH   r/   r.   rX   r   r   rZ   	exhaustedr   r  )rJ   rm   r3   arrtysr  r   r]   r  r  slotmain_shape_tyr  main_nitemsr  r  r  rL   r   shape_is_emptyr  r   r<  r  subiter)r  r`   r  nshapesr9   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   r  r9   rW  r   r   r9   r9   r:   r     r  zEmake_nditer_cls.<locals>.NdIter.iternext_specific.<locals>.<listcomp>r<   r   )r?  r
   as_bool_bitr4   r  if_unlikelyr   rM  r  r   r  r   _make_viewsr   r   r  r   rU   r  r  partial_loop_continue_loop_breakrN  )rJ   rm   r3   r   r  r  r	  r  r   viewsrU   r  r9   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  r  rJ   rm   r3   r<  r  r9   r9   r:   r    
   
z.make_nditer_cls.<locals>.NdIter._loop_continuec                 S   r  r  )r   r  r  r  r  r9   r9   r:   r    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 r9   r4   r
   rX   r  r3   r   r9   r:   r   #  s    z?make_nditer_cls.<locals>.NdIter._make_views.<locals>.<listcomp>r  rw  c                 s   s    | ]}|V  qd S r  r9   r  r9   r9   r:   r  0  s    z>make_nditer_cls.<locals>.NdIter._make_views.<locals>.<genexpr>)r}  r   r   r   r   r  r   r.   r   r  r  
_make_viewall)rJ   rm   r3   r   r	  r  r  r}  r   rettysr  r  r  array_indicessub_indicesr]   )r  narraysr  r  r  r:   r    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   r9   N)r   )r   r   r   r`   r  ri   ro   r  r  r{   r   )rJ   rm   r3   r   r  r  r  r  r[   viewr   rU   r   r9   r9   r:   r  3  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   ri   r;  )	rJ   rm   r3   r	  r  r  r]   r  r  r9   r9   r:   r  G  s   
z2make_nditer_cls.<locals>.NdIter._arrays_or_scalarsN)ra   rb   rc   r9  r   r  r   r  r  r  r  r  r  r  r9   
r  r  r  r  r  r  r$  r`   r  r  r9   r:   NdIter|  s    O*r'  )r`   r  r   r  r  objectr
   rh   )r  r  r'  r9   r&  r:   make_nditer_cls  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   rD  r  )r   r   r{   r
   rH   r/   r   r  r.   rX   r   r  r  r  r   r  rZ   rU   )rJ   rm   r3   r   r   r   r  r<  r  ro  dim_is_emptyr`   r9   r:   r  c  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 r9   )r4   r
   rX   r   r   r<  r3   rJ   r9   r:   r     s    

zKmake_ndindex_cls.<locals>.NdIndexIter.iternext_specific.<locals>.<listcomp>T)r   r   r{   r?  r
   r  r4   r  r  r   rM  r.   r>   r   rZ   r/   r   rU   r  r   rN  )
rJ   rm   r3   r   r   r  r  r   r4   rU   r,  r.  r:   r  y  s,   





z7make_ndindex_cls.<locals>.NdIndexIter.iternext_specificN)ra   rb   rc   r9  r  r  r9   r,  r9   r:   NdIndexIter^  s    r/  )r`   r
   rh   )r  r/  r9   r,  r:   make_ndindex_clsW  s   7r0  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)r  r  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   r  rD  )r   r   r{   r
   r   r   r   r  rH   r/   r`   r.   rX   r   r   )	rJ   rm   r3   r  r  r   r   r<  r  r  r9   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   r  c              	      r  r9   r  r-  r  r9   r:   r         

z\_make_flattening_iter_cls.<locals>.CContiguousFlatIter.iternext_specific.<locals>.<listcomp>)r`   r   r4   r   r   r   r
   r  r  r   ru   r   r   r.   rZ   make_anonymous_structr  r   r   )rJ   rm   r3   r  r  r   r`   r   r   r   r[   r   idxvalsidxtupler1  r  r:   r    s4   
"zH_make_flattening_iter_cls.<locals>.CContiguousFlatIter.iternext_specificc                 S   s   | |j|g}t||||S r  )r  r   ru   rJ   rm   r3   r  r  r   r[   r9   r9   r:   r,    s   z>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.getitemc                 S   s$   | |j|g}t||||| d S r  )r  r   rx   rJ   rm   r3   r  r  r   r   r[   r9   r9   r:   setitem  s   z>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.setitemN)ra   rb   rc   r9  r  r  r,  r8  r9   r1  r9   r:   CContiguousFlatIter  s    r9  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   r{   r   r`   r
   r   rU   rH   r/   r   r  r.   rX   r   r  r  r  r   pointersr  )rJ   rm   r3   r  r  r   r   r`   r   r   r:  r  r<  r  ptrptrro  r+  r9   r9   r:   r    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  FTr<   r  c              	      r  r9   r  r-  r  r9   r:   r   )  r2  zQ_make_flattening_iter_cls.<locals>.FlatIter.iternext_specific.<locals>.<listcomp>r   )r`   r
   r   rU   r   r   r:  r   r   r{   r?  r  r4   r  r  r   rM  rX   ru   r   r.   rZ   r3  r  r   r   r  r   r   r  rN  )rJ   rm   r3   r  r  r   r`   r   r   r:  r   r  is_exhaustedlast_ptrr[   r   r4  r5  r<  r  r   r   r  r  r;  	inner_dimr1  r  r:   r    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  r.   rY   uremudivreverser  r   r  )rJ   rm   r3   r  r  r   r`   r   r   r   r<  r[   r9   r9   r:   _ptr_for_indexS  s   z:_make_flattening_iter_cls.<locals>.FlatIter._ptr_for_indexc                 S   s    |  |||||}t||||S r  )rB  ru   r6  r9   r9   r:   r,  d  s   z3_make_flattening_iter_cls.<locals>.FlatIter.getitemc                 S   s&   |  |||||}t||||| d S r  )rB  rx   r7  r9   r9   r:   r8  h  s   z3_make_flattening_iter_cls.<locals>.FlatIter.setitemN)	ra   rb   rc   r9  r  r  rB  r,  r8  r9   r1  r9   r:   FlatIter  s    !ErC  )rS   r  r
   rh   )r  r  rS   r9  rC  r9   r1  r:   r    s   
D r  r  c                 C   sh   t t|}|| |}||_| |}|| ||dd}|| ||| | }t| |t||S Nr   )rK   )	r  r   NumpyFlatTyper   ri   rW   r  r   r   )rm   r3   r  r  flatiterclsflatiterarrclsr   r9   r9   r:   make_array_flatitero  s   

rI  c                 C   Z   |j \}|\}t|}|| ||d}|j}| |}	|	| ||jd}
|| |||
| d S r`  )r   r  rS   ri   r   r  )rm   r3   rL   r   r   r  rG  rF  r  rH  r  r9   r9   r:   iternext_numpy_flatiter     
rK  c                 C   sj   |j d }|\}}t|}|| ||d}|j}| |}	|	| ||jd}
|| |||
|}t| ||j|S Nr   r   )r   r  rS   ri   r   r,  r   r   )rm   r3   rL   r   r  rG  r   rF  r  rH  r  r   r9   r9   r:   iternext_numpy_getitem  s   

rN  c                 C   sf   |j d }|\}}}t|}|| ||d}|j}	| |	}
|
| ||jd}|| ||	||| |  S rM  )r   r  rS   ri   r   r8  r*  )rm   r3   rL   r   r  rG  r   r   rF  r  rH  r  r9   r9   r:   iternext_numpy_getitem_any  s   


rO  c           	      C   sF   |j d }t|}|| ||d d}| |j}|| ||jd}|jS rM  )r   r  ri   rS   r   r   )	rm   r3   rL   r   r  rF  rG  rH  r  r9   r9   r:   iternext_numpy_getitem_flat  s   
rP  c           
      C   sr   |j \}|\}tt|}|| |}||_| |}|| ||dd}|| ||| | }	t	| ||j
|	S rD  )r   r  r   NumpyNdEnumerateTyper   ri   rW   r  r   r   r   )
rm   r3   rL   r   r  r  	nditerclsr  rH  r   r9   r9   r:   make_array_ndenumerate  s   

rS  c                 C   rJ  r`  )r   r  rS   ri   r   r  )rm   r3   rL   r   r   r  r  rR  r  rH  r  r9   r9   r:   iternext_numpy_nditer  rL  rT  c                    s^    fddt |j|D }ttt|}| }| | | }t |j	|S )zndindex(*shape)c                    r@  r9   rA  )r   argtyr  r   r9   r:   r     rB  z&make_array_ndindex.<locals>.<listcomp>)
r   r   r0  r   NumpyNdIndexTyper   r  r   r   r   )rm   r3   rL   r   rU   rR  r  r   r9   r   r:   make_array_ndindex  s   

rW  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 r9   rA  )r   r   r3   rm   r~   r9   r:   r         z,make_array_ndindex_tuple.<locals>.<listcomp>)r   r`   r   rk   r
   r   r0  r   rV  r   r  r   r   )
rm   r3   rL   r   r`   r  rU   rR  r  r   r9   rX  r:   make_array_ndindex_tuple  s   
rZ  c                 C   s6   |j \}|\}t|}|| ||d}|| || d S r`  )r   r0  r  )rm   r3   rL   r   r   r  r  rR  r9   r9   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   )	rm   r3   rL   r   r  r	  r  r  r   r9   r9   r:   make_array_nditer  s   
r\  c                 C   s2   |j \}|\}t|| ||d}|| || d S r`  )r   r)  r  )rm   r3   rL   r   r   r  r  r9   r9   r:   iternext_numpy_nditer2#  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.
    r<   r   r9   r   Nrw  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  rV  )+ri   rj   rk   r   r   r{   ro   r   r   r~  smul_with_overflowr   r  r`   r  r  rY   r   r   rC   r   r   r'  r(  r   get_preferred_array_alignmentuint32r*  MemInfoPointervoidptrTypeRefr/   r    r]  _call_allocatorr   meminfo_datar   r
   rZ   r   r  r\  )rm   r3   r  r   r  r   datatyper   arrlenoverflowr   arrlen_multr   dimension_sizeallocsize_multr  rk   	align_valrq   r   miparytypeclassargtypesr   r   r   shape_arraystrides_arrayr9   r9   r:   r  0  st   




	
r  	_allocatec                 C   s   dd }|S )zPImplements a Numba-only default target (cpu) classmethod on the array type.
    c                 S   s
   t ||S r  )intrin_alloc)clsr  rq   r9   r9   r:   r
    r\  z _ol_array_allocate.<locals>.implr9   )rt  r  rq   r
  r9   r9   r:   _ol_array_allocate  s   ru  c                 C   s   |  ||S )z9Trampoline to call the intrinsic used for allocation
    )rr  )r  r   rq   r9   r9   r:   rd    s   rd  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   meminfo_alloc_aligned)rm   r3   r    r   r  rq   r   r9   r9   r:   r    s   zintrin_alloc.<locals>.codegen)r   ra  rb  r    )r  r  rq   r  rm  rL   r9   r9   r:   rs    s   rs  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 maintainedr<   >Fr%  )z#Cannot safely convert value to intpN)r   r   r{   r=   r   r~  r   sextr   r   r'  r(  r   trunc)
rm   r3   src_tr  r   
intp_widthintp_irmaxvalr   	is_largerr9   r9   r:   safecast_intp  s(   



z#_parse_shape.<locals>.safecast_intpr<   r   r   r   )znegative dimensions not allowedN)r   r   r   rz   r{   r  r   r
   r   rY   r/   get_constant_genericr.   r   r  r'  r(  r   )rm   r3   r  rw   r  r`   passed_shapesr   r   r   r<  is_negr9   r9   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  )rm   r3   rL   r   arrshapetypearrshaper  r9   r9   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   r9   )
r   r   r   r   ri   r
   r   rU   r`   r   )rm   r3   rL   r   arytyper   r   r9   r9   r:   rx    s   


rx  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   UnicodeTyper	   r  )fnamerk   r   r9   r9   r:   _check_const_str_dtype  s   
r  c                 C   "   |j }||||}dd }||fS )Nc                 S   (   t | |||\}}t| |||}| S r  )r  r  r   r'  r3   rL   r(  r  r   r   r9   r9   r:   r       znumpy_empty_nd.<locals>.codegeninstance_type)r*  ty_shapety_dtypety_retty_refty_rettyrL   r  r9   r9   r:   numpy_empty_nd     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   rS  c                       t | | S r  )r  )rU   rk   r  r9   r:   r
    rX  zol_np_empty.<locals>.implz.Cannot parse input types to function np.empty(, ))r  floatr   r   Function
typing_keyr   doublety_parse_dtypety_parse_shaper   r	   r  )rU   rk   nb_dtyper`   r
  r   r9   r  r:   ol_np_empty  s"   


r  c                 C   r  )Nc                 S   r  r  )rx  r  r   r  r9   r9   r:   r    r  z$numpy_empty_like_nd.<locals>.codegenr  )r*  ty_prototyper  r  r  rL   r  r9   r9   r:   numpy_empty_like_nd  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)rk   r  r  r   z3Cannot parse input types to function np.empty_like(r  r  c                    r  r  )r  )r  rk   r  r9   r:   r
  ,  rX  zol_np_empty_like.<locals>.implr  )r  r   r  r   r   r   rk   r  r  r	   r  )r  rk   r  r  r   r
  r9   r  r:   ol_np_empty_like  s&   


r  c                 C   r&  )Nc                 S   s<   t |jd | ||d }t||j||j|jd d S r   )ri   r   r
   ry  r   r   r   r   )r'  r3   rL   r(  r   r9   r9   r:   r  5  s   z(_zero_fill_array_method.<locals>.codegen)r   r  )r*  rJ   rL   r  r9   r9   r:   _zero_fill_array_method1  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  r0  r9   r9   r:   r
  ?  rX  z ol_array_zero_fill.<locals>.implr9   )rJ   r
  r9   r9   r:   ol_array_zero_fill<  r  r  c                 C   s   t d| tfdd}|S )Nzerosc                 S      t j| |d}|  |S Nr  )r  r  r  )rU   rk   r  r9   r9   r:   r
  H     zol_np_zeros.<locals>.impl)r  r  rU   rk   r
  r9   r9   r:   ol_np_zerosD  s   
r  c                 C      t d| ddd}|S )N
zeros_likec                 S   r  r  )r  r  r  )rY  rk   r  r9   r9   r:   r
  T  r  zol_np_zeros_like.<locals>.implr  r  r7  r9   r9   r:   ol_np_zeros_likeO  s   

r  c                 C   r  )N	ones_likec                 S   2   t j| |d}|j}tt|D ]}d||< q|S Nr  r<   r  r  r  r.   r   )rY  rk   r  arr_flatr   r9   r9   r:   r
  `  
   
zol_np_ones_like.<locals>.implr  r  r7  r9   r9   r:   ol_np_ones_like[  s   

r  c                 C   (   dd }|  ||||}t| ||j|S )Nc                 S   s4   t | t|}|j}tt|D ]}|||< q|S r  )r  r  r/   r  r.   r   )rU   r   r  r  r   r9   r9   r:   fulll  s
   
znumpy_full_nd.<locals>.fullr  rm   r3   rL   r   r  r   r9   r9   r:   numpy_full_ndi     r  c                 C   r  )Nc                 S   s0   t | |}|j}tt|D ]}|||< q|S r  r  r  r  r.   r   )rU   r   rk   r  r  r   r9   r9   r:   r  {  
   
z!numpy_full_dtype_nd.<locals>.fullr  r  r9   r9   r:   numpy_full_dtype_ndw     r  c                 C   r  )Nc                 S   s.   t | } | j}tt|D ]}|||< q| S r  r  )r  r   r  r   r9   r9   r:   r    s
   

z%numpy_full_like_nd.<locals>.full_liker  rm   r3   rL   r   r  r   r9   r9   r:   numpy_full_like_nd  r  r  c                 C   r  )Nc                 S   s0   t | |} | j}tt|D ]}|||< q| S r  r  )r  r   rk   r  r   r9   r9   r:   r    r  z/numpy_full_like_nd_type_spec.<locals>.full_liker  r  r9   r9   r:   numpy_full_like_nd_type_spec  r  r  c                 C   r  )Nonesc                 S   r  r  r  )rU   rk   r  r  r   r9   r9   r:   r
    r  zol_np_ones.<locals>.implr  r  r  r9   r9   r:   
ol_np_ones  s   

r  c                 C   r  )Nc                 S   s,   t | | f}t| D ]}d|||f< q|S rW  r  r  r.   )r  r  r]   r9   r9   r:   identity  s   z numpy_identity.<locals>.identityr  rm   r3   rL   r   r  r   r9   r9   r:   numpy_identity  s   r  c                 C   r  )Nc                 S   s.   t | | f|}t| D ]}d|||f< q|S rW  r  )r  rk   r  r]   r9   r9   r:   r    s   z*numpy_identity_type_spec.<locals>.identityr  r  r9   r9   r:   numpy_identity_type_spec  s   r  c                 C   rU  r  r9   NMr9   r9   r:   _eye_none_handler  rV  r  c                 C   s$   t |tjrdd }|S dd }|S )Nc                 S   s   | S r  r9   r  r9   r9   r:   r
    rV  z$_eye_none_handler_impl.<locals>.implc                 S      |S r  r9   r  r9   r9   r:   r
    rV  r   r   r  )r  r  r
  r9   r9   r:   _eye_none_handler_impl  s
   r  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 )Nrk   r   c                    s   t | |}t| |f }|dkr)t| || }t|D ]
}d|||| f< q|S t| | |}t|D ]
}d||| |f< q4|S r  )r  r  r  r  r.   )r  r  r   rk   _Mr  dr]   r)  r9   r:   r
    s   
znumpy_eye.<locals>.impl)
r   r   r  r  rk   r  	DTypeSpecr'  r   r;  )r  r  r   rk   r
  r9   r  r:   	numpy_eye  s   
r  c                 C   r  )Nc                 S      t j| ddS )Nr   )r   )r  diag)rw   r9   r9   r:   	diag_impl  r  znumpy_diag.<locals>.diag_implr  )rm   r3   rL   r   r  r9   r9   r:   
numpy_diag  s   r  c                 C   s^   |j d }|jdkrddd}n|jdkrddd}ntd| ||||}t| ||j|S )	Nr   r<   c                 S   s   | j }|d t| }t||f| j}|dkr-t|| D ]}| | |||| f< q|S t|| D ]}| | ||| |f< q3|S r   )rU   rL  r  r  rk   r.   )r  r   r   r  r  r]   r9   r9   r:   r    s   z#numpy_diag_kwarg.<locals>.diag_implrZ  c                 S   s   | j \}}|dk r|| }|dkr|| }tt||d}t|| j}|dkr;t|D ]}| ||| f ||< q,|S t|D ]}| || |f ||< q?|S r   )rU   r  r  r  r  rk   r.   )r  r   rowscolsr  r  r]   r9   r9   r:   r    s   
zInput must be 1- or 2-d.r$  )r   r`   r   r]  r   r   )rm   r3   rL   r   r  r  r   r9   r9   r:   numpy_diag_kwarg  s   


r  z
array.takec                 C   r  )Nc                 S   s.   || j d ks|| j  k rtd|  | S )Nr<   Index out of bounds)r   
IndexErrorr  )rY  r   r9   r9   r:   	take_impl+  s   znumpy_take_1.<locals>.take_implr  rm   r3   rL   r   r  r   r9   r9   r:   numpy_take_1'  s   r  c                    s<   |j d jdk  fdd}| ||||}t| ||j|S )Nr<   r  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   r<   r  )
r  r  r   rk   r  r  r  r  r  rU   )rY  r   r  walkeritr]   r  r  F_orderr9   r:   r  :  s   


znumpy_take_2.<locals>.take_implr  r  r9   r  r:   numpy_take_24  s   r  c                 C   r  )Nc                 S   s~   t |}t j|j| jd}t |}d}|  }|D ]}|| jd ks*|| j k r.td|| ||< |d }q||j	S r  )
r  r   r  r   rk   r  r  r  r  rU   )rY  r   convertr  r  r]   r  r  r9   r9   r:   r  T  s   


znumpy_take_3.<locals>.take_implr  r  r9   r9   r:   numpy_take_3N  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 r9   r  rX  r9   r9   r:   r   f  r  z!_arange_dtype.<locals>.<listcomp>c                 s   r  r  r   r   ComplexrX  r9   r9   r:   r  h  r  z _arange_dtype.<locals>.<genexpr>c                 s   r  r  )r   r   FloatrX  r9   r9   r:   r  j  r  zint%sr  c                 S   s   g | ]}t |qS r9   )r   	unliteralr   r  r9   r9   r:   r   y      )
r  r   
complex128r   r;  r  rk   r   r   r  )r   boundsrk   NPY_TYunliteral_boundsr9   r9   r:   _arange_dtypee  s   r  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   s   g | ]}t |tjqS r9   r  r  r9   r9   r:   r         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 )Nr<   r   zMaximum allowed size exceededT)r   r   mathceilrp  rw  r  r  r  r  r.   )r   rx  rq  rk   	lit_startlit_stoplit_step_step_start_stopnitems_cnitems_rnitems_ir   r  rw   r]   start_value
step_value
stop_value
true_dtypeuse_complexr9   r:   r
    s(   

znp_arange.<locals>.implr  )r   r   Optionalr/   r  r'  r  r  r  rk   r  r;  )r   rx  rq  rk   r
  r9   r  r:   	np_arange  s>   r  c                 C   r  )Nc                 S   s   t | |dS )Nry  )r  rz  )r   rx  r9   r9   r:   rz    r  z"numpy_linspace_2.<locals>.linspacer  rm   r3   rL   r   rz  r   r9   r9   r:   numpy_linspace_2  s   r  c                    s8   t |jj  fdd}| ||||}t| ||j|S )Nc                    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   r<   rw  )r  r  divider.   )r   rx  r|  r  divdeltarq  r]   r  r9   r:   rz    s    z"numpy_linspace_3.<locals>.linspace)r   r   rk   r]  r   r  r9   r  r:   numpy_linspace_3  s   r  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  r<   rp   N)r   ri   r
   r   rU   r   r  r   r  
raw_memcpyr   r   r   r   r   r{   r  r  r   r4   r   r   )rm   r3   rL   r   r  r   r   rettyper  r  r3  r  r2  r   r   r  r  r9   r9   r:   _array_copy  s6   


	r  z
array.copyc                 C   r  r  r  rJ  r9   r9   r:   
array_copy  r  r  c                 C   r  r  r  rJ  r9   r9   r:   
numpy_copy  r  r  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 layoutr<   r   r  r  r  r   N)r   r   r  r`   ri   r  r   r  r{   r  r   r   r   r   r   r   r   r   r   rj  r  blockr  phir/   add_incoming)rm   r3   rL   r   output_layoutr  r   r   r  rU   r   
check_funcrP  thenorelseout_thenthen_blk
out_orelse
orelse_blkret_phir9   r9   r:   _as_layout_array  sf   


r$  c                 C      t | |||ddS )Nr  r  r$  rJ  r9   r9   r:   array_asfortranarray]     r(  c                 C   r%  )Nr   r&  r'  rJ  r9   r9   r:   array_ascontiguousarrayb  r)  r*  c                 C   "   t | tjtjfrdd }|S dS )z^
    This is an implementation for scalar.
    For arrays, see `array_ascontiguousarray`.
    c                 S      t t | S r  )r  ascontiguousarrayr   r  r9   r9   r:   r
  n  rs  z,array_ascontiguousarray_scalar.<locals>.implNr   r   r'  r{  r
  r9   r9   r:   array_ascontiguousarray_scalarg     r/  c                 C   r+  )z[
    This is an implementation for scalar.
    For arrays, see `array_asfortranarray`.
    c                 S   r,  r  )r  asfortranarrayr   r  r9   r9   r:   r
  z  rs  z)array_asfortranarray_scalar.<locals>.implNr.  r
  r9   r9   r:   array_asfortranarray_scalars  r0  r2  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 rM  )r   ri   r
   r   rU   r   r  r   r   r   r   r{   r  r  r  ru   rz   rk   rx   r   r   )rm   r3   rL   r   r  r   r   r  r  r  r3  r  r2  r   r   r  r  itemr9   r9   r:   array_astype  s0   


r4  c              	   C   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   ri   r   ro   r   r   r/   r   r   sremr
   is_not_nullr   r'  r(  r   rZ   sdivr  r   r   r   r   r   r   r   r   )rm   r3   rL   r   buftyr   r  
out_ary_tyout_aryout_datamodelr   ll_itemsizerM  remis_incompatibler   rU   r   r   r   r9   r9   r:   np_frombuffer  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(...).
    NrZ  r  c                    r@  r9   rA  )r   rb  r   r   r9   r:   r     rB  znp_cfarray.<locals>.<listcomp>r  rV  )r   r   r  ri   ro   r
   r   r   r   r  r   r   rY   r   r  rA  r  rj   rk   r\  r   r   r   )rm   r3   rL   r   r  rE  r[   rU   r   r:  r   r<  r   offr   r   r   r   r9   r   r:   
np_cfarray  sJ   	




	rA  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   r{   r   r0  rB   r    )rm   r3   seqtyseqr=  r9   r9   r:   _get_seq_size  s   rD  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   decref)r3   r   r  rm   r-  r  r9   r:   wrap  s   
z$_get_borrowing_getitem.<locals>.wrap)rk   rB   r+  r,  r    r   r{   )rm   rB  rG  r9   rF  r:   _get_borrowing_getitem	  s   rH  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   rH  rk   )rB  rC  r-  r3   rm   r   r9   r:   get_first_item!  s   
z.compute_sequence_shape.<locals>.get_first_item)r   r   r{   r   r.   rY   rD  r   )rm   r3   r`   rB  rC  r   rK  r   innertyinnerr]   r9   rJ  r:   compute_sequence_shape  s   

rN  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   r9   r   r9   r:   _fail=  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%  r<   )r   rD  r   r   r   r   r0  rH  r
   rd  rk   r   r  r.   r   )rB  rC  r   r   expectedr  r-  rf  rL  rM  r]   rO  r3   check_seq_sizerm   r9   r:   rR  A  s0   
"z,check_sequence_shape.<locals>.check_seq_sizeNr9   )rm   r3   rB  rC  r   r9   rQ  r:   check_sequence_shape8  s   rS  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  rz   rk   rx   )r   r  rw   r[   )r  r3   rm   r   r   r   r9   r:   assign_itemh  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   r0  r  rH  r
   rd  rk   r   r.   r   r   r{   )rB  rC  r   r   r   r-  rf  rL  rM  r]   r   )assignrT  r3   rm   r9   r:   rU  n  s(   
 "z(assign_sequence_to_array.<locals>.assignr9   Nr9   )rm   r3   r   r   r   r  rB  rC  r9   )r  rU  rT  r3   rm   r   r   r   r:   assign_sequence_to_arraya  s   rV  c           
   	   C   s   |j }|j}|jd }|d }t| ||||}t||ksJ t| |||| t| |||}	t| ||	j||	j	||| t
| ||j |	 S r   )r   r`   r   rN  r   rS  r  rV  r   r   r   r   )
rm   r3   rL   r   r  r`   rB  rC  r   r  r9   r9   r:   np_array  s   
rW  c           
      C   s   | d}| |}|d||}||||||}||d|||d||}|j|dd d| }	| j|t|	f W d    |S 1 sLw   Y  |S )Nr   r   rL  Fr%  z%s(): axis out of bounds)	r/   r   rw  r[  r  r   r'  r(  r  )
rm   r3   	func_namer`   rM  r   ll_ndimis_neg_axisaxis_out_of_boundsr   r9   r9   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).
    r<   rL  r   r   r   r[  r
   r   rH   r.   r   rw  r[  r   rX   r   r4   )rm   r3   
orig_shaper`   rM  ll_shtyr   r  r<  ll_dim
after_axisr  r   r9   r9   r:   _insert_axis_in_shape  s   


rb  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.
    r<   r   rL  r]  )rm   r3   orig_stridesr`   rM  r_  r   r  r   r<  r`  ra  r   r9   r9   r:   _insert_axis_in_strides  s"   




rd  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   ri   r
   r   rU   r   rb  rd  r   r   r   r   r   r   )rm   r3   rL   r   rM  r  r`   r  r  r  r   r   
new_shapesnew_stridesr9   r9   r:   expand_dims  s$   
rg  c                 C   sP   |  ||d |jd tj}t| |d|jj|}t| ||||}t| ||j|S )Nr<   znp.expand_dims)	rz   r   r   r{   r\  r   r`   rg  r   )rm   r3   rL   r   rM  r  r9   r9   r:   np_expand_dims  s   rh  c           
         s   |j }|}t|jtjrt|j}n|jg}t|t|ks J  fddt|||D }t|jtjr? |j|}	n|d }	t	 |j|	S )Nc                    s"   g | ]\}}} |||qS r9   r9   )r   r  r  r  r3   rm   	transformr9   r:   r     s    z_atleast_nd.<locals>.<listcomp>r   )
r   r   r   r   r  r   r   r   r  r   )
rm   r3   rL   r   rj  r	  arrsr!  retsr  r9   ri  r:   _atleast_nd  s   
rm  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 )Nr<   r,  )r.   r`   r
   r   r  rg  r   r    )	rm   r3   r  r  r  r]   r`   rM  newarrtyrq  min_ndimr9   r:   rj  ,  s   
z(_atleast_nd_transform.<locals>.transform)r   )rp  rq  rj  r9   ro  r:   _atleast_nd_transform%  s   rq  c                 C   s   t ddg}t| ||||S rb  rq  rm  rm   r3   rL   r   rj  r9   r9   r:   np_atleast_1d<  s   rt  c                 C   s   t dddg}t| ||||S )NrZ  r   rr  rs  r9   r9   r:   np_atleast_2dC     ru  c                 C   s   t dg d}t| ||||S )Nr  )r   r   rZ  rr  rs  r9   r9   r:   np_atleast_3dJ  rv  rw  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   r/   r   rw  r[  rY   r   r  r  r  ru   rz   rk   rx   r   )rm   r3   rM  r	  rk  
arr_shapesarr_stridesr  
ret_shapesr   r  ret_stridescopy_offsetsarr_shr   r<  r   r  is_axisaddendret_datar  r  arr_starr_datar  r   r  rw   r  r9   r9   r:   _do_concatenateQ  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   rT  r   r  rY  r   r9   r:   r     rB  z#_np_concatenate.<locals>.<listcomp>znp.concatenatec                       g | ]	}t  |jqS r9   )r
   r   rU   r   r  r  r9   r:   r     r  c                    r  r9   r
   r   r   r  r  r9   r:   r     r  c                    s   g | ]}t  |qS r9   )r
   r   r  r  r9   r:   r     r  r   r  c                    s   g | ]}|  qS r9   r9   r  )r<  r9   r:   r     r  r<   Fr%  z<np.concatenate(): input sizes over dimension %d do not matchc                    s   g | ]}  |qS r9   )r4   r  r  r9   r:   r     r  )r`   r   r\  r.   r   r/   r4   r  r  r  r[  r   r
   r  r  r   rk  r'  r(  r   r  r   r   )rm   r3   r	  rk  r  rM  r`   ry  rz  r{  r  ret_shape_ptrret_shother_shapeson_axison_other_dimr  is_okr  r9   )r3   rm   r<  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   r<   c                    r  r  rT  r  r   r9   r:   r     rB  z_np_stack.<locals>.<listcomp>znp.stackr  Fr%  )z5np.stack(): all input arrays must have the same shapec                    r  r9   r  r  r  r9   r:   r     r  rL  c                    rO  r9   rP  r  )r3   r_  r9   r:   r     r  c                    s   g | ]}t   |qS r9   )r
   r   r4   )r   r  r  r9   r:   r     rY  )r`   r
   r   r   r   r\  r   rU   r  r  r   r   rk  r'  r(  r   r   r[  rH   r.   rw  r[  r   rX   r4   r  r   r   )rm   r3   r	  rk  r  rM  r`   r   r  
ll_narraysr^  r  r  r  orig_shrc  input_shapesr{  r<  r`  ra  r   input_stridesr]   r  r9   )r3   rm   r_  r:   	_np_stack  s   








r  c              	   C   s8   |  tjd}t| |t|jd t||d |j|S r   )	r   r   r{   r  r   r   r
   r   r   rm   r3   rL   r   rM  r9   r9   r:   np_concatenate  s   r  c              	   C   sF   |  ||d |jd tj}t| |t|jd t||d |j|S rb  )	rz   r   r   r{   r  r   r
   r   r   r  r9   r9   r:   np_concatenate_axis#  s   r  c                 C   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   r<   rZ  r,  )r   r   r
   r   r   r   r{   r   r`   rY   r  r   r    rg  r  r   )rm   r3   rL   r   orig_arrtys	orig_arrsr	  rk  rM  r  r  r  
expand_signewarrr9   r9   r:   np_column_stack-  s$   



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  r9   r9   r:   _np_stack_commonI  s   r  c                 C   s   |  tjd}t| ||||S r   )r   r   r{   r  r  r9   r9   r:   np_stackT  s   r  c                 C   s,   |  ||d |jd tj}t| ||||S rW  )rz   r   r   r{   r  r  r9   r9   r:   np_stack_axisZ  s   r  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   r<   c                    s   t j|  dS r  r  r  r  r9   r:   np_hstack_impln  r  z!np_hstack.<locals>.np_hstack_implr   r`   r   r   r{   r  r]  )rm   r3   rL   r   r  r`   r  r9   r  r:   	np_hstack`  s   

r  c                 C   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 rW  )r  rg  hstackr  r9   r9   r:   np_vstack_implz  r  z!np_vstack.<locals>.np_vstack_implr<   c                 S   r  )Nr   r  r  r  r9   r9   r:   r    r  r  )rm   r3   rL   r   r  r`   r  rM  r9   r9   r:   	np_vstackt  s   


r  c                 C   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 )Nr<   rw  )r  r  r  r  r9   r9   r:   r    r  z!np_dstack.<locals>.np_vstack_implr<   r,  rZ  c                 S   r  )NrZ  r  r  r  r9   r9   r:   r    r  )r   r   r`   r]  r   r   r{   r  r   r    r  rg  )rm   r3   rL   r   r  r  r`   r  rM  stack_retty	stack_sig	stack_retr  r9   r9   r:   	np_dstack  s&   

r  fillc                 C   r  )Nc                 S   s   || d d < d S r  r9   )r  rw   r9   r9   r:   	fill_impl  s   zarr_fill.<locals>.fill_implr9   )r  rw   r  r9   r9   r:   arr_fill  s   r  dotc                 C   r  )Nc                 S   r"  r  )r  r  )r  otherr9   r9   r:   dot_impl  rX  zarray_dot.<locals>.dot_implr9   )r  r  r  r9   r9   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 )NrZ  r  rw  .r  r  r`   r   rY  r  r9   r9   r:   r
    s   

znp_flip_lr.<locals>.implr	  r
  r9   r9   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 )Nr<   zInput must be >= 1-d.rw  .r  r  r9   r9   r:   r
    s   

znp_flip_ud.<locals>.implr	  r
  r9   r9   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` rC  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 )Nrw  )r.   r(   r  )lengthempty_tupler   r]   r9   r9   r:   r
    s   z6_build_flip_slice_tuple.<locals>.codegen.<locals>.impl)r   r{   r   r    r   get_constant_undefr]  )rm   r3   r    r   r
  inner_argtypes	inner_sigll_idx_typer  
inner_argsr   r   
tuple_typer9   r:   r    s   

z(_build_flip_slice_tuple.<locals>.codegen)	r   r   IntegerLiteralr	   RequireLiteralValuer   r  r  slice3_type)r*  szrL   r  r9   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`   )rY  slr9   r9   r:   r
    s   
znp_flip.<locals>.impl)r   r   r   r	   r  r
  r9   r9   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_sectionsrM  r9   r9   r:   r
    s
   znp_array_split.<locals>.implc                 S   sP   t | j| |\}}tt|d g| |g|| d   }tj| ||dS )Nr<   r  )divmodrU   r  cumsumr   r  )r   r  rM  r  r=  r   r9   r9   r:   r
    s   c              	   S   sb   t | j}t }d}|D ]}t||t||}|| |  |}q|| t||t|d   |S r   )r)   r`   r   r(   r  rY   r   r  rM  	slice_tupr   prevr  r   r9   r9   r:   r
  *  s   
c                 s   r  r  r   r   r   )r   tr9   r9   r:   r  9  r  z!np_array_split.<locals>.<genexpr>c              	   S   sf   t | j}t }d}t|D ]}t||t||}|| |  |}q|| t||t|d   |S r   )r)   r`   r   r   r(   r  rY   r  r9   r9   r:   r
  ;  s   
r$  )r   r   r  ListTyper  r   IterableTypeiterator_typer   r  r   r   r  rM  r
  r9   r9   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  r9   r9   r:   r
  N  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  rM  r  r=  r9   r9   r:   r
  T  s   r  r$  )r   r   r  r  r  r   r  r  r9   r9   r:   np_splitI  s   


r  c                 C   s   t |p| |k S r  )r  isnanr  r9   r9   r:   	lt_floatsj  r  r  Fc                 C   s   | ||f}zt | W S  ty?   | dkr%tj|rtnd|dd}|j}n| dkr7tj|r/tnd|d}|j}|t |< | Y S w )z6
    Get a sort implementation of the given kind.
    r%   NT)lt
is_argsortis_np_arrayr&   )r  r  )	_sortsKeyErrorr%   make_jit_quicksortr  run_quicksortr&   make_jit_mergesortrun_mergesort)r  is_floatr  keyr  funcr9   r9   r:   get_sort_funcn  s(   



r  z
array.sortc                    s<   |j d }tdt|jtjd  fdd}| ||||S )Nr   r%   )r  r  c                    s    |  d S r  r9   r  	sort_funcr9   r:   array_sort_impl  r  z#array_sort.<locals>.array_sort_impl)r   r  r   rk   r   r  r]  )rm   r3   rL   r   r  r  r9   r  r:   
array_sort  s   
r  c                 C   r  )Nc                 S   s   |   }|  |S r  )r  r  )rY  r   r9   r9   r:   np_sort_impl  s   znp_sort.<locals>.np_sort_implr  )rm   r3   rL   r   r  r9   r9   r:   np_sort  s   r  zarray.argsortc           	         sb   |j \}}t|jt|jtjdd  fdd}|j|j d d d}|d d }| ||||S )NT)r  r  r  c                    s    | S r  r9   r  r  r9   r:   array_argsort_impl  rG  z)array_argsort.<locals>.array_argsort_implr<   r  )	r   r  r  r   rk   r   r  replacer]  )	rm   r3   rL   r   r  r  r  innersig	innerargsr9   r  r:   array_argsort  s   
r  c                 C   s   |j |j ks|jdksJ |S )Nr  )rY  r  )rm   r3   rb  rc  rw   r9   r9   r:   array_to_array  s   r  c                 C   4   dd }t ||}| ||||g}t| ||j|S )Nc                 S   s
   |  dS r   )taker  r9   r9   r:   r
    s   
zarray0d_to_scalar.<locals>.impl)r    r]  r   r   rm   r3   rb  rc  rw   r
  rL   r   r9   r9   r:   array0d_to_scalar  s   
r  c                 C   r  )Nc                 S   s   t | d S rZ  )r  r  r9   r9   r:   r
    rX  z array_to_unichrseq.<locals>.impl)r    r]  r   r   r  r9   r9   r:   array_to_unichrseq  s   
r  c                 C   r.  )zR
    An intrinsic returning a derived array with the given shape and strides.
    r/  rY  rU   r   r9   r9   r:   reshape_unchecked  r4  r  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  r9   r9   r:   r    r  z>type_reshape_unchecked.<locals>.check_shape.<locals>.<genexpr>)r   r   r  r   rU   r9   r9   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  r  r  r9   r:   typer  s   z%type_reshape_unchecked.<locals>.typerr9   )rm   r   r9   r  r:   type_reshape_unchecked  s   	r  c                 C   s   |j d }|j}t|| ||d }t|| |}t||d }t||d }	t||j||	|j|jd |	 }
t
| |||
S )Nr   r<   rZ  rV  )r   r   ri   r
   r   r   r   r   r   r   r   )rm   r3   rL   r   r   r  r   r   rU   r   r   r9   r9   r:   impl_shape_unchecked  s   
r  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   rC  r  r  r  rU   r9   r9   r:   r5    s   zas_strided.<locals>.get_shapec                 S   r  r  r9   r  r9   r9   r:   r5       z*as_strided() strides argument is mandatoryc                 S   r  r  r9   )r  r   r9   r9   r:   get_strides  r  zas_strided.<locals>.get_stridesc                    s   t |  | || |} | S r  )r  )r  rU   r   r5  r  r9   r:   as_strided_impl  s   z#as_strided.<locals>.as_strided_implrI  )r   r  r!   rC   )r  rU   r   r  r9   r  r:   
as_strided  s   

r  c                 C   s   t | tjrdd }|S d S )Nc                 S   s2   | j dkrdS | j dkrt| dS d}t|)Nr   Fr<   z[The truth value of an array with more than one element is ambiguous. Use a.any() or a.all())r   r  r  r   )r  r   r9   r9   r:   r
  %  s   

zol_bool.<locals>.implr  r  r9   r9   r:   ol_bool"  s   	r	  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 integerr  c                    s|   |ks
t |krtd|kst |krtd|dk r$|7 }|dk r,|7 }t ||}t|||}t| |S )NzIThe second argument "axis1" is out of bounds for array of given dimensionzHThe third argument "axis2" is out of bounds for array of given dimensionr   )rL  r   r(   r  ro  )r  axis1axis2
axes_tuple	axes_listr`   r9   r:   r
  @  s   znumpy_swapaxes.<locals>.impl)
r   r   r   r   r	   r  r   r`   r   r.   )r  r
  r  r
  r9   r  r:   numpy_swapaxes1  s   


r  c                 C   s  |dk r	| j | }t| j}d||< tt||jD ]$\}\}}	|dkr'|	}
n|	dkr.|}
n
||	kr6td|}
t|||
}qt||| j| }t| |} t||}|}t	|dkrnt
t	|D ]}t||| j| }qb|}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 )Nr   r<   z*`arr` and `indices` dimensions don't match)r`   r   rU   r  r   r   r(   r  r  r   r.   r  rk   r  r  )r  r   rM  Ni_origNk_origindices_broadcast_shape	arr_shaper]   d1d2new_valarr_broadcast_shapeNiNkJr   np_s_iikka_1d
indices_1dout_1djr9   r9   r:   _take_along_axis_implU  sV   


r"  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 )Nr  z.The second argument "indices" must be an arrayz'The indices array must contain integersr<   z;`indices` and `arr` must have the same number of dimensionsc                    s   t |  |ddd S )Nr   r9   )r"  r  r  r   rM  )r  r9   r:   take_along_axis_impl  s   z1arr_take_along_axis.<locals>.take_along_axis_implrM  zaxis must be a literal valuer   zaxis is out of boundsc                    s   t | || S r  )r"  r#  r  r  r  r9   r:   r$    s   )r   r   r   r	   r  rk   r   r   r`   r   r.   r   r  r  r  )r  r   rM  arr_ndimr$  r9   r%  r:   arr_take_along_axis  s>   






r'  r  r}  r  r  r$  )FrI  (  r9  r  r  r+  llvmliter   llvmlite.irr   numpyr  numbar   r   
numba.corer   r   r   r	   r
   r   numba.np.numpy_supportr   r   r   r   r   r   r   r   r   numba.core.imputilsr   r   r   r   r   r   r   r   r   r   r   numba.core.typingr    numba.core.extendingr!   r"   r#   r$   
numba.miscr%   r&   numba.cpythonr'   numba.cpython.unsafe.tupler(   r)   numba.core.overload_gluer*   r+   numba.core.typing.npydeclr,   r  r-   r  r;   r>   ri   ro   ru   rx   r   r   r   r   r   r   r   r   ArrayIteratorBORROWEDr   r  r   r  r,  r   r   r  r  r  r8  Anyr  r   r#  r   r)  r+  r(  r-  r;  rT  r]  ra  rn  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  broadcast_shapesr  r*  r  rH  rK  rN  rh  VarArgrk  ro  ru  rI  logspacer~  rot90r  r  r  r  r  r  r  rY   r  r  r  r  r  r  r  r  r  r  r  rU   r  uniquer  r!  r   r  r$  r+  r,  r8  r  rA  rC  
MemoryViewrF  rH  rJ  rK  rL  rN  rQ  rU  rX  rZ  r_  r\  ra  CPointerrb  rd  rj  rm  rk  rn  ro  rv  rz  rt  r  r  DTyper  StringLiteralr  r  r  r  r  r  r  r  r  r  r  Bytesr  is_r  r  r  r  r  r)  r0  r  rI  rE  rK  rN  rO  rP  r  rS  rQ  rT  r  rW  rZ  rV  r[  r  r\  NumpyNdIterTyper]  r  ru  rd  rs  r  r  rx  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  eyer  r  r  r  r  r  r  r  r  r  aranger  rz  r'  r  r  r  r  r  r  r$  r1  r(  r-  r*  r/  r2  r4  
frombufferr?  rA  rD  rH  rN  rS  rV  r   rW  r\  rb  rd  rg  rh  rm  rq  
atleast_1drt  
atleast_2dru  
atleast_3drw  r  r  r  r  r  r  column_stackr  r  stackr  r  r  r  vstackr  dstackr  r  r  r  r  r  r  r  flipr  r  r  r  r  r  r  r  r  r  r  argsortr  r  UnicodeCharSeqr  r  r{  NPTimedelta
NPDatetimer  r  r  type_callabler  r  libstride_tricksr  r  r	  r  r  r"  take_along_axisr'  r9   r9   r9   r:   <module>   s     4<	E


>


(




22=QEz+
*>%




(
9}


6


$
@








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























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





)
C	%A

&4
))	=2Y		"	




<


#
<