U
    hâËdµ  ã                	   @   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 ddlmZmZmZmZmZmZmZ ddlmZmZmZ dd	lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) dd
l*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl.m<Z< ddl=m>Z?m@ZAmBZBmCZCmDZD dd„ ZEdd„ ZFdd„ ZGdd„ ZHdd„ ZIdd„ ZJdd„ ZKd d!„ ZLd"d#„ ZM�d4d$d%„ZNd&d'„ ZOd(d)„ ZPe0ePƒd*d+„ ƒZQed,ejRƒd-d.„ ƒZSd/d0„ ZTed1ejUƒe%e)jVƒd2d3„ ƒƒZW�d5d4d5„ZXd6d7„ ZYd8d9„ ZZeej[ejRej\ƒeej[ejRej]ƒd:d;„ ƒƒZ^eej[ejRej_ƒd<d=„ ƒZ`eejaejRejbejbƒd>d?„ ƒZceedejRƒd@dA„ ƒZeedBejfƒdCdD„ ƒZgedEejfejbƒdFdG„ ƒZhG dHdI„ dIeiƒZjG dJdK„ dKejƒZkG dLdM„ dMejƒZlG dNdO„ dOejƒZmG dPdQ„ dQejƒZnG dRdS„ dSejƒZoG dTdU„ dUeiƒZpdVdW„ Zqeej[ejRejfƒdXdY„ ƒZrdZd[„ Zsd\d]„ Ztd^d_„ Zud`da„ Zvdbdc„ Zwddde„ Zxdfdg„ Zydhdi„ Zze2djdk„ ƒZ{e2dldm„ ƒZ|e/dndo„ ƒZ}dpdq„ Z~e0e	jƒdrds„ ƒZ€e/dtdu„ ƒZ�e0e	j‚ƒdvdw„ ƒZƒe0e	j„ƒdxdy„ ƒZ…dzd{„ Z†d|d}„ Z‡ed~ejfƒdd€„ ƒZˆd�d‚„ Z‰ed~ejfej_ƒdƒd„„ ƒZŠed~ejfe ‹ejb¡ƒd…d†„ ƒZŒe0e	j�ƒ�d6d‡dˆ„ƒZŽe ejfd‰ƒdŠd‹„ ƒZ�e0e	j�ƒ�d7d�dŽ„ƒZ‘e0e	j’ƒ�d8d�d‘„ƒZ“d’d“„ Z”d”d•„ Z•ed–ejfej_ƒd—d˜„ ƒZ–ed–ejfe ‹ejb¡ƒd™dš„ ƒZ—e0e	j˜ƒd›dœ„ ƒZ™e0e	jšƒ�d9d�dž„ƒZ›edŸejfƒd d¡„ ƒZœee	j�ejfƒd¢d£„ ƒZžed¤ejfƒd¥d¦„ ƒZŸe/d§d¨„ ƒZ e/d©dª„ ƒZ¡e0e	j¢ƒ�d:d«d¬„ƒZ£e1ejfd­ƒ�d;d®d¯„ƒZ¤d°d±„ Z¥e0e	j¦ƒd²d³„ ƒZ§e0e	j¨ƒd´dµ„ ƒZ©e0e	jªƒd¶d·„ ƒZ«e/d¸d¹„ ƒZ¬e 1ejfdº¡d»d¼„ ƒZ­e2d½d¾„ ƒZ®d¿dÀ„ Z¯e0e¯dÁdÂ�dÃdÄ„ ƒZ°edÅejfej±ƒdÆdÇ„ ƒZ²e ejfdÈƒdÉdÊ„ ƒZ³e ejfdËƒe ej´dËƒdÌdÍ„ ƒƒZµe ejfdÎƒe ej´dÎƒdÏdÐ„ ƒƒZ¶e ejfdÑƒe ej´dÑƒdÒdÓ„ ƒƒZ·e ejfdÔƒdÕdÖ„ ƒZ¸e ejfd×ƒe ej´d×ƒdØdÙ„ ƒƒZ¹e ejfdÚƒe ej´dÚƒdÛdÜ„ ƒƒZºe ej´dÝƒdÞdß„ ƒZ»e ej´dàƒdádâ„ ƒZ¼e ej´dãƒdädå„ ƒZ½e ej´dæƒdçdè„ ƒZ¾e ejfdéƒdêdë„ ƒZ¿e ejÀdìƒdídî„ ƒZÁe#ejÀejÂƒe#ejÀejÃƒdïdð„ ƒƒZÄdñdò„ ZÅe ejfdóƒdôdõ„ ƒZÆe ejÇdÝƒe ejÇdàƒdöd÷„ ƒƒZÈe ejÇdãƒdødù„ ƒZÉe ejfdúƒdûdü„ ƒZÊe ejfdýƒdþdÿ„ ƒZË�d �d„ ZÌe1ejf�dƒe1ejf�dƒ�d�d„ ƒƒZÍ�d�d„ ZÎe ejÏ�dƒeÎƒ e ejÏ�d	ƒeÎƒ e�d
ejÐejbƒ�d�d„ ƒZÑe!ejfƒ�d�d„ ƒZÒe�d
ejfej-ƒ�d�d„ ƒZÓe!ejÔƒ�d�d„ ƒZÕe"ejÔƒ�d�d„ ƒZÖe�d
ejÔej-ƒ�d�d„ ƒZ×e�d
ejÔejØƒ�d�d„ ƒZÙe�dejÔej-ejbƒ�d�d„ ƒZÚe�dejÔejØejbƒ�d�d„ ƒZÛe$ejfƒ�d�d„ ƒZÜe$ejÔƒ�d �d!„ ƒZÝe$ejÞƒ�d"�d#„ ƒZßeejàejfejfƒ�d$�d%„ ƒZáe3ejf�d&ƒ�d'�d(„ ƒZâ�d)�d*„ Zã�d+�d,„ Zä�d<�d-�d.„Zå�d=�d/�d0„Zæ�d1�d2„ Zç�d3�d4„ Zè�d5�d6„ Zée ejf�d7ƒ�d8�d9„ ƒZêed1ejëƒe%e)jVƒ�d:�d;„ ƒƒZìeej[ejëej\ƒ�d<�d=„ ƒZíeejaejëej\ejbƒ�d>�d?„ ƒZîeedejëƒ�d@�dA„ ƒZïee	jðejfƒ�dB�dC„ ƒZñed1ejòƒe%e)jVƒ�dD�dE„ ƒƒZóeee ‹ej\¡ƒee	jôe ‹ej\¡ƒ�dF�dG„ ƒƒZõeeej_ƒee	jôej_ƒ�dH�dI„ ƒƒZöed1ej÷ƒe%e)jVƒ�dJ�dK„ ƒƒZøee	jùejbƒ�dL�dM„ ƒZúed1ejûƒe%e)jVƒ�dN�dO„ ƒƒZü�dP�dQ„ Zýe<ejf�dRƒ�dS�dT„ ƒZþ�dU�dV„ Zÿe2�dW�dX„ ƒ�Z �dY�dZ„ �Z�d[�d\„ �Z�d]�d^„ �Z�d_�d`„ �Ze2�da�db„ ƒ�Ze0e	�jƒ�ef�dc�dd„ƒ�Ze2�de�df„ ƒ�Z	e0e	�j
ƒ�d>�dg�dh„ƒ�Ze2�di�dj„ ƒ�Ze1ejf�dkƒ�dl�dm„ ƒ�Ze0e	�jƒ�ef�dn�do„ƒ�Ze0e	�jƒ�d?�dp�dq„ƒ�Ze0e	�jƒ�d@�dr�ds„ƒ�Ze0e	�jƒ�dA�dt�du„ƒ�Ze0e	�jƒ�dB�dv�dw„ƒ�Ze0e	�jƒ�dC�dx�dy„ƒ�Ze0e	�jƒ�dD�dz�d{„ƒ�Z�d|�d}„ �Ze 0�e¡�d~�d„ ƒ�Ze 0e	�j¡dd�ef�d€�d�„ƒ�Ze0e	�j ƒ�dE�d‚�dƒ„ƒ�Z!e0e	�j"ƒe1ejf�d„ƒ�d…�d†„ ƒƒ�Z#�d‡�dˆ„ �Z$e0e	�j%ƒ�dF�d‰�dŠ„ƒ�Z&e0e	�j'ƒ�dG�d‹�dŒ„ƒ�Z(�d��dŽ„ �Z)e2�d��d�„ ƒ�Z*e�d‘ejfƒ�d’�d“„ ƒ�Z+e0e	�j,ƒ�d”�d•„ ƒ�Z-�d–�d—„ �Z.e2�d˜�d™„ ƒ�Z/e0e	�j0ƒ�dš�d›„ ƒ�Z1e0e	�j2ƒ�dœ�d�„ ƒ�Z3e�džejfej±ƒe�džejfej-ƒ�dŸ�d „ ƒƒ�Z4e2�d¡�d¢„ ƒ�Z5e0e	�j6ƒ�ef�d£�d¤„ƒ�Z7e0eƒ�dH�d¥�d¦„ƒ�Z8e0eƒ�dI�d§�d¨„ƒ�Z9�d©�dª„ �Z:�d«�d¬„ �Z;�d­�d®„ �Z<�d¯�d°„ �Z=�d±�d²„ �Z>�d³�d´„ �Z?�dµ�d¶„ �Z@�d·�d¸„ �ZAe2�d¹�dº„ ƒ�ZBe0e	�jCƒ�dJ�d»�d¼„ƒ�ZD�d½�d¾„ �ZE�d¿�dÀ„ �ZF�dÁ�dÂ„ �ZG�dÃ�dÄ„ �ZHe2�dÅ�dÆ„ ƒ�ZIe0e	�jHƒ�dÇ�dÈ„ ƒ�ZJ�dÉ�dÊ„ �ZK�dË�dÌ„ �ZLe0e	�jMƒ�dÍ�dÎ„ ƒ�ZNe0e	�jOƒ�dÏ�dÐ„ ƒ�ZPe0e	�jQƒ�dÑ�dÒ„ ƒ�ZR�dÓ�dÔ„ �ZS�dÕ�dÖ„ �ZT�d×�dØ„ �ZU�dÙ�dÚ„ �ZVe2�dÛ�dÜ„ ƒ�ZWe0e	�jXƒ�dK�dÝ�dÞ„ƒ�ZY�dß�dà„ �ZZe2�dá�dâ„ ƒ�Z[e0e	�j\ƒ�dã�dä„ ƒ�Z]�då�dæ„ �Z^e2�dç�dè„ ƒ�Z_e0e	�j`ƒ�dL�dé�dê„ƒ�Za�dë�dì„ �Zbe2�dí�dî„ ƒ�Zce0e	�jdƒ�dï�dð„ ƒ�Zee2�dñ�dò„ ƒ�Zfe0e	�jgƒ�dó�dô„ ƒ�Zhe2�dõ�dö„ ƒ�Zie0e	�jjƒ�d÷�dø„ ƒ�Zke 1ejf�dù¡�dú�dû„ ƒ�Zle 1ejf�dü¡�dý�dþ„ ƒ�Zme0e	�jnƒ�dÿ�d „ ƒ�Zoe0e	�jpƒ�d�d„ ƒ�Zqe2�d�d„ ƒ�Zre0e	�jsƒ�d�d„ ƒ�Zte0e	�juƒ�dM�d�d„ƒ�Zve0e	�jwƒ�dN�d	�d
„ƒ�Zxi �Zy�d�d„ �Zz�dO�d�d„�Z{e�dejfƒ�d�d„ ƒ�Z|e0e	�j}ƒ�d�d„ ƒ�Z~e�dejfej-ƒee	�jejfej-ƒ�d�d„ ƒƒ�Z€e#ejfejfƒ�d�d„ ƒ�Z�e#ejfe�j‚ƒe#ejfe�jƒƒe#ejfej\ƒe#ejfe�j„ƒe#ejfe�j…ƒe#ejfe�j†ƒe#ejfe�j‡ƒ�d�d„ ƒƒƒƒƒƒƒ�Zˆe#ejfe�j‚ƒ�d�d„ ƒ�Z‰�d�d„ �ZŠe� ‹�eŠ¡�d �d!„ ƒ�ZŒe�eŠejfej_ej_ƒ�d"�d#„ ƒ�Z�e 0e	�jŽ�j��j�¡�dP�d$�d%„ƒ�Z�e 0e	�jŽ�j��j‘¡�dQ�d&�d'„ƒ�Z‘e0�e’ƒ�d(�d)„ ƒ�Z“e0e	�j”ƒ�d*�d+„ ƒ�Z•e/�d,�d-„ ƒ�Z–e0e	�j—ƒ�d.�d/„ ƒ�Z˜e0e	�j™ƒ�dR�d2�d3„ƒ�ZšdS (S  z[
Implementation of operations on Array objects and objects supporting
the buffer protocol.
é    N)Úir)ÚConstant)ÚpndindexÚliteral_unroll)ÚtypesÚtypingÚerrorsÚcgutilsÚ	extending)Úas_dtypeÚcarrayÚfarrayÚis_contiguousÚ
is_fortranÚcheck_is_integerÚtype_is_scalar)Útype_can_asarrayÚis_nonelikeÚnumpy_version)Úlower_builtinÚlower_getattrÚlower_getattr_genericÚlower_setattr_genericÚ
lower_castÚlower_constantÚiternext_implÚimpl_ret_borrowedÚimpl_ret_new_refÚimpl_ret_untrackedÚRefType)Ú	signature)ÚStringLiteral)Úregister_jitableÚoverloadÚoverload_methodÚ	intrinsicÚoverload_attribute)Ú	quicksortÚ	mergesort)Úslicing)Útuple_setitemÚbuild_full_slice_tuple)Úoverload_classmethod)Úparse_dtypeÚparse_shapeÚ_parse_nested_sequenceÚ_sequence_of_arraysÚ_choose_concatenation_layoutc                 C   s4   t |j|ƒt |j|ƒg}| j |¡}| d|¡ dS )zz
    Set the "range" metadata on a load instruction.
    Note the interval is in the form [lower_bound, upper_bound).
    ÚrangeN)r   ÚtypeÚmoduleZadd_metadataZset_metadata)ÚbuilderÚloadÚlower_boundÚupper_boundZrange_operandsÚmd© r:   úJ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/np/arrayobj.pyÚset_range_metadata+   s
    

ÿr<   c                 C   s&   d|j jd > d }t| |d|ƒ dS )zF
    Mark the result of a load instruction as positive (or zero).
    é   r   N)r3   Úwidthr<   )r5   r6   r8   r:   r:   r;   Úmark_positive6   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k
r@   tˆ | ƒ |¡ Y S X | jjˆ }|  |¡}|d krttj	| j
|dd�}n|}|| j
|fƒ}||fS )NZ	__array__T)Úzfill)r    Ú_contextÚget_functionÚNotImplementedErrorÚsuperÚ
_make_refsÚdata_model_managerZ_get_be_typer	   Úalloca_onceÚ_builder)ÚselfÚrefÚsigZ
array_implÚ	datamodelZbe_typeZ	outer_ref)ÚArrayStructÚ	__class__Ú
array_typeÚreal_array_typer:   r;   rE   L   s    


ÿz*make_array.<locals>.ArrayStruct._make_refsc                    sp   | j }ˆdkrˆ  | d¡S |  d¡}g }tˆƒD ]2}t ||d|¡}| |¡}| |¡ t||ƒ q0t 	||¡S )z\
            Override .shape to inform LLVM that its elements are all positive.
            r   Úshape)
rH   Ú__getattr__Ú_get_ptr_by_namer2   r	   Úgep_inboundsr6   Úappendr?   Ú
pack_array)rI   r5   ÚptrÚdimsÚiZdimptrr6   )ÚbaseÚndimr:   r;   rQ   `   s    


z%make_array.<locals>.ArrayStruct.shape)Ú__name__Ú
__module__Ú__qualname__rE   ÚpropertyrQ   Ú__classcell__r:   ©rM   rO   rZ   r[   rP   )rN   r;   rM   J   s   rM   )Zas_arrayr	   Úcreate_struct_proxyr[   )rO   r:   ra   r;   Ú
make_array>   s
    
-rc   c                 C   s   |   |j¡}|  |¡S )zB
    Return the item size for the given array or buffer type.
    )Úget_data_typeÚdtypeÚget_abi_sizeof)ÚcontextrO   Úlltyr:   r:   r;   Úget_itemsizez   s    ri   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_valuere   )rg   r5   ÚarraytyrW   rk   r:   r:   r;   Ú	load_item‚   s    ÿro   c                 C   s$   |j r
dnd}| j||j|||d�S )z4
    Store the item at the given array pointer.
    Nr=   rj   )rl   Ú
pack_valuere   )rg   r5   rn   ÚvalrW   rk   r:   r:   r;   Ú
store_item‹   s    rr   c                 C   s>   |j r(|  |||tj¡}t |||¡}n|  |||tj¡}|S )zM
    Fix the integer index' type and value for the given dimension size.
    )ÚsignedÚcastr   Úintpr)   Z	fix_indexÚuintp)rg   r5   ÚidxtyÚidxÚsizeÚindr:   r:   r;   Úfix_integer_index“   s
    r{   c                 C   s^   t |tjƒrR|jdkrRt |jtjƒs(t‚t|ƒ| ||ƒ}t| |||j	ƒ}|j|fS ||fS dS )zS
    Normalize the index type and value.  0-d arrays are converted to scalars.
    r   N)
Ú
isinstancer   ÚArrayr[   re   ÚIntegerÚAssertionErrorrc   ro   Údata)rg   r5   rw   rx   ÚidxaryZidxvalr:   r:   r;   Únormalize_indexŸ   s    
r‚   c                    s2   t |ƒr*t‡ ‡fdd„t||ƒD ƒŽ \}}||fS )z^
    Same as normalize_index(), but operating on sequences of
    index types and values.
    c                    s   g | ]\}}t ˆˆ ||ƒ‘qS r:   )r‚   )Ú.0rw   rx   ©r5   rg   r:   r;   Ú
<listcomp>²   s   þÿz%normalize_indices.<locals>.<listcomp>)ÚlenÚzip)rg   r5   Úindex_typesÚindicesr:   r„   r;   Únormalize_indices¬   s
    þrŠ   c                 C   sÌ  | j }| j}| j}	t tjdd¡}
|j|
 }t|jƒ}t|	jƒ}||@ |kr†|| }d| j	› dt
|ƒdkrndnd› d|› d�}t|ƒ‚|d	kr¤t| |	 d
¡¡d	ƒ}| tj¡}t|ttfƒrÌt |||¡}t|ttfƒrèt |||¡}t|tƒrú||ƒ}t|||||d�}|d	k�r2t| |	 d¡¡d	ƒ|d< n||d< | tjd¡}t |||jj¡}|D ]}|j||dgd�}�q^||d< t| ¡ ƒ}||k�r¨t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)rQ   Ústridesr€   Úitemsizer�   ÚparentÚnsw©ÚflagsÚnitemszmissing {0}) rA   rH   Ú
_datamodelr   r}   Úfloat64rF   ÚsetÚ_fieldsZ_fe_typer†   Ú
ValueErrorr   Úget_value_typeÚget_typeru   r|   ÚtupleÚlistr	   rV   ÚintÚdictÚget_constantÚunpack_tupler3   ÚcountÚmulÚkeysÚformatÚitemsÚsetattr)Úarrayr€   rQ   r‘   r’   r�   r“   rg   r5   rL   Zstandard_arrayZstandard_array_type_datamodelZrequired_fieldsZdatamodel_fieldsÚmissingÚmsgÚintp_tÚattrsr—   Úunpacked_shapeÚaxlenZ
got_fieldsÚkÚvr:   r:   r;   Úpopulate_array¹   s`    


*ÿÿ
ü
ÿÿ

r´   c                 C   sh   |j }|j}| tjd¡}t ||j| j¡}|D ]}|j	||dgd�}q0||_
| 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   rH   r£   r   ru   r	   r¤   rQ   r[   r¦   r—   ri   r’   )Úarytyr«   rg   r5   r—   r°   r±   r:   r:   r;   Úupdate_array_infoþ   s    ÿr¶   c                 C   s
   t ƒ ‚dS )z/Constrain axis values to valid positive values.N©rC   ©Ú	func_nameÚarg_namer[   Úaxisr:   r:   r;   Únormalize_axis  s    r¼   c                    sL   t | tƒst d¡‚t |tƒs(t d¡‚| j› d|j› d�‰ ‡ fdd„}|S )Nz func_name must be a str literal.zarg_name must be a str literal.z: Argument z* out of bounds for dimensions of the arrayc                    s,   |dk r||7 }|dk s ||kr(t ˆ ƒ‚|S ©Nr   ©rœ   r¸   ©r­   r:   r;   Úimpl"  s
    z&normalize_axis_overloads.<locals>.impl)r|   r!   r   ÚTypingErrorÚliteral_value)r¹   rº   r[   r»   rÀ   r:   r¿   r;   Únormalize_axis_overloads  s    



ÿrÃ   Zgetiterc                 C   st   |j \}|\}|  ||j¡}|  tjd¡}t ||¡}||_||_	| j
rX| j |||¡ | ¡ }	t| ||j|	ƒ}
|
S r½   )ÚargsÚmake_helperÚreturn_typer£   r   ru   r	   Úalloca_once_valueÚindexr«   Ú
enable_nrtÚnrtÚincrefÚ	_getvaluer   )rg   r5   rK   rÄ   rn   r«   ÚiterobjÚzeroZindexptrÚresÚoutr:   r:   r;   Úgetiter_array-  s    rÑ   c              	   C   s¤   t j||j|jd�}t j||j|jd�}| |d |¡}t  ||j|¡}	|dd… }
|dd… }t|t	j
ƒrŠt| |||||	|
|ƒ}| ¡ S |
r’t‚t| |||	ƒS dS )z1 Evaluate `ary[idx]`, where idx is a single int. ©r¥   r   r=   N)r	   r¤   rQ   r[   r‘   r¦   Úpointer_addr€   r|   r   ÚBufferÚ	make_viewrÌ   r   ro   )rg   r5   rÆ   rµ   Úaryrx   Úshapesr‘   ÚoffsetÚdataptrÚview_shapesÚview_stridesÚretaryr:   r:   r;   Ú_getitem_array_single_intE  s      ÿrÝ   Ziternextc              	   C   sÂ   |j \}|\}|j}| j|||d�}t|ƒ| ||jd�}	tj||	jdd�\}
| |j	¡}| 
d||
¡}| |¡ | |¡�> t| ||j||	|ƒ}| |¡ t ||¡}| ||j	¡ W 5 Q R X d S )N©Úvaluer=   rÒ   ú<)rÄ   rO   rÅ   rc   r«   r	   r¤   rQ   r6   rÈ   Úicmp_signedÚ	set_validÚif_thenrÝ   Ú
yield_typeÚyield_Úincrement_indexÚstore)rg   r5   rK   rÄ   ÚresultZitertyÚiterrn   rÍ   rÖ   r—   rÈ   Úis_validrß   Znindexr:   r:   r;   Úiternext_arrayZ  s*    
     ÿ
rë   c              	   C   sD  |   tjd¡}|   tjd¡}t ||j|j¡}	t ||j|j¡}
g }g }g }tdd„ |D ƒƒ}d}t	||ƒD �]n\}}|tj
krÔ|jt|ƒ d | }t|ƒD ]2}| |¡ | |	| ¡ | |
| ¡ |d7 }qžqlt|tjƒ�rT| j|||d�}t | |||¡ t |||	| ¡ | |j¡ t ||¡}t |||
| ¡}| |¡ | |¡ n€t|tjƒ�ržt| ||||	| ƒ}|�r’t | |||	| |¡ | |¡ n6t|ƒ�rÆ| |¡ | |¡ |d8 }ntd|f ƒ‚|d7 }ql||jk�sît‚||jk �r"| |	| ¡ | |
| ¡ |d7 }�qît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=   c                 S   s   g | ]}t |ƒr|‘qS r:   ©r   ©rƒ   rx   r:   r:   r;   r…   ‡  s      z"basic_indexing.<locals>.<listcomp>rÞ   úunexpected index type: %sF©Ú
wraparoundÚboundscheck)r£   r   ru   r	   r¤   rQ   r[   r‘   r†   r‡   Úellipsisr2   rU   r|   Ú	SliceTyperÅ   r)   Úguard_invalid_sliceÚ	fix_sliceÚstartÚget_slice_lengthZ
fix_strider~   r{   Zdo_boundscheckr   rC   r   Úget_item_pointer)rg   r5   rµ   rÖ   rˆ   r‰   rñ   rÎ   Úoner×   r‘   Zoutput_indicesZoutput_shapesZoutput_stridesÚnum_newaxesÚaxÚindexvalrw   Ú	n_missingrY   ÚsliceÚshÚstrz   rÙ   r:   r:   r;   Úbasic_indexingv  sf    




ÿ




 þr  c           	   	   C   s.   t |ƒ| |ƒ}t|||||j|j|jd� |S )zF
    Build a view over the given array with the given parameters.
    ©r€   rQ   r‘   r’   r�   r“   )rc   r´   r’   r�   r“   )	rg   r5   rµ   rÖ   rÆ   r€   r×   r‘   rÜ   r:   r:   r;   rÕ   º  s    úrÕ   c              	   C   sb   t | |||||| jd�\}}}	t|tjƒrHt| |||||||	ƒ}
|
 ¡ S |rPt‚t| |||ƒS dS )zp
    Return the result of indexing *ary* with the given *indices*,
    returning either a scalar or a view.
    ©rñ   N)	r  Úenable_boundscheckr|   r   rÔ   rÕ   rÌ   r   ro   )rg   r5   rÆ   rµ   rÖ   rˆ   r‰   rÙ   rÚ   rÛ   rÜ   r:   r:   r;   Ú_getitem_array_genericÊ  s    ÿÿ  ÿr  c           	      C   sZ   |j \}}|\}}|jdks t‚t|ƒ| ||ƒ}t| ||j|||f|fƒ}t| ||j|ƒS )z4
    Basic indexing with an integer or a slice.
    r=   )rÄ   r[   r   rc   r  rÆ   r   ©	rg   r5   rK   rÄ   rµ   rw   rÖ   rx   rÏ   r:   r:   r;   Úgetitem_arraynd_intpß  s    

   ÿr  c              	   C   sœ   |j \}}|\}}t|ƒ| ||ƒ}|j}tj||t|ƒd�}	t| |||	ƒ\}}	tdd„ |D ƒƒrvt| |||||||	ƒS t	| ||j
||||	ƒ}
t| ||j
|
ƒS )z2
    Basic or advanced indexing with a tuple.
    rÒ   c                 s   s   | ]}t |tjƒV  qd S ©N©r|   r   r}   )rƒ   Útyr:   r:   r;   Ú	<genexpr>ÿ  s     z&getitem_array_tuple.<locals>.<genexpr>)rÄ   rc   r   r	   r¤   r†   rŠ   ÚanyÚfancy_getitemr  rÆ   r   )rg   r5   rK   rÄ   rµ   ÚtuptyrÖ   Útuprˆ   r‰   rÏ   r:   r:   r;   Úgetitem_array_tupleð  s.    
 ÿ
   ÿ
   ÿr  c              	   C   sì   |j \}}}|\}}}	t|tjƒr>|j}
tj||t|ƒd�}n|f}
|f}t|ƒ| ||ƒ}t| ||
|ƒ\}
}z"t	| ||||
|| j
d�\}}}W n tk
r¦   d}Y n
X t|ƒ}|rÆt| ||||
|ƒ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†   rc   rŠ   r  r  rC   ÚboolÚfancy_setslicert   re   rr   )rg   r5   rK   rÄ   rµ   rw   ÚvaltyrÖ   rx   rq   rˆ   r‰   rÙ   r×   r‘   Zuse_fancy_indexingr:   r:   r;   Úsetitem_array	  s6    
 ÿÿÿ

 ÿr  c           	      C   sD   |j \}|\}t|ƒ}|| ||ƒ}|j}| |d¡}t| ||j|ƒS r½   )rÄ   rc   rQ   Úextract_valuer   rÆ   )	rg   r5   rK   rÄ   rµ   rÖ   ZarysttyZshapearyrÏ   r:   r:   r;   Ú	array_len2  s    r  z
array.itemc              	   C   st   |j \}|\}t|ƒ| ||ƒ}|j}|j| d|| d¡¡dd�� d}| j |t|f¡ W 5 Q R X t	| |||j
ƒS )Nú!=r=   F©Zlikelyz>item(): can only convert an array of size 1 to a Python scalar)rÄ   rc   r—   rã   rá   r3   Ú	call_convÚreturn_user_excrœ   ro   r€   )rg   r5   rK   rÄ   rµ   rÖ   r—   r­   r:   r:   r;   Ú
array_item=  s    ÿr  zarray.itemsetc           
   	   C   s�   |j \}}|\}}||jks t‚t|ƒ| ||ƒ}|j}|j| d|| d¡¡dd�� d}	| j 	|t
|	f¡ W 5 Q R X t| ||||jƒ |  ¡ S )Nr  r=   Fr  z/itemset(): can only write to an array of size 1)rÄ   re   r   rc   r—   rã   rá   r3   r  r  rœ   rr   r€   Úget_dummy_value)
rg   r5   rK   rÄ   rµ   r  rÖ   rq   r—   r­   r:   r:   r;   Úarray_itemsetL  s    
ÿr  c                   @   s@   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   s   t ‚dS )ze
        Prepare the indexer by initializing any required variables, basic
        blocks...
        Nr·   ©rI   r:   r:   r;   Úprepareg  s    zIndexer.preparec                 C   s   t ‚dS )z=
        Return this dimension's size as an integer.
        Nr·   r   r:   r:   r;   Úget_sizen  s    zIndexer.get_sizec                 C   s   t ‚dS )z;
        Return this dimension's shape as a tuple.
        Nr·   r   r:   r:   r;   Ú	get_shapet  s    zIndexer.get_shapec                 C   s   t ‚dS )z}
        Return a half-open [lower, upper) range of indices this dimension
        is guaranteed not to step out of.
        Nr·   r   r:   r:   r;   Úget_index_boundsz  s    zIndexer.get_index_boundsc                 C   s   t ‚dS )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.
        Nr·   r   r:   r:   r;   Ú	loop_head�  s    	zIndexer.loop_headc                 C   s   t ‚dS )z)
        Finish indexation loop.
        Nr·   r   r:   r:   r;   Ú	loop_tailŒ  s    zIndexer.loop_tailN)
r\   r]   r^   Ú__doc__r!  r"  r#  r$  r%  r&  r:   r:   r:   r;   r  a  s   r  c                   @   sH   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  )	rg   r5   rµ   rÖ   Údimr�   r   ru   Úll_intp)rI   rg   r5   rµ   rÖ   r)  r:   r:   r;   Ú__init__˜  s    zEntireIndexer.__init__c                 C   sB   | j }| | jj| j¡| _t || j¡| _	| 
¡ | _| 
¡ | _d S r  )r5   r  rÖ   rQ   r)  ry   r	   rG   r*  rÈ   Úappend_basic_blockÚbb_startÚbb_end©rI   r5   r:   r:   r;   r!     s
    
zEntireIndexer.preparec                 C   s   | j S r  ©ry   r   r:   r:   r;   r"  §  s    zEntireIndexer.get_sizec                 C   s   | j fS r  r0  r   r:   r:   r;   r#  ª  s    zEntireIndexer.get_shapec                 C   s   |   d¡| jfS r½   ©r*  ry   r   r:   r:   r;   r$  ­  s    zEntireIndexer.get_index_boundsc              	   C   s|   | j }| j  t| jdƒ| j¡ | | j¡ | | j¡ | | j¡}|j	| 
d|| j¡dd�� | | j¡ W 5 Q R X ||fS ©Nr   ú>=Fr  )r5   rç   r   r*  rÈ   Úbranchr-  Úposition_at_endr6   rã   rá   ry   r.  )rI   r5   Ú	cur_indexr:   r:   r;   r%  ±  s    ÿzEntireIndexer.loop_headc                 C   sD   | j }t || | j¡¡}| || j¡ | | j¡ | | j	¡ d S r  )
r5   r	   ræ   r6   rÈ   rç   r4  r-  r5  r.  ©rI   r5   Ú
next_indexr:   r:   r;   r&  ½  s
    zEntireIndexer.loop_tailN©r\   r]   r^   r'  r+  r!  r"  r#  r$  r%  r&  r:   r:   r:   r;   r(  “  s   r(  c                   @   sH   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 )ÚIntegerIndexerz0
    Compute indices from a single integer.
    c                 C   s&   || _ || _|| _| j  tj¡| _d S r  )rg   r5   rx   r�   r   ru   r*  )rI   rg   r5   rx   r:   r:   r;   r+  Ê  s    zIntegerIndexer.__init__c                 C   s   d S r  r:   r   r:   r:   r;   r!  Ð  s    zIntegerIndexer.preparec                 C   s   t | jdƒS ©Nr=   )r   r*  r   r:   r:   r;   r"  Ó  s    zIntegerIndexer.get_sizec                 C   s   dS ©Nr:   r:   r   r:   r:   r;   r#  Ö  s    zIntegerIndexer.get_shapec                 C   s   | j | j | j |  ¡ ¡fS r  )rx   r5   Úaddr"  r   r:   r:   r;   r$  Ù  s    zIntegerIndexer.get_index_boundsc                 C   s
   | j d fS r  )rx   r   r:   r:   r;   r%  Ý  s    zIntegerIndexer.loop_headc                 C   s   d S r  r:   r   r:   r:   r;   r&  à  s    zIntegerIndexer.loop_tailNr9  r:   r:   r:   r;   r:  Å  s   r:  c                   @   sH   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 )ÚIntegerArrayIndexerz;
    Compute indices from an array of integer indices.
    c                 C   s@   || _ || _|| _|| _|| _|jdks,t‚| j  tj	¡| _
d S r;  )rg   r5   rw   r�   ry   r[   r   r�   r   ru   r*  )rI   rg   r5   rw   r�   ry   r:   r:   r;   r+  é  s    zIntegerArrayIndexer.__init__c                 C   sD   | j }t || jj¡d | _t || j¡| _| 	¡ | _
| 	¡ | _d S r½   )r5   r	   r¤   r�   rQ   Úidx_sizerG   r*  Ú	idx_indexr,  r-  r.  r/  r:   r:   r;   r!  ò  s
    
zIntegerArrayIndexer.preparec                 C   s   | j S r  ©r?  r   r:   r:   r;   r"  ù  s    zIntegerArrayIndexer.get_sizec                 C   s   | j fS r  rA  r   r:   r:   r;   r#  ü  s    zIntegerArrayIndexer.get_shapec                 C   s   |   d¡| jfS r½   r1  r   r:   r:   r;   r$  ÿ  s    z$IntegerArrayIndexer.get_index_boundsc              	   C   s°   | j }| j  t| jdƒ| j¡ | | j¡ | | j¡ | | j¡}|j	| 
d|| j¡dd�� | | j¡ W 5 Q R X t| j|| jj| j| j|ƒ}t| j|| jj|| jƒ}||fS r2  )r5   rç   r   r*  r@  r4  r-  r5  r6   rã   rá   r?  r.  rÝ   rg   rw   re   r�   r{   ry   )rI   r5   r6  rÈ   r:   r:   r;   r%    s0    þ    þ  ÿzIntegerArrayIndexer.loop_headc                 C   sD   | j }t || | j¡¡}| || j¡ | | j¡ | | j	¡ d S r  )
r5   r	   ræ   r6   r@  rç   r4  r-  r5  r.  r7  r:   r:   r;   r&    s    
ÿzIntegerArrayIndexer.loop_tailNr9  r:   r:   r:   r;   r>  ä  s   	r>  c                   @   sH   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 )ÚBooleanArrayIndexerz>
    Compute indices from an array of boolean predicates.
    c                 C   sH   || _ || _|| _|| _|jdks&t‚| j  tj¡| _	t
| j	dƒ| _d S ©Nr=   r   )rg   r5   rw   r�   r[   r   r�   r   ru   r*  r   rÎ   )rI   rg   r5   rw   r�   r:   r:   r;   r+  &  s    zBooleanArrayIndexer.__init__c                 C   s^   | j }t || jj¡d | _t || j¡| _t || j¡| _	| 
¡ | _| 
¡ | _| 
¡ | _d S r½   )r5   r	   r¤   r�   rQ   ry   rG   r*  r@  r¥   r,  r-  Úbb_tailr.  r/  r:   r:   r;   r!  /  s    

zBooleanArrayIndexer.preparec              	   C   s‚   | j }t || j¡}t || j¡�P}| |¡}t| j|| j	j
| j	| j|jƒ}| || ||j¡¡}| ||¡ W 5 Q R X | |¡S r  )r5   r	   rÇ   rÎ   Ú	for_rangery   r6   rÝ   rg   rw   re   r�   rÈ   r=  Zzextr3   rç   )rI   r5   r¥   ÚloopÚcÚpredr:   r:   r;   r"  8  s    
    þzBooleanArrayIndexer.get_sizec                 C   s
   |   ¡ fS r  ©r"  r   r:   r:   r;   r#  G  s    zBooleanArrayIndexer.get_shapec                 C   s   |   d¡| jfS r½   r1  r   r:   r:   r;   r$  J  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 5 Q R X t| j|| jj| j| j|ƒ}| 	| |¡¡� | | j¡ W 5 Q R X t ||¡}| || j¡ ||fS )Nr3  Fr  )r5   rç   rÎ   r@  r¥   r4  r-  r5  r6   rã   rá   ry   r.  rÝ   rg   rw   re   r�   Únot_rD  r	   ræ   )rI   r5   r6  Ú	cur_countrH  Ú
next_countr:   r:   r;   r%  O  s0    ÿ    þzBooleanArrayIndexer.loop_headc                 C   s\   | j }| | j¡ | | j¡ t || | j¡¡}| || j¡ | | j	¡ | | j
¡ d S r  )r5   r4  rD  r5  r	   ræ   r6   r@  rç   r-  r.  r7  r:   r:   r;   r&  g  s    
ÿzBooleanArrayIndexer.loop_tailNr9  r:   r:   r:   r;   rB  !  s   		rB  c                   @   sH   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 )ÚSliceIndexerz(
    Compute indices along a slice.
    c                 C   sL   || _ || _|| _|| _|| _|| _|| _| j  tj	¡| _
t| j
dƒ| _d S r½   )rg   r5   rµ   rÖ   r)  rw   rþ   r�   r   ru   r*  r   rÎ   )rI   rg   r5   rµ   rÖ   r)  rw   rþ   r:   r:   r;   r+  w  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  )r5   r  rÖ   rQ   r)  Údim_sizer)   rô   rg   rw   rþ   rõ   r	   Z
is_neg_intÚstepÚis_step_negativerG   r*  rÈ   r¥   r,  r-  r.  r/  r:   r:   r;   r!  ‚  s    ÿ
zSliceIndexer.preparec                 C   s   t  | j| j¡S r  )r)   r÷   r5   rþ   r   r:   r:   r;   r"  �  s    zSliceIndexer.get_sizec                 C   s
   |   ¡ fS r  rI  r   r:   r:   r;   r#  “  s    zSliceIndexer.get_shapec                 C   s   t  | j| j¡\}}||fS r  )r)   Zget_slice_boundsr5   rþ   )rI   ÚlowerÚupperr:   r:   r;   r$  –  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 5 Q R X ||fS )Nz<=r3  Fr  )r5   rç   rþ   rö   rÈ   rÎ   r¥   r4  r-  r5  r6   ÚselectrP  rá   Ústoprã   r.  )rI   r5   r6  rK  Úis_finishedr:   r:   r;   r%  š  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•   )r5   r=  r6   rÈ   rþ   rO  rç   r	   ræ   r¥   r4  r-  r5  r.  )rI   r5   r8  rL  r:   r:   r;   r&  ¬  s    ÿzSliceIndexer.loop_tailNr9  r:   r:   r:   r;   rM  r  s   rM  c                   @   s@   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 )ÚFancyIndexerz4
    Perform fancy indexing on the given array.
    c              	   C   sˆ  || _ || _|| _t ||j|j¡| _t ||j|j¡| _| j  	t
j¡| _g | _g }tdd„ |D ƒƒ}d}	d}
t||ƒD �]”\}}|t
jkrÜ|jt|ƒ d | }t|ƒD ].}t|||||	ƒ}| |¡ |	d7 }	|
d7 }
qªqxt|t
jƒ�r| |||¡}t|||||	||ƒ}| |¡ næt|t
jƒ�rTt||||| j|	 ƒ}t|||ƒ}| |¡ nªt|t
jƒ�rÐt|ƒ|||ƒ}t|jt
jƒ�ršt||||| j|	 ƒ}n*t|jt
jƒ�rºt ||||ƒ}n
d�sÄt!‚| |¡ n.t"|ƒ�rð| j |
¡ |	d8 }	nt!d|f ƒ‚|	d7 }	|
d7 }
qx|	|jk�s*t!|	|jfƒ‚|	|jk �r\t|||||	ƒ}| |¡ |	d7 }	�q*t|ƒ|jk�s~t!t|ƒ|jfƒ‚|| _#d S )Nc                 S   s   g | ]}t |ƒr|‘qS r:   rì   rí   r:   r:   r;   r…   Æ  s      z)FancyIndexer.__init__.<locals>.<listcomp>r   r=   rî   )$rg   r5   rµ   r	   r¤   rQ   r[   r×   r‘   r�   r   ru   r*  Únewaxesr†   r‡   rò   r2   r(  rU   r|   ró   rÅ   rM  r~   r{   r:  r}   rc   re   r>  ÚBooleanrB  r   r   Úindexers)rI   rg   r5   rµ   rÖ   rˆ   r‰   rY  rú   rû   Znew_axrü   rw   rý   rY   Úindexerrþ   rz   r�   r:   r:   r;   r+  ¼  sz    


 ÿ
ÿ þ ÿ




"zFancyIndexer.__init__c                 C   s^   | j D ]}| ¡  q| j tjd¡}dd„ | j D ƒ}| jD ]}| ||f¡ q:t|dƒ| _	d S )Nr=   c                 S   s   g | ]}|  ¡ ‘qS r:   )r#  ©rƒ   rY   r:   r:   r;   r…     s     z(FancyIndexer.prepare.<locals>.<listcomp>r:   )
rY  r!  rg   r£   r   ru   rW  ÚinsertÚsumÚindexers_shape)rI   rY   rù   Z	res_shaper:   r:   r;   r!  þ  s    


zFancyIndexer.preparec                 C   s   | j S )z?
        Get the resulting data shape as Python tuple.
        )r^  r   r:   r:   r;   r#    s    zFancyIndexer.get_shapec              	   C   s  t |ƒ| jjkst‚| j}tj}|  d¡}|  d¡}|}|}t| j	| j
|ƒD ]†\}	}
}| || d|
|¡¡}|	 ¡ \}}| ||¡}| || ||¡¡}| d||¡}| || |||¡¡}| || |||¡¡}qL| ||¡}| |||¡}| |||¡}||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[   r   r5   r	   Ú	false_bitr*  r‡   rY  r^  Úor_Úicmp_unsignedr$  r¦   Úsubrá   r=  rS  )rI   r‘   r’   r5   Úis_emptyrÎ   rù   rQ  rR  rZ  rQ   ÚstrideZlower_indexZupper_indexZlower_offsetZupper_offsetZis_downwardsr:   r:   r;   Úget_offset_bounds  sB    


ÿÿþÿþÿzFancyIndexer.get_offset_boundsc                 C   s    t dd„ | jD ƒŽ \}}||fS )Nc                 s   s   | ]}|  ¡ V  qd S r  )r%  r[  r:   r:   r;   r  >  s     z+FancyIndexer.begin_loops.<locals>.<genexpr>)r‡   rY  )rI   r‰   Úcountsr:   r:   r;   Úbegin_loops=  s    zFancyIndexer.begin_loopsc                 C   s   t | jƒD ]}| ¡  q
d S r  )ÚreversedrY  r&  )rI   rY   r:   r:   r;   Ú	end_loopsA  s    zFancyIndexer.end_loopsN)
r\   r]   r^   r'  r+  r!  r#  rf  rh  rj  r:   r:   r:   r;   rV  ·  s   B&rV  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¤   rQ   r‘   r€   rV  r!  rÆ   r#  Ú_empty_nd_implrÇ   r£   r   ru   rh  Úget_item_pointer2Úlayoutr  ro   r6   Úgeprr   ræ   rç   rj  r   rÌ   )rg   r5   rK   rÄ   rµ   rÖ   rˆ   r‰   r×   r‘   r€   rZ  Zout_tyZ
out_shapesrÐ   Zout_dataZout_idxÚ_rW   rq   ÚcurZnext_idxr:   r:   r;   r  F  s<    
 ÿÿ  þ
r  c           	   	   C   s†   |j \}}|\}}t|ƒ| ||ƒ}|jdkrht| |||ƒ\}}t| ||j|||f|fƒ}t| ||j|ƒS t| ||||||f|fƒS dS )z3
    Advanced or basic indexing with an array.
    r   N)rÄ   rc   r[   r‚   r  rÆ   r   r  r  r:   r:   r;   Úfancy_getitem_arrayq  s$    


   ÿ
   ÿrq  c              	   C   sæ   |j }| d¡}| d¡}|jdkr8|}	| ||j¡}
n¦|}	|}
t|jƒD ]Z}| || | || |¡¡}| d||¡}| 	|| 
|
|¡|
¡}
| 	||	| 
|	|¡¡}	qJ| 
|
|¡}
| 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=   ÚCFr3  r_  )r’   r3   rm  r¦   r—   r2   r[   rc  rá   rS  r=  )rg   r5   ÚarrtyÚarrr×   r‘   r’   rÎ   rù   rQ  rR  rY   Zmax_axis_offsetZ
is_upwardsrd  r:   r:   r;   Úoffset_bounds_from_strides…  s4    



ÿ
 ÿ 
ÿru  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.
    )Úptrtointr3   r=  )rg   r5   rQ  rR  r€   Zdata_ptr_as_intrö   Úendr:   r:   r;   Úcompute_memory_extents¯  s    rx  c           	      C   s&   t | |||||ƒ\}}t| ||||ƒS )zr
    Compute a half-open range [start, end) of pointer-sized integers
    which fully contain the array data.
    )ru  rx  )	rg   r5   rs  rt  r×   r‘   r€   rQ  rR  r:   r:   r;   Úget_array_memory_extentsº  s
    
 ÿry  c                 C   s$   |  | d||¡| d||¡¡}|S )z[
    Whether two memory extents [a_start, a_end) and [b_start, b_end)
    may overlap.
    rà   )Úand_rb  )rg   r5   Za_startZa_endZb_startZb_endZmay_overlapr:   r:   r;   Úextents_may_overlapÅ  s
    þr{  c                    s  ˆj ‰d‰t ˆ ˆ¡‰ˆ‰d ‰ˆ jˆdd��¨ ˆ  |j|j¡}ˆj ˆ |¡}	|	j ‰ˆ  	|	ˆ¡}	ˆ  
|	ˆ¡ ˆ tj¡}
t ˆ ˆ|
¡�F}t ˆˆ ˆˆˆ	ˆ
j|¡}t ˆˆ |	ˆˆˆ|¡}ˆ  
ˆ  |¡|¡ W 5 Q R X W 5 Q R X ‡ ‡‡‡‡‡‡‡‡‡	‡
‡fdd„}‡ ‡‡‡‡fdd„}||fS )Nr‹   Fr  c                    sª   t  ˆ ˆ¡}ˆ jˆdd��v\}}|�. ˆ  t jˆˆ ˆ  ˆ¡ˆˆˆ| dd�|¡ W 5 Q R X |�* ˆ  t jˆˆ ˆˆˆ	ˆ
j| dd�|¡ W 5 Q R X W 5 Q R X tˆˆ ˆ
ˆ  |¡ƒS )NFr  ©rð   )r	   rG   Úif_elserç   rl  r6   rm  ro   )Úsource_indicesÚsrc_ptrZif_copyZ	otherwise)r5   rg   Ú	copy_dataÚcopy_layoutÚcopy_shapesÚcopy_stridesÚptrtyÚsrc_dataÚ
src_shapesÚsrc_stridesÚsrctyÚuse_copyr:   r;   Úsrc_getitemñ  s4      üú
  ýûz&maybe_copy_source.<locals>.src_getitemc               	      sB   ˆ j ˆdd��* ˆ  ˆ¡} ˆ  | ˆ¡} ˆj ˆ | ¡ W 5 Q R X d S )NFr  )rã   r6   ÚbitcastrÊ   Úfree©r€   )r5   rg   r€  r‰  Ú	voidptrtyr:   r;   Úsrc_cleanup  s    
z&maybe_copy_source.<locals>.src_cleanup)r3   r	   rÇ   rã   r¦   r’   r—   rÊ   Úallocater‹  rç   r�   r   ru   Ú	loop_nestrl  rm  r6   )rg   r5   r‰  rˆ  Úsrcr†  r‡  r…  Ú	allocsizer€   r®   r‰   r  Údest_ptrrŠ  r�  r:   )r5   rg   r€  r�  r‚  rƒ  r„  r…  r†  r‡  rˆ  r‰  rŽ  r;   Úmaybe_copy_sourceÒ  s:    
  þ
  þ&"r•  c           
   	      sþ   |   tjd¡}|   tjd¡‰t|ƒt|ƒkrZt|ƒt|ƒ }ˆg| | }|g| | }nœt|ƒt|ƒk röt|ƒt|ƒ }‡ ‡fdd„|d|… D ƒ}t ˆ j|tj¡}ˆ j	ˆ  
|¡dd�� d}	| j ˆ t|	f¡ W 5 Q R X ||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                    s   g | ]}ˆ   d |ˆ¡‘qS ©r_  )rb  ©rƒ   rÿ   ©r5   rù   r:   r;   r…   %  s   ÿz(_bc_adjust_dimension.<locals>.<listcomp>NFr  z,cannot broadcast source array for assignment)r£   r   rv   r†   Ú	functoolsÚreducerz  r	   Útrue_bitrã   rJ  r  r  rœ   )
rg   r5   r×   r‘   Útarget_shaperÎ   Znd_diffZ
dim_is_oneÚacceptedr­   r:   r˜  r;   Ú_bc_adjust_dimension  s(    	
ÿ
ÿrž  c           
         s¤   g }g }|   tjd¡‰|   tjd¡‰‡ fdd„t||ƒD ƒ}‡ ‡fdd„|D ƒ}‡ fdd„t||ƒD ƒ}	‡ fdd„t|	||ƒD ƒ}‡ ‡fdd„t|	|ƒD ƒ}||fS )	zü
    Broadcast shapes and strides to target_shape given that their ndim already
    matches.  For each location where the shape is 1 and does not match the
    dim for target, it is set to the value at the target and the stride is
    set to zero.
    r   r=   c                    s   g | ]\}}ˆ   d ||¡‘qS )r  ©rá   )rƒ   ÚtarÚold©r5   r:   r;   r…   @  s   ÿz,_bc_adjust_shape_strides.<locals>.<listcomp>c                    s   g | ]}ˆ   d |ˆ¡‘qS r–  rŸ  )rƒ   r¡  r˜  r:   r;   r…   B  s     c                    s   g | ]\}}ˆ   ||¡‘qS r:   )rz  )rƒ   ÚxÚyr¢  r:   r;   r…   C  s     c                    s    g | ]\}}}ˆ   |||¡‘qS r:   ©rS  )rƒ   Úpr   r¡  r¢  r:   r;   r…   D  s   ÿc                    s   g | ]\}}ˆ   |ˆ|¡‘qS r:   r¥  )rƒ   r¦  r¡  )r5   rÎ   r:   r;   r…   F  s   ÿ)r£   r   rv   r‡   )
rg   r5   r×   r‘   rœ  Z	bc_shapesZ
bc_stridesÚmismatchZ
src_is_oneÚpredsr:   )r5   rù   rÎ   r;   Ú_bc_adjust_shape_strides4  s     
ÿ

ÿÿr©  c           	   	   C   sš   t  ||j¡}t  ||j¡}t| ||||ƒ\}}t| ||||ƒ\}}|jt|ƒdd�}t|ƒ| |ƒ}t	||j
t  ||¡t  ||¡|j|j|jd� ||fS )zX
    Broadcast the given array to the target_shape.
    Returns (array_type, array)
    ÚA©r[   rm  r  )r	   r¤   rQ   r‘   rž  r©  Úcopyr†   rc   r´   r€   rV   r’   r�   r“   )	rg   r5   Úarrtypert  rœ  r×   r‘   Znew_arrtypeZnew_arrr:   r:   r;   Ú_broadcast_to_shapeK  s(    
ÿ ÿ

úr®  c                 C   s,   |j |jddd�}|||ƒ}dd„ }||fS )Nrª  T)r[   rm  Úreadonlyc           
   	   S   sz   |\}}|j d }t|ƒ| ||ƒ}t ||¡}t| ||||ƒ\}}t|dt|  |j 	d¡¡d ƒƒ | 
¡ }	t| ||j|	ƒS )Nr   r“   )rÄ   rc   r	   r¤   r®  rª   r   r�   r˜   rž   rÌ   r   rÆ   )
rg   r5   rK   rÄ   r’  Zshape_rˆ  ro  ÚdestrÏ   r:   r:   r;   Úcodegenj  s    
þz$_numpy_broadcast_to.<locals>.codegen)r¬  r¥   )Ú	typingctxr«   rQ   ÚretrK   r±  r:   r:   r;   Ú_numpy_broadcast_toe  s    
r´  c                 C   s$   |j dd�}||ƒ}dd„ }||fS )NT©r¯  c                 S   sH   |\}|j d }t|ƒ| ||ƒ}t |jj¡|_| ¡ }t| ||j|ƒS r½   )	rÄ   rc   r	   Zget_null_valuer“   r3   rÌ   r   rÆ   )rg   r5   rK   rÄ   r’  rˆ  r°  rÏ   r:   r:   r;   r±  ‚  s    
z#get_readonly_array.<locals>.codegen)r¬  )r²  rt  r³  rK   r±  r:   r:   r;   Úget_readonly_array|  s    	r¶  c           
      C   s”   | j }t|ƒ}t|ƒ}||kr&tdƒ‚|D ]}|dk r*tdƒ‚q*d}|| }||k r�|| }|| }	||	kst|dkr†|d7 }|d7 }qLtdƒ‚qLd 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)rQ   r†   rœ   )
r«   Z
dest_shapeZ	src_shapeZsrc_ndimZ	dest_ndimry   Z	src_indexZ
dest_indexZsrc_dimZdest_dimr:   r:   r;   Ú_can_broadcastŽ  s"    

r·  c                 C   s   t  | ¡} t| |ƒ t| |ƒS r  )ÚnpÚasarrayr·  r´  ©r«   rQ   r:   r:   r;   Ú_default_broadcast_to_impl®  s    

r»  c                 C   s  t | ƒst d¡‚t|tjƒr*dd„ }|S t|tjƒrVt|jtjƒsRd}t |¡‚tS t|tj	ƒr˜|j
dkr˜tdd„ |D ƒƒs”d|› d	�}t |¡‚tS t|tj	ƒrì|j
dkrìt| tjƒoÂ| jdk}t| ƒsÐ|rÜd
d„ }|S d}t |¡‚nd| }t |¡‚d S )Nz-The first argument "array" must be array-likec                 S   s   t  | |f¡S r  )r¸  Úbroadcast_torº  r:   r:   r;   rÀ   »  s    z numpy_broadcast_to.<locals>.implz7The second argument "shape" must be a tuple of integersr   c                 S   s   g | ]}t |tjƒ‘qS r:   )r|   r   ÚIntegerLiteral)rƒ   Útypr:   r:   r;   r…   Ç  s     z&numpy_broadcast_to.<locals>.<listcomp>ú"z," object cannot be interpreted as an integerc                 S   s   t  | ¡} t| ƒS r  )r¸  r¹  r¶  rº  r:   r:   r;   rÀ   Ï  s    
z/Cannot broadcast a non-scalar to a scalar arrayz:The argument "shape" must be a tuple or an integer. Got %s)r   r   rÁ   r|   r   r~   ÚUniTuplere   r»  ÚTupler¥   Úallr}   r[   r   )r«   rQ   rÀ   r­   Zis_scalar_arrayr:   r:   r;   Únumpy_broadcast_to´  s4    


ÿrÃ  c                 C   sr   t t|ƒƒD ]`}|t|ƒ | }|| }|dk r8tdƒ‚|dkrBq| | dkrX|| |< q| | |krtdƒ‚qd S )Nr   ú#negative dimensions are not allowedr=   z=shape mismatch: objects cannot be broadcast to a single shape)r2   r†   rœ   )ÚrÚmrQ   rY   r²   Útmpr:   r:   r;   Únumpy_broadcast_shapes_listß  s    
rÈ  c                     sô   t | ƒD ]n\}}t|tjƒ}t|tjƒo4t|jtjƒ}t|tjƒoNt|jƒdk}|s|s|sd|› d|› �}t 	|¡‚qd‰| D ]6}t|tjƒrœt
ˆdƒ‰q€t|tjƒr€t
ˆt|ƒƒ‰q€ˆdkrÈdd„ S dˆ ‰ddlm‰  ‡ ‡‡fd	d
„}|S d S )Nr   z	Argument z* must be either an int or tuple[int]. Got r=   c                  W   s   dS r<  r:   ©rÄ   r:   r:   r;   Ú<lambda>  ó    z+ol_numpy_broadcast_shapes.<locals>.<lambda>©r=   )Ú_isinstance_no_warnc                     sz   dgˆ }ˆ}t | ƒD ]@}ˆ |tƒr>t|ƒdkr>t|ˆ|ƒ qˆ |tƒrt|ˆ|fƒ qt|ƒD ]\}}t|||ƒ}q`|S rC  )r   rŸ   r†   rÈ  r¡   Ú	enumerater*   )rÄ   rÅ  r  Úargrx   Úelem©rÍ  rÆ  Útup_initr:   r;   rÀ     s    

z'ol_numpy_broadcast_shapes.<locals>.impl)rÎ  r|   r   r~   rÀ  re   rÁ  r†   r   rÁ   Úmaxr  Znumba.cpython.builtinsrÍ  )rÄ   rx   rÏ  Zis_intZis_int_tupleZis_empty_tupler­   rÀ   r:   rÑ  r;   Úol_numpy_broadcast_shapesð  s*    ÿrÔ  c                     sþ   t | ƒD ]"\}}t|ƒst d|› d�¡‚qd }d }| D ]H}t|tjtjfƒrV|j}n|}|d krh|}q8||kr8t d| › �¡‚q8d‰ t | ƒD ]T\}}t|tj	ƒr°t
ˆ |jƒ‰ qŽt|tjtjtjfƒrÒt
ˆ dƒ‰ qŽt d|› �¡‚qŽ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|||| ƒ}q8g }t | ƒD ]}| t t |¡|¡¡ qZ|S r;  )	r   rÈ  r¸  r¹  rQ   r2   r*   rU   r¼  )rÄ   rQ   r«   r  rY   Zouts©rÆ  rÒ  r:   r;   rÀ   >  s    
z$numpy_broadcast_arrays.<locals>.impl)rÎ  r   r   rÁ   r|   r   r}   r  re   ZArrayCompatiblerÓ  r[   ÚNumberrX  )rÄ   rx   rÏ  Zunified_dtypeÚdtrÀ   r:   rÕ  r;   Únumpy_broadcast_arrays  s.    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sÞt‚t||ƒD ]\}}ˆ  |ˆ  d||¡¡}qèˆ j|dd�� d}ˆj ˆ t|f¡ W 5 Q R X tˆˆ ˆˆ|||ƒ\}}| |
|j¡\}}tˆˆ |||ƒ\}}tˆˆ ||||ƒ}tˆˆ |ˆˆ|||ƒ\}}nÆt	ˆt
jƒ�rRˆj‰| ¡ }t|ƒdk�sÒt‚ˆ  tt!t
j"ˆƒ¡}|ˆ ˆfƒ}ˆ  d|d |¡}ˆ j|dd�� d}ˆj ˆ t|f¡ W 5 Q R X ‡ ‡‡‡‡fdd„}d	d
„ }nˆ‰‡fdd„}dd
„ }ˆ #t
j$d¡} | %¡ \}!}"t&|"ƒ}"|j'D ]}#|" (|#| ¡ �q’dd„ |"D ƒ}$||$ƒ}%ˆ )ˆ |%ˆ|j¡}%tj*ˆˆ ||	|
|j+|!dˆj,d�	}&t-ˆˆ ||%|&ƒ | .¡  |ƒ  ˆ /¡ S )zÇ
    Implement slice assignment for arrays.  This implementation works for
    basic as well as fancy indexing, since there's no functional difference
    between the two for indexed assignment.
    r  Fr  z0cannot assign slice from input of different sizer=   r   c                    s,   | \}ˆ  tjtˆˆtjƒ¡}|ˆ ˆ|fƒS r  )rB   ÚoperatorÚgetitemr    r   ru   )r~  rx   Úgetitem_impl©r5   rg   r’  Z	src_dtyperˆ  r:   r;   rŠ     s    þz#fancy_setslice.<locals>.src_getitemc                   S   s   d S r  r:   r:   r:   r:   r;   r�  ¨  s    z#fancy_setslice.<locals>.src_cleanupc                    s   ˆ S r  r:   )r~  )r’  r:   r;   rŠ  °  s    c                   S   s   d S r  r:   r:   r:   r:   r;   r�  ³  s    c                 S   s   g | ]}|d k	r|‘qS r  r:   )rƒ   rG  r:   r:   r;   r…   Ç  s      z"fancy_setslice.<locals>.<listcomp>rï   )0rÄ   rc   r	   r¤   rQ   r‘   r€   rV  r!  r|   r   rÔ   re   r#  r®  r`  r†   r   r‡   ra  rá   rã   r  r  rœ   ry  rf  r’   rx  r{  r•  ÚSequencerB   r    ru   r£   rv   rh  r    rW  r\  rt   rl  rm  r  rr   rj  r  )'rg   r5   rK   rÄ   rˆ   r‰   rµ   ro  rÖ   Zdest_shapesÚdest_stridesÚ	dest_datarZ  Zindex_shaper†  r‡  r…  Zshape_errorÚur³   r­   Z	src_startZsrc_endZ
dest_lowerZ
dest_upperZ
dest_startZdest_endr‰  rŠ  r�  Úlen_implZseq_lenrÎ   Zdest_indicesrg  rY   r~  rq   r”  r:   rÜ  r;   r  U  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                    s"   g | ]\}}ˆ  ˆ ||tj¡‘qS r:   ©rt   r   ru   )rƒ   r
  rq   r„   r:   r;   r…   è  s   ÿz#vararg_to_tuple.<locals>.<listcomp>©re   r¥   )rÄ   r‡   r	   rV   r3   r   rÀ  ru   r†   r   r    rÆ   )rg   r5   rK   rÄ   rµ   ZdimtysrÖ   rX   rQ   ÚshapetyÚnew_sigÚnew_argsr:   r„   r;   Úvararg_to_tupleá  s    
ÿrç  zarray.transposec                 C   s   t | ||jd |d ƒS r½   )Úarray_TrÄ   ©rg   r5   rK   rÄ   r:   r:   r;   Úarray_transposeô  s    rê  c                 C   sn   t | ƒt t| ƒƒkrtdƒ‚t |ƒ}| D ] }||ks@t|ƒ|kr(tdƒ‚q(||  |d d …< ||  |d d …< d S )Nzrepeated axis in transposez2axis is out of bounds for array of given dimension)r†   rš   rœ   Úabs)r»   rQ   r‘   r)  r£  r:   r:   r;   Úpermute_arraysù  s    
rì  c              
      s˜  |j d }t|ƒˆˆ |d ƒ}|j d |d  }}|j|j }}	ˆ tj¡}
t |
|¡‰||j	|j
g}‡ ‡fdd„|D ƒ}t||ƒD ]\}}ˆ  ||¡ q„tj|	ddd�‰ˆ tjˆ |
¡¡}‡ ‡‡fdd„|D ƒ}t||ƒD ]6\}}t|ˆ  ||
 ¡ ¡ˆ tj|¡g|g|d d� qÞˆ ˆ tt tjˆˆˆ¡d	d„ |D ƒ¡ t|jƒˆˆ ƒ}t||jˆ  |d ¡ˆ  |d
 ¡|j|j|jd� | ¡ }tˆˆ |j|ƒS )Nr   r=   c                    s   g | ]}t  ˆ ˆ¡‘qS r:   ©r	   rG   ©rƒ   ro  )r5   Úll_ary_sizer:   r;   r…     s     z)array_transpose_tuple.<locals>.<listcomp>r‹   ©re   r[   rm  c                    s   g | ]}t ˆƒˆˆ ƒ‘qS r:   ©rc   rî  )r5   rg   Ú	np_ary_tyr:   r;   r…      s     ©r€   rQ   r‘   r’   r�   c                 S   s   g | ]}|  ¡ ‘qS r:   ©rÌ   ©rƒ   Úar:   r:   r;   r…   0  s     é   r  ) rÄ   rc   r¥   re   r�   r   ru   r   Ú	ArrayTyperQ   r‘   r‡   rç   r}   r£   rf   r´   r‹  Ú
as_pointerÚcompile_internalrì  r   r    ÚvoidrÆ   r€   r6   r’   r�   r“   rÌ   r   )rg   r5   rK   rÄ   rµ   rÖ   Zaxistyr»   Znum_axisre   r*  ZarysZll_arysr’  ÚdstZnp_itemsizeZnp_arysZnp_aryZll_aryr³  rÏ   r:   )r5   rg   rï  rò  r;   Úarray_transpose_tuple  sT    
ÿû	  ÿýúrý  c                 C   s    t | |||ƒ\}}t| |||ƒS r  )rç  rý  ©rg   r5   rK   rÄ   rå  ræ  r:   r:   r;   Úarray_transpose_vararg?  s    rÿ  c                 C   s8   t | tjƒrt d¡‚|d kr*ddd„}n
ddd„}|S )Nz#np.transpose does not accept tuplesc                 S   s   |   ¡ S r  ©Ú	transpose©rö  Úaxesr:   r:   r;   Únp_transpose_implK  s    z*numpy_transpose.<locals>.np_transpose_implc                 S   s
   |   |¡S r  r   r  r:   r:   r;   r  N  s    )N)N)r|   r   r  r   ZUnsupportedError)rö  r  r  r:   r:   r;   Únumpy_transposeE  s    

r  ÚTc           	      C   sª   |j dkr|}nŒt|ƒ| ||ƒ}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[   rc   r	   r¤   rQ   r‘   r´   r€   rV   r’   r�   r“   rÌ   r   )	rg   r5   r¾  rß   rÏ   rÖ   r³  r×   r‘   r:   r:   r;   rè  T  s     
úrè  é2   c                 C   sT   t | tjƒst d¡‚t |tjƒs,t d¡‚t |ttjfƒsFt 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 integerr  c                 S   s   t  | ||¡}t  d|¡S )Ng      $@)r¸  ÚlinspaceÚpower)rö   rT  Únumr¤  r:   r:   r;   rÀ   q  s    znumpy_logspace.<locals>.impl)r  )r|   r   rÖ  r   rÁ   r¡   r~   )rö   rT  r  rÀ   r:   r:   r;   Únumpy_logspaceh  s    



r  r=   c                 C   sR   t |ttjfƒst d¡‚t | tjƒs0t d¡‚| jdk rDt d¡‚ddd„}|S )	Nz*The second argument "k" must be an integerú)The first argument "arr" must be an arrayr÷  úInput must be >= 2-d.r=   c                 S   st   |d }|dkr| d d … S |dkr8t  t  | ¡dd¡S |dkrPt  t  | ¡¡S |dkrlt  t  | dd¡¡S t‚d S )Né   r   r=   r÷  é   )r¸  ÚswapaxesÚfliplrÚflipudr   )rt  r²   r:   r:   r;   rÀ   ƒ  s    znumpy_rot90.<locals>.impl)r=   )	r|   r¡   r   r~   r   rÁ   r}   r[   ÚNumbaValueError)rt  r²   rÀ   r:   r:   r;   Únumpy_rot90x  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.
    Znumba_attempt_nocopy_reshaperQ   r   r‘   )r�   r   ru   rù  Zintcr   ÚFunctionTyper	   Zget_or_insert_functionr4   r[   rT   rS   Úcallr’   )rg   r5   rµ   rÖ   ÚnewndÚnewshapeÚ
newstridesr*  Zll_intp_starZll_intcÚfntyÚfnÚndrQ   r‘   Z
is_f_orderrÏ   r:   r:   r;   Ú_attempt_nocopy_reshape“  sD    	     ú
ÿ
 ÿ   þr  c           	      C   s¦   d}d}t |ƒD ]&\}}|dk r.|d7 }|}q||9 }q|dkrR| |kr¢tdƒ‚nP|dkrš|dkrpd}| dk}n| | }| | dk}|s�tdƒ‚|||< ntdƒ‚d S )Nr   r=   z)total size of new array must be unchangedzmultiple negative shape values)rÎ  rœ   )	ÚorigsizerQ   Znum_neg_valueZ
known_sizerû   rŒ   Zneg_axÚinferredÚokr:   r:   r;   Únormalize_reshape_value·  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 5 Q R X t|ƒ| |ƒ}t||
j"| #|¡| #|¡|
j$|
j%|
j&d� | ¡ }t'| ||j|ƒS )	Nr   r=   r‹   rð  ró  r_  zincompatible shape for arrayr  )(rÄ   rÆ   r�   r   ru   r   rø  r¥   rc   r	   rG   rç   r}   re   r£   rf   r´   r‹  rù  r—   rú  r"  r   r    rû  rv   rÌ   r  rb  r3   rã   r  r  rC   r€   r6   r’   r�   r“   r   )rg   r5   rK   rÄ   rµ   Úrettyrä  rQ   r*  Zll_shaperÖ   r  Zshape_ary_tyÚ	shape_aryZshape_itemsizery   r  r  r!  Úfailr­   r³  rÏ   r:   r:   r;   Úarray_reshapeÕ  sd    

ÿû ÿ
ý ÿúr&  c                 C   s    t | |||ƒ\}}t| |||ƒS r  )rç  r&  rþ  r:   r:   r;   Úarray_reshape_vararg  s    r'  c                 C   s   dd„ }|S )Nc                 S   s
   |   |¡S r  )Úreshape)rö  rQ   r:   r:   r;   Únp_reshape_impl  s    z#np_reshape.<locals>.np_reshape_implr:   )rö  rQ   r)  r:   r:   r;   Ú
np_reshape  s    r*  c                 C   s\   t | ƒst d¡‚t |ƒs$t d¡‚t|ƒr8ddd„}n t|tjƒsNt 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©rt  Úvaluesr»   r:   r:   r;   rÀ   .  s    znp_append.<locals>.implz,The third argument "axis" must be an integerc                 S   s   t j| |f|d�S ©N©r»   ©r¸  r,  r-  r:   r:   r;   rÀ   8  s    )N)N)r   r   rÁ   r   r|   r   r~   )rt  r.  r»   rÀ   r:   r:   r;   Ú	np_append#  s    



r2  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(  ry   ©rÖ   r:   r:   r;   Ú
imp_nocopy@  s    zarray_ravel.<locals>.imp_nocopyc                 S   s   |   ¡ S )zCopy version)Úflattenr3  r:   r:   r;   Úimp_copyD  s    zarray_ravel.<locals>.imp_copyr   r‹   )rÄ   rm  rú  r   rÆ   )rg   r5   rK   rÄ   r4  r6  ÚimprÏ   r:   r:   r;   Úarray_ravel=  s    r8  c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   |   ¡ S r  )r+  ©rö  r:   r:   r;   Únp_ravel_implV  s    znp_ravel.<locals>.np_ravel_impl)rú  )rg   r5   rK   rÄ   r:  r:   r:   r;   Únp_ravelT  s    r;  zarray.flattenc                 C   s,   dd„ }|   ||||¡}t| ||j|ƒ}|S )Nc                 S   s   |   ¡  | j¡S r  )r¬  r(  ry   r3  r:   r:   r;   r7  _  s    zarray_flatten.<locals>.imp)rú  r   rÆ   )rg   r5   rK   rÄ   r7  rÏ   r:   r:   r;   Úarray_flatten\  s    r<  c                 C   sl   |d krt  | ¡n|}t  | ||¡\}}}t  |j¡D ]0}|| }	|| }
|| }tt|	|
ƒ|ƒ||< q6|S r  )r¸  Ú
empty_likeÚbroadcast_arraysÚndindexrQ   ÚminrÓ  )rö  Úa_minÚa_maxrÐ   r³  Úa_bÚa_min_bÚa_max_brÈ   Úval_aZ	val_a_minZ	val_a_maxr:   r:   r;   Ú_np_clip_implg  s    rG  c                 C   sH   t  | j¡D ]6}| | }|| }|r4t||ƒ||< qt||ƒ||< q|S r  )r¸  r?  rQ   r@  rÓ  )rö  ÚbZuse_minrÐ   rÈ   rF  Zval_br:   r:   r;   Ú_np_clip_impl_noneu  s    rI  c                 C   sv  t | ƒst d¡‚t|tjƒs0t |ƒs0t d¡‚t|tjƒsNt |ƒsNt d¡‚t|tjƒspt|ƒspd}t |¡‚|d kp‚t|tjƒ}|d kp–t|tjƒ}|r®|r®ddd„}|S t|tjƒ}t|tjƒ}	|rÜ|	rÜddd„}
|
S |�r|	�s|� rüdd	d
„}|S ddd„}|S nf|�s<|	�r<|�r,ddd„}|S ddd„}|S n6|�rPddd„}|S |�rdddd„}|S ddd„}|S d S ) Nú#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ƒ‚d S )Nz&array_clip: must set either max or minr¾   ©rö  rA  rB  rÐ   r:   r:   r;   Ú
np_clip_nnš  s    znp_clip.<locals>.np_clip_nnc                 S   sH   |d krt  | ¡n|}t  | j¡D ] }| | }tt||ƒ|ƒ||< q"|S r  )r¸  r=  r?  rQ   r@  rÓ  ©rö  rA  rB  rÐ   r³  rÈ   rF  r:   r:   r;   Ú
np_clip_ss£  s
    znp_clip.<locals>.np_clip_ssc                 S   sB   |d krt  | ¡n|}t  | j¡D ]}| | }t||ƒ||< q"|S r  )r¸  r=  r?  rQ   rÓ  rM  r:   r:   r;   Ú
np_clip_sn±  s
    znp_clip.<locals>.np_clip_snc                 S   s   t  | |¡}t| |||ƒS r  ©r¸  Ú	full_likerG  )rö  rA  rB  rÐ   Z
a_min_fullr:   r:   r;   Ú
np_clip_sa¾  s    znp_clip.<locals>.np_clip_sac                 S   sB   |d krt  | ¡n|}t  | j¡D ]}| | }t||ƒ||< q"|S r  )r¸  r=  r?  rQ   r@  rM  r:   r:   r;   Ú
np_clip_nsÉ  s
    znp_clip.<locals>.np_clip_nsc                 S   s   t  | |¡}t| |||ƒS r  rP  )rö  rA  rB  rÐ   Z
a_max_fullr:   r:   r;   Ú
np_clip_asÖ  s    znp_clip.<locals>.np_clip_asc                 S   s4   |d krt  | ¡n|}t  | |¡\}}t||d|ƒS )NT©r¸  r=  r>  rI  )rö  rA  rB  rÐ   r³  rC  rE  r:   r:   r;   Ú
np_clip_naâ  s    znp_clip.<locals>.np_clip_nac                 S   s4   |d krt  | ¡n|}t  | |¡\}}t||d|ƒS )NFrU  )rö  rA  rB  rÐ   r³  rC  rD  r:   r:   r;   Ú
np_clip_anê  s    znp_clip.<locals>.np_clip_anc                 S   s   t | |||ƒS r  )rG  rK  r:   r:   r;   Ú
np_clip_aaò  s    znp_clip.<locals>.np_clip_aa)N)N)N)N)N)N)N)N)N)	r   r   rÁ   r|   r   ÚNoneTyper}   r   rÖ  )rö  rA  rB  rÐ   r­   Za_min_is_noneZa_max_is_nonerL  Za_min_is_scalarZa_max_is_scalarrN  rO  rR  rS  rT  rV  rW  rX  r:   r:   r;   Únp_clip�  sV    
ÿ
ÿ










rZ  Úclipc                 C   s   ddd„}|S )Nc                 S   s   t  | |||¡S r  )r¸  r[  rK  r:   r:   r;   rÀ   ý  s    zarray_clip.<locals>.impl)NNNr:   )rö  rA  rB  rÐ   rÀ   r:   r:   r;   Ú
array_clipû  s    
r\  c              	      sÔ  |j |j kst‚|j|jks t‚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r2|d |krˆˆƒ}n|d |kr2ˆˆƒ}||krN|ˆ ksJ| dkrNdS |ˆkr`| d }nd}||k rž|| dkr|dS || }||  |9  < |||< n:||krØ|| | }|| dkrÂdS || ||< |||< n dS )Nr  r   Fr=   Tr:   )	r  rX   r‘   Úold_itemsizeÚnew_itemsizerm  rY   ÚnewdimZ
bytelength©Z
any_layoutZc_layoutZf_layoutÚint8r:   r;   r7  	  s.    



z_change_dtype.<locals>.imprQ   r   r‘   r=   rð  Nró  )r[   r   rm  Úordr   rb  r£   ru   ri   r	   rT   rS   r}   rc   rV   rf   rd   r´   rÌ   r    Úbooleanrú  r¶   r   rÆ   )rg   r5   ZoldtyÚnewtyrÖ   Z
new_layoutr7  r^  r_  r  Z
shape_dataZstrides_dataZshape_strides_array_typeÚaryclsZshape_constantZsizeof_intpZstrides_constantr$  Zstrides_aryrQ   r‘   rÄ   rK   rÏ   r:   ra  r;   Ú_change_dtype	  s†    	
0ÿÿ ÿ  ÿ
ÿÿ
û
û
ÿú	
rg  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¹  rQ   r9  r:   r:   r;   rÀ   …	  s    znp_shape.<locals>.impl©r   r   rÁ   ©rö  rÀ   r:   r:   r;   Únp_shape€	  s    
rj  c                 C   s   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 r:   r:   )rƒ   rY   r£  ©rH  r:   r;   r…   ‘	  s      z5np_unique.<locals>.np_unique_impl.<locals>.<listcomp>)r¸  Úsortr+  r    rÎ  r«   )rö  ÚheadÚtailr:   rk  r;   Únp_unique_implŽ	  s    z!np_unique.<locals>.np_unique_implr:   )rö  ro  r:   r:   r;   Ú	np_uniqueŒ	  s    rp  c                 C   sh   dd„ }t | tjtjtjtjtjfƒrdt |tjƒr6tS t |tjtjfƒrZt |j	tjƒrZ|S t
 d¡‚d S )Nc           	      S   sÂ   t j|t jd�}|jd dkr,t| |d ƒS t  |dk ¡rBtdƒ‚t  | ¡}| ¡ }|jd }|j|jkrrtdƒ‚t jt  	|¡|j
d�}d}t|ƒD ](}|| |||||  …< ||| 7 }q”|S )N©re   r   r=   rÄ  z(operands could not be broadcast together)r¸  r¹  Zint64rQ   Únp_repeat_impl_repeats_scalerr  rœ   r+  Úemptyr]  re   r2   )	rö  ÚrepeatsZrepeats_arrayÚasaÚaravelÚnÚ	to_returnÚposrY   r:   r:   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Ö  rX  r~   rr  re   r   rÁ   )rö  rt  rz  r:   r:   r;   Ú	np_repeat–	  s    üÿr|  c                 C   sœ   |dk rt dƒ‚t | ¡}| ¡ }|jd }|dkrDtjd|jd�S |dkrVt |¡S tj|| |jd�}t|ƒD ] }|| ||| |d | …< qr|S d S )Nr   rÄ  rq  r=   )	rœ   r¸  r¹  r+  rQ   rs  re   r¬  r2   )rö  rt  ru  rv  rw  rx  rY   r:   r:   r;   rr  Ã	  s    


rr  Úrepeatc                 C   s   dd„ }|S )Nc                 S   s   t  | |¡S r  )r¸  r}  )rö  rt  r:   r:   r;   Úarray_repeat_impl×	  s    z'array_repeat.<locals>.array_repeat_implr:   )rö  rt  r~  r:   r:   r;   Úarray_repeatÕ	  s    r  c                 C   s   t  |¡}dd„ }||fS )z"Computes the itemsize of the dtypec                 S   s,   |   |jd j¡}|   |j¡}||  |¡ƒS r½   )rd   rÄ   re   rÆ   rf   )Úcgctxr5   rK   Úllargsrh   Zllintpr:   r:   r;   r±  â	  s    z%_intrin_get_itemsize.<locals>.codegen)r   ru   )Útyctxre   rK   r±  r:   r:   r;   Ú_intrin_get_itemsizeÝ	  s    
rƒ  c                 C   s   d S r  r:   )rö  re   r:   r:   r;   Ú_compatible_viewé	  s    r„  Zgeneric)Útargetc                 C   s   dd„ }|S )zDDetermines if the array and dtype are compatible for forming a view.c                 S   sÎ   t |ƒ}|| jkrÊ| jdkr*d}t|ƒ‚n | jd }| j| dk}| jdk}| j| | jk}|rt|rt|rtd}t|ƒ‚|| jk r¢|dks”| j| dkrÊd}	t|	ƒ‚n(| j| | j }
|
| dkrÊd}t|ƒ‚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œ   rQ   ry   r‘   )rö  re   Z
dtype_sizeZmsg1r»   Úp1Úp2Zp3Zmsg2Zmsg3r`  Zmsg4r:   r:   r;   rÀ   ó	  s(    






z ol_compatible_view.<locals>.implr:   ©rö  re   rÀ   r:   r:   r;   Úol_compatible_viewí	  s    #r‰  z
array.viewc              	   C   s,  |j d }|j}t|ƒ| ||d ƒ}t|ƒ| |ƒ}t|jjƒ}t|ƒD ]:}	t||	ƒ}
|	dkrt|jj	}| 
|
|¡|_qFt||	|
ƒ qFtdkrÂ| j}| t¡}| ||j ˜i ¡}|  ||¡}|||ƒ t| ||||ƒ}| d|t|j	dƒ¡}| |¡� d}| j |t|f¡ W 5 Q R X | ¡ }t| ||j|ƒS )Nr   r€   )r=   é   r_  z"new type not compatible with array)rÄ   rÆ   rc   rš   r˜   r›   ÚsortedÚgetattrr€   r3   r‹  rª   r   Ztyping_contextZresolve_value_typer„  Zget_call_typerB   rg  rb  r   rã   r  r  rœ   rÌ   r   )rg   r5   rK   rÄ   rµ   r#  rÖ   r³  Úfieldsr²   rq   r„  r‚  r  Z_compatible_view_sigrÀ   r!  r%  r­   rÏ   r:   r:   r;   Ú
array_view
  s0    



rŽ  re   c                 C   s   |   ¡ }t| |||ƒS r  )r  r   ©rg   r5   r¾  rß   rÏ   r:   r:   r;   Úarray_dtypeD
  s    r�  rQ   c                 C   s(   t |ƒ}|| ||ƒ}|j}t| |||ƒS r  )rc   rQ   r   ©rg   r5   r¾  rß   rn   r«   rÏ   r:   r:   r;   Úarray_shapeJ
  s    r’  r‘   c                 C   s(   t |ƒ}|| ||ƒ}|j}t| |||ƒS r  )rc   r‘   r   r‘  r:   r:   r;   Úarray_stridesS
  s    r“  r[   c                 C   s   |   tj|j¡}t| |||ƒS r  )r£   r   ru   r[   r   r�  r:   r:   r;   Ú
array_ndim\
  s    r”  ry   c                 C   s(   t |ƒ}|| ||ƒ}|j}t| |||ƒS r  )rc   r—   r   r‘  r:   r:   r;   Ú
array_sizec
  s    r•  r’   c                 C   s(   t |ƒ}|| ||ƒ}|j}t| |||ƒS r  )rc   r’   r   r‘  r:   r:   r;   Úarray_itemsizek
  s    r–  Únbytesc                 C   s2   t |ƒ}|| ||ƒ}| |j|j¡}t| |||ƒS )z"
    nbytes = size * itemsize
    )rc   r¦   r—   r’   r   r‘  r:   r:   r;   Úarray_nbytest
  s    r˜  Ú
contiguousc                 C   s   |   tj|j¡}t| |||ƒS r  )r£   r   rd  Ú	is_contigr   r�  r:   r:   r;   Úarray_contiguous€
  s    r›  Úc_contiguousc                 C   s   |   tj|j¡}t| |||ƒS r  )r£   r   rd  Zis_c_contigr   r�  r:   r:   r;   Úarray_c_contiguous†
  s    r�  Úf_contiguousc                 C   s   |   tj|j¡}t| |||ƒS r  )r£   r   rd  Zis_f_contigr   r�  r:   r:   r;   Úarray_f_contiguousŒ
  s    rŸ  r¯  c                 C   s    |   tj|j ¡}t| |||ƒS r  )r£   r   rd  Úmutabler   r�  r:   r:   r;   Úarray_readonly’
  s    r¡  Úctypesc           	      C   sP   t |ƒ}|| ||ƒ}t |¡}|  ||¡}|j|_|j|_| ¡ }t| |||ƒS r  )rc   r   ÚArrayCTypesrÅ   r€   r�   rÌ   r   )	rg   r5   r¾  rß   rn   r«   ZactÚctinforÏ   r:   r:   r;   Úarray_ctypesš
  s    
r¥  r€   c                 C   s8   | j |||d�}|j}| ||  tj¡¡}t| |||ƒS ©NrÞ   )rÅ   r€   rv  r�   r   ru   r   )rg   r5   r¾  rß   r¤  rÏ   r:   r:   r;   Úarray_ctypes_data§
  s    r§  c                 C   s6   | j |||d�}|j}| ||  |¡¡}t| |||ƒS r¦  )rÅ   r€   r‹  r�   r   )rg   r5   ÚfromtyÚtotyrq   r¤  rÏ   r:   r:   r;   Úarray_ctypes_to_pointer°
  s    rª  c           
      C   sr   t |ƒ|||d�}t tj|j¡}| | |j¡¡}ttj	||tjƒ}|j
|j| tj|¡g}| || ||¡}	|	S )a)  Helper to invoke the contiguous checker function on an array

    Args
    ----
    checker :
        ``numba.numpy_supports.is_contiguous``, or
        ``numba.numpy_supports.is_fortran``.
    context : target context
    builder : llvm ir builder
    aryty : numba type
    ary : llvm value
    rÞ   )rc   r   rÀ  ru   r[   rf   r�   re   r    Zbool_rQ   r‘   r£   rú  )
Úcheckerrg   r5   rµ   rÖ   Ztup_intpr’   Z	check_sigZ
check_argsrš  r:   r:   r;   Ú_call_contiguous_check¹
  s    ÿ
ÿr¬  r–   c                 C   s>   |   |t |¡¡}||_| ¡ }| j |||¡ t| |||ƒS r  )rÅ   r   Ú
ArrayFlagsr“   rÌ   rÊ   rË   r   )rg   r5   r¾  rß   ÚflagsobjrÏ   r:   r:   r;   Úarray_flagsÓ
  s
    r¯  c                 C   sZ   |j jdkr2| j|||d�}tt| ||j |jƒ}n|j jdk}|  tj|¡}t	| |||ƒS )Nr‹   rÞ   )
rO   rm  rÅ   r¬  r   r“   r£   r   rd  r   )rg   r5   r¾  rß   r®  rÏ   rq   r:   r:   r;   Úarray_flags_c_contiguousÜ
  s     ÿr°  c                 C   sr   |j jdkr2| j|||d�}tt| ||j |jƒ}n2|j j}|j jdkrN|dkn|dk}|  tj	|¡}t
| |||ƒS )Nr]  rÞ   r=   rr  )rO   rm  rÅ   r¬  r   r“   r[   r£   r   rd  r   )rg   r5   r¾  rß   r®  rÏ   rm  rq   r:   r:   r;   Úarray_flags_f_contiguousê
  s     ÿr±  Úrealc                 C   sL   |j tjkrt| |||dd�S |j tjkr8t| |||ƒS td tj ¡ƒ‚d S )Nr²  ©Úattrzunsupported .real for {})	re   r   Úcomplex_domainÚarray_complex_attrÚnumber_domainr   rC   r¨   r3   )rg   r5   r¾  rß   r:   r:   r;   Úarray_real_partû
  s
    r¸  Úimagc                 C   s¤   |j tjkrt| |||dd�S |j tjkr�t|jdd�|ƒ}t| |||gƒ\}}t| |||ƒ}t	 
||j| |j|j¡d¡ t| ||j| ¡ ƒS td tj ¡ƒ‚d S )Nr¹  r³  Trµ  r   zunsupported .imag for {})re   r   rµ  r¶  r·  r    r¬  Ú_parse_empty_like_argsrk  r	   Úmemsetr€   r¦   r’   r—   r   rÆ   rÌ   rC   r¨   r3   )rg   r5   r¾  rß   rK   r­  r×   rÖ   r:   r:   r;   Úarray_imag_part  s    ÿÿ
ÿr¼  c                 C   sÞ   |dks|j tjkr"td |¡ƒ‚t|ƒ}|| ||ƒ}|j j}|  |  |¡¡}|j	 
|¡}	|  |¡ ¡ }
| |j|
¡}|dkr–| |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
          ^   ^   ^
    )r²  r¹  zcannot get attribute `{}`r¹  é    r=   rª  ©re   rm  )r€   r’   )re   r   rµ  rC   r¨   rc   Zunderlying_floatrf   rd   r’   r3   r�   rù  r‹  r€   rn  r   ÚIntTyper¬  r¢   r	   Zcopy_structr   rÌ   )rg   r5   r¾  rß   r´  rn   r«   ZfltyZsizeof_fltyr’   Z
llfltptrtyrÙ   Zresulttyrè   Úreplr:   r:   r;   r¶    s     r¶  ÚconjÚ	conjugatec                 C   s   dd„ }|S )Nc                 S   s
   t  | ¡S r  )r¸  rÁ  ©rt  r:   r:   r;   rÀ   Q  s    zarray_conj.<locals>.implr:   ©rt  rÀ   r:   r:   r;   Ú
array_conjN  s    rÅ  c                 C   s   |   ¡ S r  )r  )rg   r5   ZdtypetyZdtypevalr:   r:   r;   Ú
dtype_typeY  s    rÆ  r3   ÚkindZstatic_getitemc                 C   s@   |j }t|tjƒr.|  |¡dƒ}t| |||ƒS d}t |¡‚dS )zåThis handles the "static_getitem" when a Numba type is subscripted e.g:
    var = typed.List.empty_list(float64[::1, :])
    It only allows this on simple numerical types. Compound types, like
    records, are not supported.
    NzlUnreachable; the definition of __getitem__ on the numba.types.abstract.Type metaclass should prevent access.)rÆ   r|   r   r}   r�   r   r   ZLoweringError)rg   r5   rK   rÄ   r#  rÏ   r­   r:   r:   r;   Ústatic_getitem_number_clazzf  s    rÈ  c              	      s„  t |ƒ}|ˆ ||ƒ}|j}t|tjƒs6td||f ƒ‚| |¡}| |¡}	t|tjƒrr|j	|j|j
|j
 dd�}
n|j	|dd�}
t |
ƒ}|ˆ |ƒ}ˆ  tj|	¡}tj||j||jjd�}t|tjƒ�r.t ||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ª  rð  r¾  )rÆ   c                    s   g | ]}ˆ   tj|¡‘qS r:   ©r£   r   ru   r[  ©rg   r:   r;   r…      s     z(array_record_getattr.<locals>.<listcomp>c                    s   g | ]}ˆ   tj|¡‘qS r:   rÉ  r[  rÊ  r:   r;   r…   £  s     r  )rc   re   r|   r   ÚRecordrC   ÚtypeofrØ   ÚNestedArrayr¬  r[   r£   ru   r	   rÓ   r€   r3   r¤   rQ   r‘   rf   rd   r´   r�   r“   rÌ   r   )rg   r5   r¾  rß   r´  rn   r«   Zrectypere   rØ   ZrestyZrarytyZraryZconstoffsetZ
newdataptrrQ   r‘   ZdatasizerÏ   r:   rÊ  r;   Úarray_record_getattr~  sX    ÿ

 
 ÿ
   ÿúrÎ  c                 C   s0   |d }t |tƒst‚t| ||jd |d |ƒS rC  )r|   ÚstrrC   rÎ  rÄ   )rg   r5   rK   rÄ   rÈ   r:   r:   r;   Úarray_record_getitem¶  s    
rÐ  c              	      s  ˆ   ||¡ | |¡}| |¡}t|tjƒrÊt|ƒ}|ˆ |ƒ}|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rêdnd}ˆ  ||||¡}tˆ |||ƒS dS )zT
    Generic getattr() implementation for records: get the given record member.
    c                    s   g | ]}ˆ   tj|¡‘qS r:   rÉ  ©rƒ   rŒ   rÊ  r:   r;   r…   Î  s     z"record_getattr.<locals>.<listcomp>c                    s   g | ]}ˆ   tj|¡‘qS r:   rÉ  rÑ  rÊ  r:   r;   r…   Ð  s     Nr  r=   )Úsentry_record_alignmentrØ   rÌ  r|   r   rÍ  rc   re   rQ   r‘   r	   Úget_record_memberrd   r´   rV   r£   ru   ry   rÌ   r   rl   rm   )rg   r5   r¾  rß   r´  rØ   Úelemtyrµ   rÖ   re   r  r  ÚnewdatarÏ   Údptrrk   r:   rÊ  r;   Úrecord_getattr¿  sB    



ÿ
ÿ
ÿ

ù	
ÿr×  c              	   C   sÚ   |j \}}|\}}|  ||¡ | |¡}	| |¡}
t|
tjƒrŽt |¡| ||d d�}|j	}t 
|||	|jj¡}t ||||  tj|
j¡¡ nHt 
|||	|  |
¡¡}|  ||||
¡}|jr¾dnd}| j||
|||d� dS )zT
    Generic setattr() implementation for records: set the given record member.
    r=   rÞ   Nrj   )rÄ   rÒ  rØ   rÌ  r|   r   rÍ  r	   rb   r€   rÓ  r3   ZpointeeZmemcpyr£   ru   r—   rd   rt   rl   rp   )rg   r5   rK   rÄ   r´  r¾  r  r…  rq   rØ   rÔ  Z
val_structr’  r°  rÖ  rk   r:   r:   r;   Úrecord_setattrç  s,    


ÿ
ÿ
ÿ
ÿrØ  c                 C   s4   |   |jd |d ¡}|| ||jd |d |d ƒS )ú3
    Record.__getitem__ redirects to getattr()
    r   r=   )Úget_getattrrÄ   )rg   r5   rK   rÄ   rÀ   r:   r:   r;   Úrecord_static_getitem_str  s    rÛ  c                 C   s^   |j d j}t|j d jƒ}|  |j|| ¡}|  |j d |¡}|| ||j d |d || ƒS )rÙ  r=   r   )rÄ   rÂ   r    r�  Zinsert_const_stringr4   rÚ  )rg   r5   rK   rÄ   rx   r�  Zll_fieldrÀ   r:   r:   r;   Úrecord_static_getitem_int  s
    rÜ  Zstatic_setitemc                 C   sJ   |j \}}}|\}}}	t|j||ƒ}
|  ||
¡}|dk	s<t‚||||	fƒS )ú3
    Record.__setitem__ redirects to setattr()
    N)rÄ   r    rÆ   Úget_setattrr   )rg   r5   rK   rÄ   Úrectyro  r  Úrecrx   rq   Úgetattr_sigrÀ   r:   r:   r;   Úrecord_static_setitem_str  s    
râ  c                 C   s^   |j \}}}|\}}}	t|j||ƒ}
t|j d jƒ}|  || |
¡}|dk	sPt‚||||	fƒS )rÝ  r   N)rÄ   r    rÆ   r    r�  rÞ  r   )rg   r5   rK   rÄ   rß  ro  r  rà  rx   rq   rá  r�  rÀ   r:   r:   r;   Úrecord_static_setitem_int'  s    
rã  c                 C   s   |   |||¡S )zB
    Create a constant array (mechanism is target-dependent).
    )Úmake_constant_array)rg   r5   r
  Úpyvalr:   r:   r;   Úconstant_array9  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¿  r—  Ú	bytearrayÚtostringr	   rÇ   )rg   r5   r
  rå  Zltyrq   r:   r:   r;   Úconstant_recordA  s    rê  c                 C   s"   t jt|ƒt jd�}|  |||¡S )zM
    Create a constant array from bytes (mechanism is target-dependent).
    rq  )r¸  r«   rè  Zuint8rä  )rg   r5   r
  rå  Úbufr:   r:   r;   Úconstant_bytesK  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  )rQ   r‘   r¢  r€   ©rö  rH  r:   r:   r;   Úarray_is_impl]  s
    
ÿþzarray_is.<locals>.array_is_impl)rÄ   r	   r`  rú  )rg   r5   rK   rÄ   ÚatyZbtyrî  r:   r:   r;   Úarray_isW  s
    
rð  Ú__hash__c                 C   s   dd„ S )Nc                 S   s   d S r  r:   rÃ  r:   r:   r;   rÊ  j  rË  zol_array_hash.<locals>.<lambda>r:   rÃ  r:   r:   r;   Úol_array_hashh  s    rò  c                 C   s
   t | dƒS )zq
    Return the Structure representation of the given *flatiterty* (an
    instance of types.NumpyFlatType).
    Úflat©Ú_make_flattening_iter_cls)Ú
flatitertyr:   r:   r;   Úmake_array_flat_clsp  s    r÷  c                 C   s
   t | dƒS )zv
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdEnumerateType).
    Úndenumeraterô  ©Únditertyr:   r:   r;   Úmake_array_ndenumerate_clsx  s    rû  c              
   C   sþ   |   tjd¡}| d¡}	|d k	r.| tj|¡ tt|ƒƒD ]”}
t 	|||
¡}t 
|| |¡¡}||
 }| d||¡}t ||¡�, | ||¡ |d k	rž||
ƒ | |	¡ W 5 Q R X | ||¡ |d k	r:||
ƒ q:|d k	ræ| tj|¡ | |	¡ | |	¡ d S )Nr   Zend_incrementrà   )r£   r   ru   r,  rç   r	   Ú
false_byteri  r2   rT   ræ   r6   rá   Ú	if_likelyr4  Ú	true_byter5  )rg   r5   r[   rQ   r‰   Úend_flagÚloop_continueÚ
loop_breakrÎ   Úbbendr)  Úidxptrrx   r¥   Ú	in_boundsr:   r:   r;   Ú_increment_indices€  s*    


r  c                 C   s*   t  ||j|j¡}t| ||j|||ƒ d S r  )r	   r¤   rQ   r[   r  )rg   r5   rs  rt  r‰   rÿ  rQ   r:   r:   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[   )rI   r  r  r	  r
  r:   r:   r;   r+  ¶  s
    z-make_nditer_cls.<locals>.BaseSubIter.__init__c                 S   s   t | j| j|ƒ d S r  )rª   r  r  )rI   rW   r:   r:   r;   Úset_member_ptr½  s    z3make_nditer_cls.<locals>.BaseSubIter.set_member_ptrc                 S   s   t | j| jƒS r  )rŒ  r  r  r   r:   r:   r;   Ú
member_ptrÀ  s    z/make_nditer_cls.<locals>.BaseSubIter.member_ptrc                 S   s   d S r  r:   ©rI   rg   r5   r:   r:   r;   Úinit_specificÄ  s    z2make_nditer_cls.<locals>.BaseSubIter.init_specificc                 S   s   d S r  r:   ©rI   rg   r5   Úlogical_dimr:   r:   r;   r   Ç  s    z2make_nditer_cls.<locals>.BaseSubIter.loop_continuec                 S   s   d S r  r:   r  r:   r:   r;   r  Ê  s    z/make_nditer_cls.<locals>.BaseSubIter.loop_breakN)r\   r]   r^   r'  r+  r  r™  Úcached_propertyr  r  r   r  r:   r:   r:   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   ru   r  r	   rÇ   )rI   rg   r5   rÎ   r:   r:   r;   r  Ó  s    z2make_nditer_cls.<locals>.FlatSubIter.init_specificc                 S   s   |  | j¡}| |j|g¡S r  )r6   r  rn  r€   )rI   rg   r5   r‰   rs  rt  rÈ   r:   r:   r;   Úcompute_pointer×  s    z4make_nditer_cls.<locals>.FlatSubIter.compute_pointerc                 S   s8   || j d kr4| | j¡}t ||¡}| || j¡ d S r;  )r[   r6   r  r	   ræ   rç   )rI   rg   r5   r  rÈ   r:   r:   r;   r   Û  s    z2make_nditer_cls.<locals>.FlatSubIter.loop_continuec                 S   s^   |dkr&|  tjd¡}| || j¡ n4|| jd krZ| | j¡}t ||¡}| || j¡ d S ©Nr   r=   )	r£   r   ru   rç   r  r[   r6   r	   ræ   )rI   rg   r5   r  rÎ   rÈ   r:   r:   r;   r  â  s    z/make_nditer_cls.<locals>.FlatSubIter.loop_breakN)r\   r]   r^   r'  r  r  r   r  r:   r:   r:   r;   ÚFlatSubIterÍ  s
   r  c                       s$   e Zd ZdZ‡ fdd„Zdd„ ZdS )z+make_nditer_cls.<locals>.TrivialFlatSubIterzx
        Sub-iterator walking a contiguous array in physical order,
        *without* support for broadcasting.
        c                    s   ˆ j r
t‚d S r  )Úneed_shaped_indexingr   r  rù  r:   r;   r  ó  s    z9make_nditer_cls.<locals>.TrivialFlatSubIter.init_specificc                 S   s&   t |ƒdkstt |ƒƒ‚| |j|¡S r;  )r†   r   rn  r€   ©rI   rg   r5   r‰   rs  rt  r:   r:   r;   r  ö  s    z;make_nditer_cls.<locals>.TrivialFlatSubIter.compute_pointerN)r\   r]   r^   r'  r  r  r:   rù  r:   r;   ÚTrivialFlatSubIterí  s   r  c                   @   s   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t‚tj|||||dd�S ©NFr|  )r†   r[   r   r	   rø   r  r:   r:   r;   r  ÿ  s
     ÿz7make_nditer_cls.<locals>.IndexedSubIter.compute_pointerN©r\   r]   r^   r'  r  r:   r:   r:   r;   ÚIndexedSubIterú  s   r  c                   @   s   e Zd ZdZdd„ ZdS )z'make_nditer_cls.<locals>.ZeroDimSubIterz5
        Sub-iterator "walking" a 0-d array.
        c                 S   s   |j S r  r�  r  r:   r:   r;   r  	  s    z7make_nditer_cls.<locals>.ZeroDimSubIter.compute_pointerNr  r:   r:   r:   r;   ÚZeroDimSubIter  s   r  c                   @   s   e Zd ZdZdd„ ZdS )z&make_nditer_cls.<locals>.ScalarSubIterz8
        Sub-iterator "walking" a scalar value.
        c                 S   s   |S r  r:   r  r:   r:   r;   r    s    z6make_nditer_cls.<locals>.ScalarSubIter.compute_pointerNr  r:   r:   r:   r;   ÚScalarSubIter  s   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 ]8\}}|\}}}}d| }	|| }
| |
| |	||ƒ¡ q&|S )N)ró  ZindexedZ0dZscalarzindex%d)r  rÎ  rY  rU   )rI   ÚlZ	factoriesrY   rc  rÇ  r	  r
  ro  r  Úfactory)r  r  r  r  r  rú  r:   r;   Úsubiters  s    
üz(make_nditer_cls.<locals>.NdIter.subitersc                    s@  |  tjd¡}| |t |¡|¡| _t|ƒD ]8\}}t|tjƒs,d| }t	 
||| ¡}	t| ||	ƒ q,|  ||||¡}t tjˆ¡}
d}d}t|ƒD ]6\}}t|tjƒr”|jˆkr”|| j}|| j} qôq”ˆdksØt‚| ||
d¡}|  tjd¡}dd„ }t||ƒD ]T\}}t|tjƒ�r|jdk�rttjt tj|j¡|
ƒ}| ||||j|f¡ �qt	 ||¡}ˆ dk�r€|ddd	… }| d
||¡}| |t	jt	j¡}ˆj�s®|f}t|ƒˆk�sÀt‚t	j||jˆd�}tˆƒD ] }t	  |||¡}| !||¡ �qÚ|| _"t	 #|||j¡| _t	 
||¡| _$| j%D ]}| &||¡ �q(dS )zY
            Initialize the nditer() instance for the specific array inputs.
            r   úscalar%dNr:   r=   c                 S   s>   t | ƒ}t|ƒD ](}| | |t |ƒ| |  krtdƒ‚qd S )Nz2nditer(): operands could not be broadcast together)r†   r2   rœ   )rQ   Ú
main_shaperw  rY   r:   r:   r;   Úcheck_shapeO  s    zBmake_nditer_cls.<locals>.NdIter.init_specific.<locals>.check_shaper]  r  r_  r0  )'r£   r   ru   Ú
make_tuplerÁ  ÚarraysrÎ  r|   r}   r	   rÇ   rª   Ú_arrays_or_scalarsrÀ  r[   rQ   r—   r   r‡   r    Únonerú  r¤   rá   rS  rþ  rü  r  r†   rG   r3   r2   rT   rç   r‰   rV   Ú	exhaustedr   r  )rI   rg   r5   Úarrtysr%  rÎ   rY   r
  r  ZslotZmain_shape_tyr"  Zmain_nitemsrs  r#  rt  rK   r×   Zshape_is_emptyr(  r‰   r)  r  Úsubiter)rm  r[   rú  Únshapesr:   r;   r  ,  sf    ÿ

þ ÿ

ÿ
z-make_nditer_cls.<locals>.NdIter.init_specificc                    s*  |  d¡}t || | j¡¡}t ||¡� | d¡ | |¡ W 5 Q R X ˆ j}t 	|| j¡}|  
||||¡}| j}| d¡ |  |||||¡}	dd„ |	D ƒ}	t|	ƒdkrº| |	d ¡ n| | |ˆ j|	¡¡ t 	|| j¡}
t||t|
ƒ|
|| jt | j||¡t | j||¡ƒ | |¡ | |¡ dS )	zJ
            Compute next iteration of the nditer() instance.
            rw  FTc                 S   s   g | ]}|  ¡ ‘qS r:   rô  ©rƒ   r³   r:   r:   r;   r…   �  s     zEmake_nditer_cls.<locals>.NdIter.iternext_specific.<locals>.<listcomp>r=   r   N)r,  r	   Úas_bool_bitr6   r(  Úif_unlikelyrâ   r4  r%  r¤   r&  r‰   Ú_make_viewsr†   rå   r$  rä   rQ   r  r™  ÚpartialÚ_loop_continueÚ_loop_breakr5  )rI   rg   r5   rè   r  r(  r)  r%  r‰   ÚviewsrQ   rù  r:   r;   Úiternext_specific{  sD    

ÿ

ÿ þþû

z1make_nditer_cls.<locals>.NdIter.iternext_specificc                 S   s@   | j D ]4}|j|  kr"|jk rn q| ||||j ¡ qd S r  )r   r	  r
  r   ©rI   rg   r5   r)  rc  r:   r:   r;   r1  ¥  s    
z.make_nditer_cls.<locals>.NdIter._loop_continuec                 S   s@   | j D ]4}|j|  kr"|jk rn q| ||||j ¡ qd S r  )r   r	  r
  r  r5  r:   r:   r;   r2  ª  s    
z+make_nditer_cls.<locals>.NdIter._loop_breakc                    sð   dgˆ }ˆj }| j}ˆj}	t|	tjƒr2t|	ƒ}	n|	g}	‡ ‡fdd„tˆƒD ƒ‰t||ƒD ]z\}
}|
\}}}}ˆ|j	|j
… }ˆdkr”|ddd… }|D ]:}|| dks¬t‚|  |ˆ ||	| || || |¡||< q˜qZtdd„ |D ƒƒsìt‚|S )z:
            Compute the views to be yielded.
            Nc              	      s    g | ]}ˆ   t ˆ ˆ|¡¡‘qS r:   ©r6   r	   rT   r[  ©r5   r‰   r:   r;   r…   »  s   ÿz?make_nditer_cls.<locals>.NdIter._make_views.<locals>.<listcomp>r]  r  c                 s   s   | ]
}|V  qd S r  r:   r,  r:   r:   r;   r  È  s     z>make_nditer_cls.<locals>.NdIter._make_views.<locals>.<genexpr>)rY  r   rä   r|   r   r  r    r2   r‡   r	  r
  r   Ú
_make_viewrÂ  )rI   rg   r5   r‰   r)  r%  r3  rY  r   Úrettysrc  r*  ro  Zarray_indicesZsub_indicesrY   )rm  Únarraysrú  r+  r7  r;   r/  ¯  s2    

ÿ
  þz+make_nditer_cls.<locals>.NdIter._make_viewsc                 S   sŽ   t |tjƒr|jdkst‚| |||||¡}| |¡||ƒ}	t||ƒ}
| |t 	tj
d¡d¡}| |t 	tj
d¡d¡}t|	||||
dd� |	S )zD
            Compute a 0d view for a given input array.
            r   r:   N)r�   )r|   r   r}   r[   r   r  rc   ri   r$  rÀ  ru   r´   )rI   rg   r5   r‰   r#  rs  rt  r*  rW   Úviewr’   rQ   r‘   r:   r:   r;   r8  Ë  s    
ÿÿz*make_nditer_cls.<locals>.NdIter._make_viewc           	      S   s`   g }t t||ƒƒD ]H\}\}}t|tjƒrF| | |¡|||d�¡ q| t| d| ƒ¡ q|S )NrÞ   r!  )rÎ  r‡   r|   r   r}   rU   rc   rŒ  )	rI   rg   r5   r)  r%  r  rY   rs  rt  r:   r:   r;   r&  ß  s    þ
z2make_nditer_cls.<locals>.NdIter._arrays_or_scalarsN)r\   r]   r^   r'  r™  r  r   r  r4  r1  r2  r/  r8  r&  r:   ©
r  r  r  r  r  rm  r:  r[   rú  r+  r:   r;   ÚNdIter  s   O*r=  )r[   rm  r†   r%  r  Úobjectr	   rb   )rú  r  r=  r:   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 ]Z}t 	|||¡}| 
||¡ || }	| d|	|¡}
t ||
¡� | 
tj|¡ W 5 Q R X q@|| _|| _t |||j¡| _d S ©Nr   r0  r_  )r£   r   ru   r	   rG   r3   rÇ   rü  r2   rT   rç   rb  r.  rþ  r‰   r(  rV   rQ   )rI   rg   r5   r×   rÎ   r‰   r(  r)  r  rN  Údim_is_empty©r[   r:   r;   r  û  s"    
ÿÿz3make_ndindex_cls.<locals>.NdIndexIter.init_specificc           
   	      sâ   |  tjd¡}ˆ  d¡}t ˆ ˆ  ˆj¡¡}t ˆ |¡� | 	d¡ ˆ  
|¡ W 5 Q R X ‡ ‡fdd„tˆƒD ƒ}|D ]}tˆ |ƒ qt| t ˆ ||j¡¡ | 	d¡ t ˆ ˆjˆ¡}	t|ˆ ˆ|	ˆjˆjƒ ˆ  
|¡ ˆ  |¡ d S )Nr   rw  Fc              	      s"   g | ]}ˆ   t ˆ ˆj|¡¡‘qS r:   )r6   r	   rT   r‰   ©rƒ   r)  ©r5   rI   r:   r;   r…     s
   ý
þzKmake_ndindex_cls.<locals>.NdIndexIter.iternext_specific.<locals>.<listcomp>T)r£   r   ru   r,  r	   r-  r6   r(  r.  râ   r4  r2   r?   rå   rV   r3   r¤   rQ   r  r‰   r5  )
rI   rg   r5   rè   rÎ   r  r(  r‰   r6   rQ   rB  rD  r;   r4    s,    

ÿ
ý

 ÿ
z7make_ndindex_cls.<locals>.NdIndexIter.iternext_specificN)r\   r]   r^   r'  r  r4  r:   rB  r:   r;   ÚNdIndexIterö  s   rE  )r[   r	   rb   )rú  rE  r:   rB  r;   Úmake_ndindex_clsï  s    7rF  c                    s\   ˆ dkst ‚| j}|jdkr:G ‡ fdd„dt | ¡ƒ}|S G ‡ fdd„dt | ¡ƒ}|S d 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rztj||j	|  tj|j
¡d�}t|j
ƒD ]}t |||¡}| ||¡ qT|| _d S )Nr   rø  r0  )r£   r   ru   r	   rÇ   rÈ   r’   re  rG   r3   r[   r2   rT   rç   r‰   )	rI   rg   r5   rs  rt  rÎ   r‰   r)  r  ©rÇ  r:   r;   r  ;  s     þzD_make_flattening_iter_cls.<locals>.CContiguousFlatIter.init_specificc              	      sè   |j }|j}ˆ  | j¡}ˆ  d||¡}	| |	¡ t ˆ |	¡�¢ ˆ  |j	|g¡}
t
|ˆ ||
ƒ}ˆdkrp| |¡ nP| j‰‡ ‡fdd„t|ƒD ƒ}t ˆ |¡}| t ˆ ||g¡¡ t|ˆ ||ˆƒ t ˆ |¡}ˆ  || j¡ W 5 Q R X d S )Nrà   ró  c              	      s    g | ]}ˆ   t ˆ ˆ|¡¡‘qS r:   r6  rC  r7  r:   r;   r…   d  s
   ý
þz\_make_flattening_iter_cls.<locals>.CContiguousFlatIter.iternext_specific.<locals>.<listcomp>)r[   r—   r6   rÈ   rá   râ   r	   rý  rn  r€   ro   rå   r‰   r2   rV   Úmake_anonymous_structr  ræ   rç   )rI   rg   r5   rs  rt  rè   r[   r—   rÈ   rê   rW   rß   ÚidxvalsÚidxtuplerG  r7  r;   r4  T  s4    
ýÿÿ ÿzH_make_flattening_iter_cls.<locals>.CContiguousFlatIter.iternext_specificc                 S   s   |  |j|g¡}t||||ƒS r  )rn  r€   ro   ©rI   rg   r5   rs  rt  rÈ   rW   r:   r:   r;   rÚ  r  s    z>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.getitemc                 S   s$   |  |j|g¡}t|||||ƒ d S r  )rn  r€   rr   ©rI   rg   r5   rs  rt  rÈ   rß   rW   r:   r:   r;   Úsetitemv  s    z>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.setitemN)r\   r]   r^   r'  r  r4  rÚ  rM  r:   rG  r:   r;   ÚCContiguousFlatIter6  s
   rN  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 ]t}t ||	|¡}t ||
|¡}| ||¡ | ||¡ || }| d||¡}t ||¡� | tj|¡ W 5 Q R X q||	| _|
| _|| _d S r@  )r£   r   ru   r€   r[   r	   r¤   rQ   rG   r3   rÇ   rü  r2   rT   rç   rb  r.  rþ  r‰   Úpointersr(  )rI   rg   r5   rs  rt  rÎ   r€   r[   r×   r‰   rO  r(  r)  r  ÚptrptrrN  rA  r:   r:   r;   r  …  sB      ÿÿ  ÿÿÿz9_make_flattening_iter_cls.<locals>.FlatIter.init_specificc              
      s"  |j }t ˆ |j|¡}t ˆ |j|¡}| j‰| j}	| tj	d¡}
ˆ  
d¡}t ˆ ˆ  | j¡¡}t ˆ |¡� | d¡ ˆ  |¡ W 5 Q R X | d¡ t ˆ |	|d ¡}ˆ  |¡}t|ˆ ||ƒ}ˆdkrÒ| |¡ n:‡ ‡fdd„t|ƒD ƒ}t ˆ |¡}| t ˆ ||g¡¡ tt|ƒƒD ]à}t ˆ ˆ|¡}t ˆ ˆ  |¡¡}|| }|| }ˆ  d	||¡}t ˆ |¡�~ ˆ  ||¡ t ˆ |	|¡}ˆ  |¡}t ˆ ||¡}ˆ  ||¡ t|d |ƒD ] }t ˆ |	|¡}ˆ  ||¡ �q´ˆ  |¡ W 5 Q R X ˆ  |
|¡ �qˆ  tj| j¡ ˆ  |¡ ˆ  |¡ d S )
Nr   rw  FTr=   ró  c              	      s    g | ]}ˆ   t ˆ ˆ|¡¡‘qS r:   r6  rC  r7  r:   r;   r…   Á  s
   ý
þzQ_make_flattening_iter_cls.<locals>.FlatIter.iternext_specific.<locals>.<listcomp>rà   )r[   r	   r¤   rQ   r‘   r‰   rO  r£   r   ru   r,  r-  r6   r(  r.  râ   r4  rT   ro   rå   r2   rV   rH  ri  ræ   rá   rý  rç   rÓ   rþ  r5  )rI   rg   r5   rs  rt  rè   r[   r×   r‘   rO  rÎ   r  Úis_exhaustedZlast_ptrrW   rß   rI  rJ  r)  r  rx   r¥   re  r  rP  Z	inner_dimrG  r7  r;   r4  ¦  sl    
 
ÿ


ýÿÿÿ
þ
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¤   rQ   r‘   ri  r2   rU   ZuremZudivÚreverserl  r€   rm  )rI   rg   r5   rs  rt  rÈ   r[   r×   r‘   r‰   r)  rW   r:   r:   r;   Ú_ptr_for_indexë  s      þz:_make_flattening_iter_cls.<locals>.FlatIter._ptr_for_indexc                 S   s    |   |||||¡}t||||ƒS r  )rS  ro   rK  r:   r:   r;   rÚ  ü  s    z3_make_flattening_iter_cls.<locals>.FlatIter.getitemc                 S   s&   |   |||||¡}t|||||ƒ d S r  )rS  rr   rL  r:   r:   r;   rM     s    z3_make_flattening_iter_cls.<locals>.FlatIter.setitemN)	r\   r]   r^   r'  r  r4  rS  rÚ  rM  r:   rG  r:   r;   ÚFlatIter}  s   !ErT  )r   rO   rm  r	   rb   )rö  rÇ  rO   rN  rT  r:   rG  r;   rõ  0  s    
D rõ  ró  c                 C   sh   t t |¡ƒ}|| |ƒ}||_|  |¡}|| || d¡d�}| | |||¡ | ¡ }t| |t |¡|ƒS ©Nr«   )rJ   )	r÷  r   ÚNumpyFlatTyper«   rc   rS   r  rÌ   r   )rg   r5   rs  rt  ÚflatiterclsÚflatiterÚarrclsrÏ   r:   r:   r;   Úmake_array_flatiter  s    

rZ  c                 C   sZ   |j \}|\}t|ƒ}|| ||d�}|j}|  |¡}	|	| ||jd�}
| | |||
|¡ d S r¦  )rÄ   r÷  rO   rc   r«   r4  )rg   r5   rK   rÄ   rè   rö  rX  rW  rs  rY  rt  r:   r:   r;   Úiternext_numpy_flatiter  s    
r[  c                 C   sj   |j d }|\}}t|ƒ}|| ||d�}|j}|  |¡}	|	| ||jd�}
| | |||
|¡}t| ||j|ƒS ©Nr   rÞ   )rÄ   r÷  rO   rc   r«   rÚ  r   rÆ   )rg   r5   rK   rÄ   rö  rX  rÈ   rW  rs  rY  rt  rÏ   r:   r:   r;   Úiternext_numpy_getitem'  s    

r]  c                 C   sf   |j d }|\}}}t|ƒ}|| ||d�}|j}	|  |	¡}
|
| ||jd�}| | ||	|||¡ |  ¡ S r\  )rÄ   r÷  rO   rc   r«   rM  r  )rg   r5   rK   rÄ   rö  rX  rÈ   rß   rW  rs  rY  rt  r:   r:   r;   Úiternext_numpy_getitem_any7  s    


r^  c           	      C   sF   |j d }t|ƒ}|| ||d d�}|  |j¡}|| ||jd�}|jS r\  )rÄ   r÷  rc   rO   r«   r—   )	rg   r5   rK   rÄ   rö  rW  rX  rY  rt  r:   r:   r;   Úiternext_numpy_getitem_flatH  s    
r_  c           
      C   sr   |j \}|\}tt |¡ƒ}|| |ƒ}||_|  |¡}|| || d¡d�}| | |||¡ | ¡ }	t	| ||j
|	ƒS rU  )rÄ   rû  r   ÚNumpyNdEnumerateTyper«   rc   rS   r  rÌ   r   rÆ   )
rg   r5   rK   rÄ   rs  rt  Ú	nditerclsr  rY  rÏ   r:   r:   r;   Úmake_array_ndenumerateS  s    

rb  c                 C   sZ   |j \}|\}t|ƒ}|| ||d�}|j}|  |¡}	|	| ||jd�}
| | |||
|¡ d S r¦  )rÄ   rû  rO   rc   r«   r4  )rg   r5   rK   rÄ   rè   rú  r  ra  rs  rY  rt  r:   r:   r;   Úiternext_numpy_nditere  s    
rc  c                    s^   ‡ ‡fdd„t |j|ƒD ƒ}tt t|ƒ¡ƒ}|ˆˆ ƒ}| ˆˆ |¡ | ¡ }tˆˆ |j	|ƒS )zndindex(*shape)c                    s"   g | ]\}}ˆ  ˆ ||tj¡‘qS r:   râ  )rƒ   ZargtyrÏ  r„   r:   r;   r…   y  s   ÿz&make_array_ndindex.<locals>.<listcomp>)
r‡   rÄ   rF  r   ÚNumpyNdIndexTyper†   r  rÌ   r   rÆ   )rg   r5   rK   rÄ   rQ   ra  r  rÏ   r:   r„   r;   Úmake_array_ndindexu  s    
ÿ
re  c           
         s�   |j j}|dkrJ|jd j‰|d }t ˆ ||¡}‡ ‡‡fdd„|D ƒ}ng }tt t	|ƒ¡ƒ}|ˆˆ ƒ}| 
ˆˆ |¡ | ¡ }	tˆˆ |j |	ƒS )zndindex(shape)r   c                    s   g | ]}ˆ  ˆ |ˆtj¡‘qS r:   râ  rí   ©r5   rg   rw   r:   r;   r…   Ž  s   ÿz,make_array_ndindex_tuple.<locals>.<listcomp>)rÆ   r[   rÄ   re   r	   r¤   rF  r   rd  r†   r  rÌ   r   )
rg   r5   rK   rÄ   r[   r  rQ   ra  r  rÏ   r:   rf  r;   Úmake_array_ndindex_tuple„  s    ÿ
rg  c                 C   s6   |j \}|\}t|ƒ}|| ||d�}| | ||¡ d S r¦  )rÄ   rF  r4  )rg   r5   rK   rÄ   rè   rú  r  ra  r:   r:   r;   Úiternext_numpy_ndindex›  s
    rh  c           	      C   sn   |j }|j}t|jd tjƒr0t ||d ¡}n
|d g}t|ƒ| |ƒ}| 	| |||¡ | 
¡ }t| |||ƒS )z
    nditer(...)
    r   )rÆ   r%  r|   rÄ   r   r  r	   r¤   r?  r  rÌ   r   )	rg   r5   rK   rÄ   rú  r)  r%  r  rÏ   r:   r:   r;   Úmake_array_nditer§  s    
ri  c                 C   s2   |j \}|\}t|ƒ| ||d�}| | ||¡ d S r¦  )rÄ   r?  r4  )rg   r5   rK   rÄ   rè   rú  r  r:   r:   r;   Úiternext_numpy_nditer2»  s    rj  c              	   C   sP  t |ƒ}|| |ƒ}|  |j¡}|  tjt| |ƒ¡}|  tjd¡}tt 	d¡dƒ}	|D ]0}
| 
||
¡}| |d¡}| |	| |d¡¡}	qT|jdkr–d}nž|jdkrà|g}t|dd… ƒD ]}| | |d |¡¡ q¶tt|ƒƒ}nT|jdk�r$|g}|dd… D ]}| | |d |¡¡ qþt|ƒ}ntd |j¡ƒ‚| 
||¡}| |d¡}| |	| |d¡¡}	|j|	d	d
�� | j |td¡ W 5 Q R X |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   r:   r‹   Nr  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
  ró  )+rc   rd   re   r£   r   ru   ri   r   r   r¿  Zsmul_with_overflowr  ra  r[   rm  ri  rU   r¦   rŸ   rC   r¨   rã   r  r  rœ   Zget_preferred_array_alignmentZuint32r  ÚMemInfoPointerÚvoidptrZTypeRefr3   r    rú  Ú_call_allocatorrÊ   Zmeminfo_datar�   r	   rV   r´   r‹  rù  )rg   r5   r­  r×   rf  rÖ   Údatatyper’   ZarrlenÚoverflowrŒ   Zarrlen_multr‘   Zdimension_sizeZallocsize_multr“  re   Z	align_valrk   rÄ   ÚmipZarytypeclassZargtypesr�   r€   r®   Zshape_arrayZstrides_arrayr:   r:   r;   rk  È  sv    
 
ÿ


ÿÿ þ
ûrk  Ú	_allocatec                 C   s   dd„ }|S )zTImplements a Numba-only default target (cpu) classmethod on the array
    type.
    c                 S   s
   t ||ƒS r  )Úintrin_alloc)Úclsr“  rk   r:   r:   r;   rÀ     s    z _ol_array_allocate.<locals>.implr:   )rs  r“  rk   rÀ   r:   r:   r;   Ú_ol_array_allocate  s    rt  c                 C   s   |   ||¡S )z9Trampoline to call the intrinsic used for allocation
    )rq  )r­  ry   rk   r:   r:   r;   rm  !  s    rm  c                 C   s(   dd„ }t  t j¡}t|||ƒ}||fS )z3Intrinsic to call into the allocator for Array
    c                 S   s   |\}}| j  |||¡}|S r  )rÊ   Zmeminfo_alloc_aligned)rg   r5   r    rÄ   r“  rk   r�   r:   r:   r;   r±  +  s    zintrin_alloc.<locals>.codegen)r   rk  rl  r    )r²  r“  rk   r±  rp  rK   r:   r:   r;   rr  '  s    rr  c              
   C   sÔ   dd„ }t |tjƒr.d}|  |||tj¡g}n&t |tjƒs>t‚|j}tj	|||d�}g }|D ]}| 
|| ||j|ƒ¡ q\|  |tjd¡}	t|ƒD ]>}
| d||
 |	¡}t ||¡� | j |td¡ W 5 Q R X q�|S )z;
    Parse the shape argument to an array constructor.
    c           
   	   S   s¬   |   tj¡}|j}t |¡}t|d|d > d ƒ}|j|k rJ| ||¡}n^|j|kr¨| d||¡}	|j	|	dd�� | j
 |td¡ W 5 Q R X |j|kr¤| ||¡}n|}|S )z0Cast src to intp only if value can be maintainedr=   ú>Fr  )z#Cannot safely convert value to intp)r�   r   ru   r>   r   r¿  r   Zsextrá   rã   r  r  rœ   Útrunc)
rg   r5   Zsrc_tr’  r®   Z
intp_widthZintp_irÚmaxvalrÏ   Z	is_largerr:   r:   r;   Úsafecast_intp9  s$    


 þ
z#_parse_shape.<locals>.safecast_intpr=   rÒ   r   rà   )znegative dimensions not allowed)r|   r   r~   rt   ru   r  r   r¥   r	   r¤   rU   r3   Úget_constant_genericr2   rá   r.  r  r  rœ   )rg   r5   r
  rq   rx  r[   Zpassed_shapesr×   rŒ   rÎ   r)  Zis_negr:   r:   r;   Ú_parse_shape5  s(      ÿrz  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Æ   rz  )rg   r5   rK   rÄ   ZarrshapetypeZarrshaper­  r:   r:   r;   Ú_parse_empty_argse  s    
r{  c                 C   sX   |j d }t|tjƒrJt|ƒ| ||d d�}tj||j|jd�}|j	|fS |j	dfS dS )z_
    Parse the arguments of a np.empty_like(), np.zeros_like() or
    np.ones_like() call.
    r   rÞ   rÒ   r:   N)
rÄ   r|   r   r}   rc   r	   r¤   rQ   r[   rÆ   )rg   r5   rK   rÄ   ÚarytyperÖ   r×   r:   r:   r;   rº  o  s    

rº  c                 C   s&   t |tjƒr"d| › d�}t |¡‚d S )NzIf np.z0 dtype is a string it must be a string constant.)r|   r   ZUnicodeTyper   rÁ   )Úfnamere   r­   r:   r:   r;   Ú_check_const_str_dtype}  s    r~  c                 C   s"   |j }||||ƒ}dd„ }||fS )Nc                 S   s(   t | |||ƒ\}}t| |||ƒ}| ¡ S r  )r{  rk  rÌ   ©r€  r5   rK   r�  r­  r×   rÖ   r:   r:   r;   r±  ˆ  s    znumpy_empty_nd.<locals>.codegen©Zinstance_type)r‚  Zty_shapeÚty_dtypeÚty_retty_refÚty_rettyrK   r±  r:   r:   r;   Únumpy_empty_ndƒ  s    r„  c                    sœ   t d|ƒ |tks0t|tjƒr(|jtks0t|ƒr8tj}nt|ƒ}t	| ƒ}|d k	r||d k	r|tj
||dd�‰ tf‡ fdd„	}|S d| › d|› d�}t |¡‚d S )	Nrs  r‹   rð  c                    s   t | |ˆ ƒS r  )r„  )rQ   re   ©r#  r:   r;   rÀ   �  s    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Á   )rQ   re   Únb_dtyper[   rÀ   r­   r:   r…  r;   Úol_np_empty�  s"    

ÿÿþr�  c                 C   s"   |j }||||ƒ}dd„ }||fS )Nc                 S   s(   t | |||ƒ\}}t| |||ƒ}| ¡ S r  )rº  rk  rÌ   r  r:   r:   r;   r±  ª  s    z$numpy_empty_like_nd.<locals>.codegenr€  )r‚  Zty_prototyper�  r‚  rƒ  rK   r±  r:   r:   r;   Únumpy_empty_like_nd¥  s    r�  c                    s¬   t d|ƒ t|ƒst|ƒ}nt| tjƒr0| j}n| }|d k	r~t| tjƒrn| jdkrX| jnd}| j||dd�‰ qšt |dd¡‰ nd| › d|› d	�}t	 
|¡‚d‡ fd
d„	}|S )Nr=  rª  r‹   F)re   rm  r¯  r   z3Cannot parse input types to function np.empty_like(r†  r‡  c                    s   t | |ˆ ƒS r  )r�  )rt  re   r…  r:   r;   rÀ   Å  s    zol_np_empty_like.<locals>.impl)N)r~  r   rŒ  r|   r   r}   re   rm  r¬  r   rÁ   )rt  re   rŽ  rm  r­   rÀ   r:   r…  r;   Úol_np_empty_like±  s    


r‘  c                 C   s   t  |¡}dd„ }||fS )Nc                 S   s<   t |jd ƒ| ||d ƒ}t ||j| |j|j¡d¡ d S r½   )rc   rÄ   r	   r»  r€   r¦   r’   r—   )r€  r5   rK   r�  rÖ   r:   r:   r;   r±  Î  s    ÿz(_zero_fill_array_method.<locals>.codegen)r   r'  )r‚  rI   rK   r±  r:   r:   r;   Ú_zero_fill_array_methodÊ  s    
r’  Ú
_zero_fillc                 C   s   dd„ }|S )z?Adds a `._zero_fill` method to zero fill an array using memset.c                 S   s   t | ƒ d S r  )r’  r   r:   r:   r;   rÀ   Ø  s    z ol_array_zero_fill.<locals>.implr:   )rI   rÀ   r:   r:   r;   Úol_array_zero_fillÕ  s    r”  c                 C   s   t d|ƒ tfdd„}|S )NÚzerosc                 S   s   t j| |d�}| ¡  |S ©Nrq  )r¸  rs  r“  )rQ   re   rt  r:   r:   r;   rÀ   á  s    zol_np_zeros.<locals>.impl)r~  rˆ  ©rQ   re   rÀ   r:   r:   r;   Úol_np_zerosÝ  s    
r˜  c                 C   s   t d|ƒ ddd„}|S )NÚ
zeros_likec                 S   s   t j| |d�}| ¡  |S r–  )r¸  r=  r“  )rö  re   rt  r:   r:   r;   rÀ   í  s    zol_np_zeros_like.<locals>.impl)N©r~  rˆ  r:   r:   r;   Úol_np_zeros_likeè  s    

r›  c                 C   s   t d|ƒ ddd„}|S )NÚ	ones_likec                 S   s2   t j| |d�}|j}tt|ƒƒD ]}d||< q |S ©Nrq  r=   ©r¸  r=  ró  r2   r†   )rö  re   rt  Úarr_flatrx   r:   r:   r;   rÀ   ù  s
    
zol_np_ones_like.<locals>.impl)Nrš  rˆ  r:   r:   r;   Úol_np_ones_likeô  s    

r   c                    s2   t d|ƒ t|ƒst|ƒ‰ n|‰ d‡ fdd„	}|S )NÚfullc                    s0   t  | ˆ ¡}|j}tt|ƒƒD ]}|||< q|S r  ©r¸  rs  ró  r2   r†   )rQ   Ú
fill_valuere   rt  rŸ  rx   ©rŽ  r:   r;   r¡  
  s
    
zimpl_np_full.<locals>.full)N)r~  r   rŒ  )rQ   r£  re   r¡  r:   r¤  r;   Úimpl_np_full  s    

r¥  c                 C   s   t d|ƒ ddd„}|S )NrQ  c                 S   s0   t  | |¡}|j}tt|ƒƒD ]}|||< q|S r  rž  )rö  r£  re   rt  rŸ  rx   r:   r:   r;   rQ    s
    
z$impl_np_full_like.<locals>.full_like)Nrš  )rö  r£  re   rQ  r:   r:   r;   Úimpl_np_full_like  s    

r¦  c                 C   s   t d|ƒ ddd„}|S )NÚonesc                 S   s2   t j| |d�}|j}tt|ƒƒD ]}d||< q |S r�  r¢  )rQ   re   rt  rŸ  rx   r:   r:   r;   rÀ   '  s
    
zol_np_ones.<locals>.impl)Nrš  r—  r:   r:   r;   Ú
ol_np_ones!  s    

r¨  c                    s4   t d|ƒ t|ƒst|ƒ‰ ntj‰ d‡ fdd„	}|S )NÚidentityc                    s.   t  | | fˆ ¡}t| ƒD ]}d|||f< q|S r;  )r¸  r•  r2   )rw  re   rt  rY   r¤  r:   r;   r©  8  s    z"impl_np_identity.<locals>.identity)N)r~  r   rŒ  r   r‹  )rw  re   r©  r:   r¤  r;   Úimpl_np_identity0  s    

rª  c                 C   s   d S r  r:   ©ÚNÚMr:   r:   r;   Ú_eye_none_handler@  s    r®  c                 C   s"   t |tjƒrdd„ }ndd„ }|S )Nc                 S   s   | S r  r:   r«  r:   r:   r;   rÀ   G  s    z$_eye_none_handler_impl.<locals>.implc                 S   s   |S r  r:   r«  r:   r:   r;   rÀ   J  s    ©r|   r   rY  )r¬  r­  rÀ   r:   r:   r;   Ú_eye_none_handler_implD  s    
r°  c                    sf   |d kst |tjƒr t t¡‰ n.t |tjtjfƒrDtt	|d|ƒƒ‰ n
t |¡‰ d dtf‡ fdd„	}|S )Nre   r   c                    s€   t | |ƒ}t | |fˆ ¡}|dkrPt| || ƒ}t|ƒD ]}d|||| f< q8n,t| | |ƒ}t|ƒD ]}d||| |f< qf|S r  )r®  r¸  r•  r@  r2   )r¬  r­  r²   re   Z_Mrt  ÚdrY   ©r×  r:   r;   rÀ   Z  s    
znumpy_eye.<locals>.impl)
r|   r   rY  r¸  re   rˆ  Ú	DTypeSpecrÖ  r   rŒ  )r¬  r­  r²   re   rÀ   r:   r²  r;   Ú	numpy_eyeO  s    
r´  c                 C   sD   t | ƒst d¡‚t| tjƒr@| jdkr2t d¡‚ddd„}|S d S )Nz#The argument "v" must be array-like)r=   r÷  zInput must be 1- or 2-d.r   c                 S   s.  | j dkrŒ| j}|d t|ƒ }t ||f| j¡}|dkrbt|| ƒD ]}| | |||| f< qFn&t|| ƒD ]}| | ||| |f< qn|S | j\}}|dk r¦|| }|dkr¶|| }tt||ƒdƒ}t 	|| j¡}|dk�rt|ƒD ]}| ||| f ||< qæn$t|ƒD ]}| || |f ||< �q
|S d S rC  )
r[   rQ   rë  r¸  r•  re   r2   rÓ  r@  rs  )r³   r²   rŒ   rw  r³  rY   ÚrowsÚcolsr:   r:   r;   Ú	diag_implr  s.    


zimpl_np_diag.<locals>.diag_impl)r   )r   r   rÁ   r|   r   r}   r[   ÚNumbaTypeError)r³   r²   r·  r:   r:   r;   Úimpl_np_diagi  s    



r¹  Útakec                    s‚   t | tjƒr$t |tjƒr$dd„ }|S tdd„ | |fD ƒƒrT|jdk‰ ‡ fdd„}|S t | tjƒr~t |tjtjfƒr~dd„ }|S d S )Nc                 S   s.   || j d ks|| j  k r"tdƒ‚|  ¡ | S )Nr=   úIndex out of bounds)ry   Ú
IndexErrorr+  )rö  r‰   r:   r:   r;   Ú	take_impl•  s    znumpy_take.<locals>.take_implc                 s   s   | ]}t |tjƒV  qd S r  r	  ©rƒ   rÏ  r:   r:   r;   r  ›  s     znumpy_take.<locals>.<genexpr>r]  c                    s†   t j|j| jd�}ˆ r | ¡ }n|}t  |¡}d}|  ¡ }|D ]:}|| jd ks\|| j k rdtdƒ‚|| ||< |d }q>| |j	¡S ©Nrq  r   r=   r»  )
r¸  rs  ry   re   r¬  r  r+  r¼  r(  rQ   )rö  r‰   r³  ZwalkerÚitrY   ró  r£  ©ZF_orderr:   r;   r½  ž  s    


c                 S   s~   t  |¡}t j|j| jd�}t  |¡}d}|  ¡ }|D ]:}|| jd ksT|| j k r\tdƒ‚|| ||< |d }q6| |j	¡S r¿  )
r¸  r«   rs  ry   re   r  r+  r¼  r(  rQ   )rö  r‰   Úconvertr³  rÀ  rY   ró  r£  r:   r:   r;   r½  ±  s    


)r|   r   r}   r~   rÂ  rm  r{  r  )rö  r‰   r½  r:   rÁ  r;   Ú
numpy_take�  s    
ÿrÃ  c                  G   s|   dd„ | D ƒ}t dd„ |D ƒƒr(tj}nPt dd„ |D ƒƒrBtj}n6ttddt t¡j  ƒ}dd„ |D ƒ}t	||g ƒ}|S )	Nc                 S   s   g | ]}t |tjƒs|‘qS r:   r¯  rõ  r:   r:   r;   r…   Á  s      z!_arange_dtype.<locals>.<listcomp>c                 s   s   | ]}t |tjƒV  qd S r  ©r|   r   ÚComplexrõ  r:   r:   r;   r  Ã  s     z _arange_dtype.<locals>.<genexpr>c                 s   s   | ]}t |tjƒV  qd S r  )r|   r   ÚFloatrõ  r:   r:   r;   r  Å  s     zint%srç  c                 S   s   g | ]}t  |¡‘qS r:   )r   Z	unliteral©rƒ   r£  r:   r:   r;   r…   Ô  s     )
r  r   Ú
complex128r™   rŒ  r¸  re   r¡   r’   rÓ  )rÄ   Zboundsre   ZNPY_TYZunliteral_boundsr:   r:   r;   Ú_arange_dtypeÀ  s    rÉ  c                    s  t |tjƒr|j}t |tjƒr$|j}t |tjƒr6|j}|d krDtj}|d krRtj}|d kr`tj}t | tjƒr¢t |tjtjfƒr¢t |tjtjfƒr¢t |tjtjfƒs¦d 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 r:   rÄ  rÇ  r:   r:   r;   r…   ö  s   ÿznp_arange.<locals>.<listcomp>rÂ   c                    sð   ˆ d k	rˆ n| }ˆd k	rˆn|}ˆd k	r,ˆn|}|d k	r<|nd}|d krTd| }}	n
|| }}	|dkrnt dƒ‚|	| | }
tt |
j¡ƒ}ˆdkr´tt |
j¡ƒ}tt||ƒdƒ}n
t|dƒ}t 	|ˆ¡}|}t
|ƒD ]}|||  ||< qÖ|S )Nr=   r   zMaximum allowed size exceededT)rœ   r¡   ÚmathÚceilr²  r¹  rÓ  r@  r¸  rs  r2   )rö   rT  rO  re   Z	lit_startZlit_stopZlit_stepZ_stepÚ_startÚ_stopZnitems_cZnitems_rZnitems_ir—   rt  rq   rY   ©Zstart_valueZ
step_valueZ
stop_valueZ
true_dtypeZuse_complexr:   r;   rÀ   ý  s(    

znp_arange.<locals>.impl)NNN)r|   r   ÚOptionalr3   r'  rÖ  rY  r³  rÉ  re   r  rŒ  )rö   rT  rO  re   rÀ   r:   rÎ  r;   Ú	np_arangeÚ  s>    ÿþýÿrÐ  c                    sn   t dd„ | |fD ƒƒsd S t|ttjfƒs8d}t |¡‚tdd„ | |fD ƒƒrVtj‰ ntj	‰ d‡ fdd„	}|S )	Nc                 s   s   | ]}t |tjƒV  qd S r  )r|   r   rÖ  r¾  r:   r:   r;   r     s     z!numpy_linspace.<locals>.<genexpr>z%The argument "num" must be an integerc                 s   s   | ]}t |tjƒV  qd S r  rÄ  r¾  r:   r:   r;   r  '  s     r  c                    sŠ   t  |ˆ ¡}| d } |d }|dkr(|S |d }|dkrn||  }t  ||¡}td|ƒD ]}| ||  ||< qVn| |d< |dkr†||d< |S )Ng      ð?r   r=   r  )r¸  rs  Údivider2   )rö   rT  r  rt  ÚdivÚdeltarO  rY   rq  r:   r;   r	  -  s    z numpy_linspace.<locals>.linspace)r  )
rÂ  r|   r¡   r   r~   r   rÁ   r  rÈ  r™   )rö   rT  r  r­   r	  r:   rq  r;   Únumpy_linspace  s    
rÔ  c              
   C   s  |j d }t|ƒ| ||d d�}t ||j¡}|j}t| |||ƒ}|j}	|j}
|jdks\t	‚|j|jkr„tj
||
|	|j|jdd� n„t ||j¡}t ||j¡}|  tj¡}t |||¡�H}t | ||	|||j|¡}t | ||
|||j|¡}| | |¡|¡ W 5 Q R X t| ||j| ¡ ƒS )z
    Array copy.
    r   rÞ   rr  r=   rj   )rÄ   rc   r	   r¤   rQ   rÆ   rk  r€   rm  r   Z
raw_memcpyr—   r’   r‘   r�   r   ru   r‘  rl  rç   r6   r   rÌ   )rg   r5   rK   rÄ   r|  rÖ   r×   Úrettyper³  r…  rß  r‡  rÞ  r®   r‰   r  r”  r:   r:   r;   Ú_array_copyF  s>    
 ÿ
  þ
  þrÖ  c                 C   s@   t |tjƒst‚|jdkrdnd}|j|dd�}||ƒ}|tfS )Nr]  r‹   F)rm  r¯  )r|   r   r}   r   rm  r¬  rÖ  )r²  rö  rm  r³  rK   r:   r:   r;   Ú_array_copy_intrinsick  s
    r×  z
array.copyc                 C   s   t | |||ƒS r  )rÖ  ré  r:   r:   r;   Ú
array_copyt  s    rØ  c                 C   s   t | tjƒrdd„ }|S )Nc                 S   s   t | ƒS r  )r×  r9  r:   r:   r;   Ú
numpy_copy|  s    z#impl_numpy_copy.<locals>.numpy_copyr	  )rö  rÙ  r:   r:   r;   Úimpl_numpy_copyy  s    rÚ  c              
   C   sÒ  |j }|jd }|j|ks"tdƒ‚|jdkrÀ|jdks:t‚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sà|jdkrò|jdkròt| |||d ƒS |jdk�rÀ|dk�st‚|dk�rtnt}t|| |||d ƒ}| |¡�V\}}|� t| |||d ƒ}|j}W 5 Q R X |� t| |||ƒ}|j}W 5 Q R X W 5 Q R X | |j¡}| ||¡ | ||¡ |S t| |||ƒS d	S )
zd
    Common logic for layout conversion function;
    e.g. ascontiguousarray and asfortranarray
    r   z return-type has incorrect layoutr=   rÞ   rÌ  rr  rª  r‹   N)rÆ   rÄ   rm  r   r[   rc   ry  r   rÀ  ru   r$  r’   r´   r€   r�   r“   r   rÌ   r   r   r¬  r}  ÚblockrÖ  Úphir3   Zadd_incoming)rg   r5   rK   rÄ   Úoutput_layoutr#  rµ   rÖ   r³  rQ   r‘   Z
check_funcrš  ZthenZorelseZout_thenZthen_blkZ
out_orelseZ
orelse_blkZret_phir:   r:   r;   Ú_as_layout_array�  sd    

  ÿþ ÿÿÿüÿrÞ  c                    sH   t ˆ tjƒst ˆ ¡‚|jˆ jt|jdƒd�}||ˆ ƒ}|‡ fdd„fS )Nr=   )rm  r[   c                    s   t | |||ˆ jd�S )N©rÝ  )rÞ  rÂ   )rG  rH  rŒ   rö  rß  r:   r;   rÊ  Ê  s       ÿz,_as_layout_array_intrinsic.<locals>.<lambda>)	r|   r   r!   r   ÚRequireLiteralValuer¬  rÂ   rÓ  r[   )r²  rö  rÝ  r³  rK   r:   rß  r;   Ú_as_layout_array_intrinsicÂ  s
    

rá  c                 C   sF   t | ƒst d¡‚t| tjtjfƒr.dd„ }nt| tjƒrBdd„ }|S )NrJ  c                 S   s   t  t  | ¡¡S r  )r¸  Úascontiguousarrayr«   r9  r:   r:   r;   rÀ   Ô  s    z%array_ascontiguousarray.<locals>.implc                 S   s
   t | dƒS ©Nr‹   ©rá  r9  r:   r:   r;   rÀ   ×  s    ©r   r   rÁ   r|   r   rÖ  rX  r}   ri  r:   r:   r;   Úarray_ascontiguousarrayÎ  s    

ræ  c                 C   sL   t | ƒst d¡‚t| tjtjfƒr0dd„ }|S t| tjƒrHdd„ }|S d S )NrJ  c                 S   s   t  t  | ¡¡S r  )r¸  Úasfortranarrayr«   r9  r:   r:   r;   rÀ   â  s    z"array_asfortranarray.<locals>.implc                 S   s
   t | dƒS )Nr]  rä  r9  r:   r:   r;   rÀ   æ  s    rå  ri  r:   r:   r;   Úarray_asfortranarrayÜ  s    
rè  zarray.astypec              
   C   s  |j d }t|ƒ| ||d d�}t ||j¡}|j}t| |||ƒ}|j}	|j}
t ||j¡}t ||j¡}|  	t
j¡}t |||¡�h}t | ||	|||j|¡}t | ||
|||j|¡}t| |||ƒ}|  |||j|j¡}t| ||||ƒ W 5 Q R X t| ||j| ¡ ƒS r\  )rÄ   rc   r	   r¤   rQ   rÆ   rk  r€   r‘   r�   r   ru   r‘  rl  rm  ro   rt   re   rr   r   rÌ   )rg   r5   rK   rÄ   r|  rÖ   r×   rÕ  r³  r…  rß  r‡  rÞ  r®   r‰   r  r”  Úitemr:   r:   r;   Úarray_astypeë  s6    

  þ
  þrê  c                 C   s"   |j }||||ƒ}dd„ }||fS )Nc              	   S   s  |j d }|j}t|ƒ| ||d d�}t|ƒ}|| |ƒ}|j}	t| |ƒ}
t|jj|
ƒ}| |j	|j¡}| 
||¡}t ||¡}|j|dd�� d}| j |t|f¡ W 5 Q R X 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Æ   rc   r˜   ri   r   r’   r3   r¦   r—   Zsremr	   Zis_not_nullrã   r  r  rœ   rV   Zsdivr‹  r€   r�   rž   r´   r�   r“   rÌ   r   )rg   r5   rK   rÄ   Zbuftyrµ   rë  Z
out_ary_tyÚout_aryZout_datamodelr’   Úll_itemsizer—  ÚremZis_incompatibler­   rQ   r‘   r€   rÏ   r:   r:   r;   r±    s<    


 ÿúznp_frombuffer.<locals>.codegenr€  )r²  Úbufferre   r#  r
  rK   r±  r:   r:   r;   Únp_frombuffer
  s    $rï  c                    sº   t d|ƒ t| tjƒr | jdkr4d| › �}t |¡‚|tksZt|tjƒrR|j	tksZt
|ƒrbtj}nt|ƒ}|d k	rŠtj|dd| j d�‰ nd| › d|› d�}t |¡‚tf‡ fd	d
„	}|S )NÚ
frombufferr‹   z+Argument "buffer" must be buffer-like. Got r=   )re   r[   rm  r¯  z3Cannot parse input types to function np.frombuffer(r†  r‡  c                    s   t | |ˆ ƒS r  )rï  )rî  re   r…  r:   r;   rÀ   M  s    z impl_np_frombuffer.<locals>.impl)r~  r|   r   rÔ   rm  r   rÁ   rˆ  r‰  rŠ  r   r‹  rŒ  r}   r   )rî  re   r­   rŽ  rÀ   r:   r…  r;   Úimpl_np_frombuffer6  s*    



ÿÿþ
ÿ
rñ  c                    sP   t |ƒr$tdd ƒ‰ d‡ fdd„	}|S t|tjƒrLtd|ƒ‰ d‡ fdd„	}|S d S )Nr‹   c                    s
   ˆ | |ƒS r  r:   ©rW   rQ   re   ©Úintrinsic_cfarrayr:   r;   rÀ   W  s    zimpl_carray.<locals>.implc                    s
   ˆ | |ƒS r  r:   rò  ró  r:   r;   rÀ   ]  s    )N)N©r   Úget_cfarray_intrinsicr|   r   r³  ©rW   rQ   re   rÀ   r:   ró  r;   Úimpl_carrayR  s    

rø  c                    sP   t |ƒr$tdd ƒ‰ d‡ fdd„	}|S t|tjƒrLtd|ƒ‰ d‡ fdd„	}|S d S )Nr]  c                    s
   ˆ | |ƒS r  r:   rò  ró  r:   r;   rÀ   g  s    zimpl_farray.<locals>.implc                    s
   ˆ | |ƒS r  r:   rò  ró  r:   r;   rÀ   m  s    )N)Nrõ  r÷  r:   ró  r;   Úimpl_farrayb  s    

rù  c                    s   t ‡ ‡fdd„ƒ}|S )Nc           	         sü   |t jkrd }n*t|t jƒr$|j}nd|› d�}t |¡‚ˆ d kr^|d krXd}t |¡‚|}nVtˆ t jƒržˆ j}|d k	r´||kr´d|› d|› d�}t |¡‚ndˆ › d�}t |¡‚t|ƒ}|d krÚd|› d�}t |¡‚t  	||ˆ¡}t
|||ƒ}|tfS )Nz pointer argument expected, got 'ú'z*explicit dtype required for void* argumentzmismatching dtype 'z' for pointer type 'zinvalid dtype spec 'zinvalid shape ')r   rl  r|   ÚCPointerre   r   r¸  r³  r�  r}   r    Ú
np_cfarray)	r²  rW   rQ   Z	ptr_dtyper­   re   r[   r#  rK   ©Údtype_rm  r:   r;   rô  s  s2    




z0get_cfarray_intrinsic.<locals>.intrinsic_cfarray©r%   )rm  rþ  rô  r:   rý  r;   rö  r  s    rö  c                    s<  |j dd… \}}|dd… \}}|j}|jdks6t‚t|ƒˆˆ ƒ}	tˆ|ƒ}
t |
¡}t|t	j
ƒrrt ˆ |¡}n|f}|f}‡ ‡fdd„t||ƒD ƒ}|}g }|jdkrÌ|D ]}| |¡ ˆ  ||¡}q®n,t|ƒD ]}| |¡ ˆ  ||¡}qÔ| ¡  ˆ  |ˆ |j¡ ¡ ¡}t|	||||dd� |	 ¡ }tˆˆ |j|ƒS )zR
    numba.numpy_support.carray(...) and
    numba.numpy_support.farray(...).
    Nr÷  rr  c                    s"   g | ]\}}ˆ  ˆ ||tj¡‘qS r:   râ  )rƒ   r¨  rß   r„   r:   r;   r…   «  s   ÿznp_cfarray.<locals>.<listcomp>r]  ró  )rÄ   rÆ   rm  r   rc   ri   r	   r®   r|   r   r  r¤   r‡   rU   r¦   ri  rR  r‹  rd   re   rù  r´   rÌ   r   )rg   r5   rK   rÄ   r„  rä  rW   rQ   rµ   rë  r’   rì  r×   Úoffr‘   rŒ   r€   rÏ   r:   r„   r;   rü  –  sH    

ÿ


ÿú	rü  c                 C   sV   t |tjƒr|  tjt|ƒ¡S t |tjƒrJ|  tttj|ƒ¡}|||fƒS dsRt	‚d S r½   )
r|   r   r  r£   ru   r†   rÝ  rB   r    r   )rg   r5   ÚseqtyÚseqrá  r:   r:   r;   Ú_get_seq_sizeÊ  s    r  c                    s2   |j ‰ˆ  tjtˆ|tjƒ¡‰‡ ‡‡fdd„}|S )zK
    Return a getitem() implementation that doesn't incref its result.
    c                    s$   ˆ| |ƒ}ˆ j r ˆ j | ˆ|¡ |S r  )rÉ   rÊ   Zdecref)r5   rÄ   r³  ©rg   rÛ  r#  r:   r;   ÚwrapÜ  s    
z$_get_borrowing_getitem.<locals>.wrap)re   rB   rÙ  rÚ  r    r   ru   )rg   r  r  r:   r  r;   Ú_get_borrowing_getitemÔ  s    ÿr  c                    st   ˆ  tj¡}t|dƒ‰‡ ‡‡fdd„}g }|| }}	t|ƒD ].}
|
dkrV|||	ƒ\}}	| tˆˆ ||	ƒ¡ q<t|ƒS )zF
    Compute the likely shape of a nested sequence (possibly 0d).
    r   c                    sT   t | tjƒr2t| ƒdkrdS | d ˆ  |d¡fS ntˆ| ƒ}| j|ˆ |ˆfƒfS d S )Nr   )NN)r|   r   r  r†   r  r  re   )r  r  rÛ  ©r5   rg   rÎ   r:   r;   Úget_first_itemì  s    
z.compute_sequence_shape.<locals>.get_first_item)r�   r   ru   r   r2   rU   r  rŸ   )rg   r5   r[   r  r  r®   r  r×   ÚinnertyÚinnerrY   r:   r  r;   Úcompute_sequence_shapeå  s    

r  c                    s0   ‡‡fdd„‰ ‡ ‡‡‡fdd„‰ˆ|||ƒ dS )z?
    Check the nested sequence matches the given *shapes*.
    c                      s   ˆj  ˆ td¡ d S )N)zincompatible sequence shape)r  r  rœ   r:   r„   r:   r;   Ú_fail  s    
ÿz#check_sequence_shape.<locals>._failc              	      s  t |ƒdkrd S tˆˆ| |ƒ}|d }ˆ d||¡}ˆj|dd�� ˆ ƒ  W 5 Q R X t |ƒdkrdd S t| tjƒr¾tˆ| ƒ}t 	ˆ|¡�0}| j
}|ˆ||jfƒ}	ˆ||	|dd … ƒ W 5 Q R X nXt| tjƒ�rtt | ƒƒD ],}
| |
 }ˆ ||
¡}	ˆ||	|dd … ƒ qØnd�st| ƒ‚d S )Nr   r  Fr  r=   )r†   r  rá   rã   r|   r   rÝ  r  r	   rE  re   rÈ   r  r2   r  r   )r  r  r×   ry   Úexpectedr§  rÛ  rF  r	  r
  rY   ©r  r5   Úcheck_seq_sizerg   r:   r;   r    s*    
 z,check_sequence_shape.<locals>.check_seq_sizeNr:   )rg   r5   r  r  r×   r:   r  r;   Úcheck_sequence_shape  s    r  c                    s:   ‡ ‡‡‡‡‡fdd„‰‡‡‡‡fdd„‰ˆ||ˆdƒ dS )zl
    Assign a nested sequence contents to an array.  The shape must match
    the sequence's structure.
    c              
      sB   t jˆˆˆˆˆˆ j| dd�}ˆ ˆ||ˆ j¡}tˆˆˆ ||ƒ d S r  )r	   rl  rm  rt   re   rr   )r‰   r  rq   rW   )rs  r5   rg   r€   r×   r‘   r:   r;   Úassign_item3  s      ÿz-assign_sequence_to_array.<locals>.assign_itemc              	      s  t |ƒdkr2t| tjtjfƒr"t‚ˆ|| |ƒ d S |d }t| tjƒržtˆ| ƒ}t ˆ|¡�:}| j	}|ˆ||j
fƒ}ˆ |||dd … ||j
f ƒ W 5 Q R X nlt| tjƒrütt | ƒƒD ]B}	| |	 }ˆ ||	¡}ˆ tj|	¡}
ˆ |||dd … ||
f ƒ q¶nd�s
t| ƒ‚d S r  )r†   r|   r   rÝ  r  r   r  r	   rE  re   rÈ   r2   r  r£   ru   )r  r  r×   r‰   ry   rÛ  rF  r	  r
  rY   rÈ   )Úassignr  r5   rg   r:   r;   r  9  s$    
* z(assign_sequence_to_array.<locals>.assignr:   Nr:   )rg   r5   r€   r×   r‘   rs  r  r  r:   )rs  r  r  r5   rg   r€   r×   r‘   r;   Úassign_sequence_to_array,  s    r  c                 C   s>   t | |ƒ\}}t|ƒr|}nt|ƒ}|d kr0d S t ||d¡S rã  )r/   r   rŒ  r   r}   )r²  r>  re   r[   Z	seq_dtyper:   r:   r;   Únp_array_typerU  s    r  c                 C   s0   t d|ƒ t| ||ƒ}|||ƒ}dd„ }||fS )Nr«   c           
   	   S   sŠ   |j }|j}|jd }|d }t| ||||ƒ}t|ƒ|ks>t‚t| ||||ƒ t| |||ƒ}	t| ||	j	||	j
|||ƒ t| ||j |	 ¡ ƒS r½   )rÆ   r[   rÄ   r  r†   r   r  rk  r  r€   r‘   r   rÌ   )
rg   r5   rK   rÄ   rs  r[   r  r  r×   rt  r:   r:   r;   r±  f  s"    
   ÿ
ÿznp_array.<locals>.codegen)r~  r  )r²  Úobjre   r³  rK   r±  r:   r:   r;   Únp_array`  s
    

r  c                 C   sL   t d|ƒ t| ƒst d¡‚t|ƒs>t|ƒd kr>d}t |¡‚ddd„}|S )Nr«   z(The argument "object" must be array-likez:The argument "dtype" must be a data-type if it is providedc                 S   s
   t | |ƒS r  )r  )r>  re   r:   r:   r;   rÀ   „  s    zimpl_np_array.<locals>.impl)N)r~  r   r   rÁ   r   rŒ  )r>  re   r­   rÀ   r:   r:   r;   Úimpl_np_arrayz  s    



r  c           
   	   C   s�   |  d¡}|  |¡}| d||¡}| || ||¡|¡}| | d||¡| d||¡¡}|j|dd��  d| }	| j |t|	f¡ W 5 Q R X |S )Nr   rà   r3  Fr  z%s(): axis out of bounds)	r3   rá   rS  r=  ra  rã   r  r  r¼  )
rg   r5   r¹   r[   r»   rÎ   Zll_ndimZis_neg_axisZaxis_out_of_boundsr­   r:   r:   r;   Ú_normalize_axis‰  s    

þr  c              
   C   sÂ   t |ƒ|d kst‚t tj|¡}t ||¡}t d¡}t|d ƒD ]R}t |¡}	| d|	|¡}
|| }| 	|
| 
|	|¡|	¡}| |t ||d|¡¡ qD| |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=   r3  r   ©r†   r   r   rø  r	   r®   rG   r2   rá   rS  r=  rç   rT   r¤   r6   )rg   r5   Ú
orig_shaper[   r»   Úll_shtyr×   rù   r)  Úll_dimÚ
after_axisrÿ   rx   r:   r:   r;   Ú_insert_axis_in_shapeœ  s    


þr  c              
   C   sÈ   t |ƒ|d kst‚t tj|¡}t ||¡}t d¡}t d¡}t|d ƒD ]N}	t |	¡}
| d|
|¡}| 	|| 
|
|¡|
¡}| ||	 t ||d|¡¡ qN| |t ||d|¡¡ t || |¡¡S )zD
    Same as _insert_axis_in_shape(), but with a strides array.
    r=   r   r3  r  )rg   r5   Úorig_stridesr[   r»   r  r‘   rù   rÎ   r)  r  r  rx   r:   r:   r;   Ú_insert_axis_in_strides¹  s"    



þ
ÿr   c              	   C   sœ   |j }|j}|jd }t|ƒ| ||d d�}t|ƒ| |ƒ}	t ||j¡}
t ||j¡}t| ||
||ƒ}t	| ||||ƒ}t
|	|j|||j|j|jd� |	 ¡ S )z/
    np.expand_dims() with the given axis.
    r   rÞ   r  )rÆ   r[   rÄ   rc   r	   r¤   rQ   r‘   r  r   r´   r€   r’   r�   r“   rÌ   )rg   r5   rK   rÄ   r»   r#  r[   rs  rt  r³  r×   r‘   Z
new_shapesZnew_stridesr:   r:   r;   Úexpand_dimsÖ  s$    
úr!  c                 C   sB   |j dkr|jnd}|j|j d |d�}|||ƒ}dd„ }||fS )Nr=   rª  r«  c                 S   sP   |   ||d |jd tj¡}t| |d|jj|ƒ}t| ||||ƒ}t| ||j|ƒS )Nr=   znp.expand_dims)	rt   rÄ   r   ru   r  rÆ   r[   r!  r   )rg   r5   rK   rÄ   r»   r³  r:   r:   r;   r±  ø  s     ÿznp_expand_dims.<locals>.codegen)r[   rm  r¬  )r²  rö  r»   rm  r³  rK   r±  r:   r:   r;   Únp_expand_dimsò  s
    
r"  c                 C   sL   t | tjƒs d| › �}t |¡‚t |tjƒs@d|› �}t |¡‚dd„ }|S )Nz)First argument "a" must be an array. Got z(Argument "axis" must be an integer. Got c                 S   s
   t | |ƒS r  )r"  )rö  r»   r:   r:   r;   rÀ     s    z!impl_np_expand_dims.<locals>.impl)r|   r   r}   r   rÁ   r~   )rö  r»   r­   rÀ   r:   r:   r;   Úimpl_np_expand_dims  s    



r#  c                    s   t ‡ ‡fdd„ƒ‰‡fdd„S )Nc                    sX   |‰ ‡fdd„|D ƒ‰‡ ‡‡‡fdd„}t tˆƒdkr@t ˆ¡nˆd tj |¡ƒ|fS )Nc                    s    g | ]}|j t|jˆ ƒd �‘qS )rB  )r¬  rÓ  r[   r¾  )Úminimumr:   r;   r…     s     z-_atleast_nd.<locals>.impl.<locals>.<listcomp>c                    sn   t ˆˆƒ‰t ˆ |d ¡}‡ ‡‡fdd„t|ˆˆƒD ƒ}t|ƒdkrVˆ ˆ |j|¡}n|d }tˆˆ |j|ƒS )Nr   c                    s"   g | ]\}}}ˆˆˆ |||ƒ‘qS r:   r:   )rƒ   rt  rs  r#  ©r5   rg   Ú	transformr:   r;   r…     s   ÿz>_atleast_nd.<locals>.impl.<locals>.codegen.<locals>.<listcomp>r=   )Ú_atleast_nd_transformr	   r¤   r‡   r†   r$  rÆ   r   )rg   r5   rK   rÄ   ÚarrsZretsr³  )r)  r  r$  r9  r%  r;   r±    s    

ÿz*_atleast_nd.<locals>.impl.<locals>.codegenr=   r   )r    r†   r   rÁ  ZStarArgTupleZ
from_types)ZtypingcontextrÄ   r±  )r  r$  )r)  r9  r;   rÀ     s    
ÿÿz_atleast_nd.<locals>.implc                     s   ˆ | Ž S r  r:   rÉ  )rÀ   r:   r;   rÊ  (  rË  z_atleast_nd.<locals>.<lambda>rÿ  )r$  r  r:   )r  rÀ   r$  r;   Ú_atleast_nd  s    r)  c                    s"   ˆt ˆ ƒkst‚‡ ‡fdd„}|S )z`
    Return a callback successively inserting 1-sized dimensions at the
    following axes.
    c           	         sb   t ˆƒD ]T}|d }|j|k rt ˆ | ¡}|j|jd d�}t| |t ||¡|f|ƒ}|}q|S )Nr=   rB  )r2   r[   r	   r®   r¬  r!  r   r    )	rg   r5   rt  rs  r#  rY   r[   r»   Znewarrty©r  Úmin_ndimr:   r;   r&  2  s    

 þz(_atleast_nd_transform.<locals>.transform)r†   r   )r+  r  r&  r:   r*  r;   r'  +  s    r'  c                  G   s"   t dd„ | D ƒƒrtddgƒS d S )Nc                 s   s   | ]}t |tjƒV  qd S r  r	  r¾  r:   r:   r;   r  D  s     z np_atleast_1d.<locals>.<genexpr>r=   r   ©rÂ  r)  rÉ  r:   r:   r;   Únp_atleast_1dB  s    r-  c                  G   s$   t dd„ | D ƒƒr tdddgƒS d S )Nc                 s   s   | ]}t |tjƒV  qd S r  r	  r¾  r:   r:   r;   r  J  s     z np_atleast_2d.<locals>.<genexpr>r÷  r   r,  rÉ  r:   r:   r;   Únp_atleast_2dH  s    r.  c                  G   s&   t dd„ | D ƒƒr"tddddgƒS d S )Nc                 s   s   | ]}t |tjƒV  qd S r  r	  r¾  r:   r:   r;   r  P  s     z np_atleast_3d.<locals>.<genexpr>r  r   r÷  r,  rÉ  r:   r:   r;   Únp_atleast_3dN  s    r/  c	                 C   sŽ  t |ƒt |ƒ  kr.t |ƒ  kr.t |ƒks4n t‚t d¡}	t| |||ƒ}
t ||
j¡}g }|D ]d}|	}tt||ƒƒD ]B\}\}}| 	d| 
|¡|¡}| ||¡}| || ||¡|¡}qx| |¡ qb|
j}t|||||ƒD ]ª\}}}}}|j}tj||tj|jd�}|�h}t | |||||j|¡}t| |||ƒ}|  |||j|j¡}t | |||||j|¡}t| ||||ƒ W 5 Q R X t |||¡}qÞ|
S )z2
    Concatenate arrays along the given axis.
    r   r_  )Úorder)r†   r   r	   r®   rk  r¤   r‘   rÎ  r‡   rá   r3   r¦   rS  r=  rU   r€   r‘  rm  rl  ro   rt   re   rr   rÓ   )rg   r5   r»   r)  r(  Ú
arr_shapesÚarr_stridesr#  Ú
ret_shapesrÎ   r³  Zret_stridesZcopy_offsetsZarr_shrØ   r)  ry   re  Úis_axisÚaddendZret_datars  rt  Zarr_stZarr_datar‘  r‰   r  rq   r”  r:   r:   r;   Ú_do_concatenateT  sT    4

þ ÿÿ
  þ
  þr6  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 ƒ}ˆ  |
¡�¨\}}|�& t 	ˆ j
||g ¡}ˆ  ||¡ W 5 Q R X |�d tj}|D ]}ˆ  |ˆ  d||¡¡}�qˆ jˆ  |¡dd�� ˆj ˆ tdˆ f¡ W 5 Q R X W 5 Q R X W 5 Q R X qr‡ fdd„|	D ƒ}	tˆˆ |||||||	ƒ	}tˆˆ || ¡ ƒS )Nc                    s"   g | ]\}}t |ƒˆˆ |d �‘qS ©rÞ   rñ  ©rƒ   rï  rö  r„   r:   r;   r…   ”  s   ÿz#_np_concatenate.<locals>.<listcomp>únp.concatenatec                    s   g | ]}t  ˆ |j¡‘qS r:   )r	   r¤   rQ   ©rƒ   rt  r¢  r:   r;   r…   š  s     c                    s   g | ]}t  ˆ |j¡‘qS r:   ©r	   r¤   r‘   r:  r¢  r:   r;   r…   ›  s     c                    s   g | ]}t  ˆ |¡‘qS r:   )r	   rÇ   r—  r¢  r:   r;   r…      s   ÿr   r_  c                    s   g | ]}|ˆ  ‘qS r:   r:   r—  )r)  r:   r;   r…   §  s     r=   Fr  z<np.concatenate(): input sizes over dimension %d do not matchc                    s   g | ]}ˆ   |¡‘qS r:   )r6   r—  r¢  r:   r;   r…   »  s     )r[   r‡   r  r2   rá   r3   r6   r}  r™  rš  r=  rç   r	   r›  rz  rã   rJ  r  r  rœ   r6  r   rÌ   )rg   r5   r)  r(  r#  r»   r[   r1  r2  r3  r4  Zret_shape_ptrZret_shZother_shapesZon_axisZon_other_dimrÿ   Úis_okr³  r:   )r5   rg   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 ]n}tj}tt ˆ |j¡|
ƒD ]N\}}ˆ  	|ˆ  
d||¡¡}ˆ jˆ  |¡dd�� ˆj ˆ td	¡ W 5 Q R X qŽqp‡ fd
d„|D ƒ}t tj|¡‰t ˆ ˆ¡}t ˆ ˆ¡}t|d ƒD ]l}t |¡}ˆ  
d||¡}|
| }ˆ  |ˆ  ||¡|¡}ˆ  |t ˆ |d|¡¡ ˆ  |t ˆ |d|¡¡ �q$ˆ  |t ˆ |d|¡¡ ˆ  |	t ˆ |d|¡¡ t ˆ ˆ  |¡¡}|gt|ƒ }t ˆ ˆ  |¡¡}‡ ‡fdd„tt|ƒƒD ƒ}t|d ƒD ]l}t |¡}ˆ  
d||¡}ˆ  |ˆ  ||¡|¡}tt|ƒƒD ]*}ˆ  || | t ˆ || d|¡¡ �qZ�qtt|ƒƒD ]"}ˆ  |t ˆ || d|¡¡ �q–‡ fdd„|D ƒ}tˆˆ |||||||ƒ	}tˆˆ || ¡ ƒS )Nr   r=   c                    s"   g | ]\}}t |ƒˆˆ |d �‘qS r7  rñ  r8  r„   r:   r;   r…   Ê  s   ÿz_np_stack.<locals>.<listcomp>únp.stackr_  Fr  )z5np.stack(): all input arrays must have the same shapec                    s   g | ]}t  ˆ |j¡‘qS r:   r;  r:  r¢  r:   r;   r…   Ü  s     r3  c                    s   g | ]}t  ˆ ˆ¡‘qS r:   rí  r[  )r5   r  r:   r;   r…   ý  s   ÿc                    s   g | ]}t  ˆ ˆ  |¡¡‘qS r:   )r	   r¤   r6   )rƒ   r   r¢  r:   r;   r…     s   ÿ)r[   r	   r®   r†   r‡   r  r¤   rQ   r›  rz  rá   rã   rJ  r  r  rœ   r   rø  rG   r2   rS  r=  rç   rT   r6   r6  r   rÌ   )rg   r5   r)  r(  r#  r»   r[   rÎ   rù   Z
ll_narraysr  rt  r<  rÿ   Zorig_shr  Zinput_shapesr3  r)  r  r  rx   Zinput_stridesrY   r³  r:   )r5   rg   r  r;   Ú	_np_stackÃ  s˜    

ÿÿ þ

þý
ÿ

þÿÿÿ

ÿ    þr?  c                 C   sN   |d k	rt |tjƒsd S t| d|ƒ\}}|dkr8tdƒ‚t|ƒ}t |||¡S )Nr9  r   z.zero-dimensional arrays cannot be concatenated)r|   r   r~   r0   Ú	TypeErrorr1   r}   )r²  r%  r»   re   r[   rm  r:   r:   r;   Únp_concatenate_typer  s     ÿrA  c                 C   s6   t | ||ƒ}t|tjƒst‚|||ƒ}dd„ }||fS )Nc              	   S   sF   |   ||d |jd tj¡}t| |t|jd ƒt ||d ¡|j|ƒS rC  )	rt   rÄ   r   ru   r=  r    r	   r¤   rÆ   ©rg   r5   rK   rÄ   r»   r:   r:   r;   r±  3  s    üznp_concatenate.<locals>.codegen)rA  r|   r   r}   r   )r²  r%  r»   r³  rK   r±  r:   r:   r;   Únp_concatenate-  s
    
rC  c                 C   s   t | tjƒrddd„}|S d S )Nr   c                 S   s
   t | |ƒS r  )rC  ©r%  r»   r:   r:   r;   rÀ   A  s    z!impl_np_concatenate.<locals>.impl)r   ©r|   r   r  ©r%  r»   rÀ   r:   r:   r;   Úimpl_np_concatenate>  s    
rG  c                 C   s*   |D ] }|j dk s|j dkrtdƒ‚qdS )Nr=   r÷  z7np.column_stack() is only defined on 1-d and 2-d arrays)r[   r@  )rg   r¹   r%  rö  r:   r:   r;   Ú_column_stack_dimsF  s    
rH  c                 C   sB   t | d|td�\}}t|ƒ}t |||¡}||ƒ}dd„ }||fS )Nznp.column_stack)Zdim_chooserc                 S   sÈ   t |jd ƒ}t ||d ¡}g }g }|  tjd¡}t||ƒD ]t\}	}
|	jdkrf| 	|	¡ | 	|
¡ q>|	jdkstt
‚|	jdd�}t ||	¡}t| |||
f|ƒ}| 	|¡ | 	|¡ q>t| ||||j|ƒS )Nr   r=   r÷  rB  )r    rÄ   r	   r¤   r£   r   ru   r‡   r[   rU   r   r¬  r   r    r!  r=  rÆ   )rg   r5   rK   rÄ   Zorig_arrtysZ	orig_arrsr)  r(  r»   rs  rt  re  Ú
expand_sigZnewarrr:   r:   r;   r±  X  s&    



 ÿz np_column_stack.<locals>.codegen)r0   rH  r1   r   r}   )r²  r  re   r[   rm  r³  rK   r±  r:   r:   r;   Únp_column_stackO  s     þ
rJ  c                 C   s   t | tjƒrdd„ }|S d S )Nc                 S   s   t | ƒS r  )rJ  ©r  r:   r:   r;   rÀ   x  s    zimpl_column_stack.<locals>.implrE  ©r  rÀ   r:   r:   r;   Úimpl_column_stacku  s    rM  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Æ   rB  r:   r:   r;   Ú_np_stack_common}  s    ürN  c           	      C   sV   t | d|ƒ\}}tdd„ |D ƒƒr&dnd}t ||d |¡}|||ƒ}dd„ }||fS )	Nr>  c                 s   s   | ]}|j d kV  qdS )r]  N)rm  rõ  r:   r:   r;   r  �  s     z"np_stack_common.<locals>.<genexpr>r]  r‹   r=   c                 S   s,   |   ||d |jd tj¡}t| ||||ƒS r;  )rt   rÄ   r   ru   rN  rB  r:   r:   r;   r±  ‘  s    z np_stack_common.<locals>.codegen)r0   rÂ  r   r}   )	r²  r%  r»   re   r[   rm  r³  rK   r±  r:   r:   r;   Únp_stack_commonˆ  s     ÿ
rO  c                 C   s   t | tjƒrddd„}|S d S )Nr   c                 S   s
   t | |ƒS r  )rO  rD  r:   r:   r;   rÀ   ›  s    zimpl_np_stack.<locals>.impl)r   rE  rF  r:   r:   r;   Úimpl_np_stack˜  s    
rP  c                 C   s4   t | ||ƒ\}}t||ƒ}t|ƒ}t |||¡}|S r  )r0   rÓ  r1   r   r}   )r²  r¹   r%  Zndim_minre   r[   rm  r³  r:   r:   r;   ÚNdStack_typer   s
    
rQ  c                 C   s&   t | d|dƒ}||ƒ}dd„ }||fS )Nz	np.hstackr=   c                    sj   |j d }|d j}|dkr:|  tjd¡‰ t| |||ˆ ƒS |dkrFdnd‰ ‡ fdd„}|  ||||¡S d S )Nr   r=   c                    s   t j| ˆ d�S r/  r1  ©r%  r0  r:   r;   Únp_hstack_impl¼  s    z3_np_hstack.<locals>.codegen.<locals>.np_hstack_impl©rÄ   r[   r£   r   ru   rN  rú  )rg   r5   rK   rÄ   r  r[   rS  r:   r0  r;   r±  ®  s    

z_np_hstack.<locals>.codegen©rQ  ©r²  r  r³  rK   r±  r:   r:   r;   Ú
_np_hstack©  s    rW  c                 C   s   t | tjƒrdd„ }|S d S )Nc                 S   s   t | ƒS r  )rW  rK  r:   r:   r;   rÀ   Ç  s    zimpl_np_hstack.<locals>.implrE  rL  r:   r:   r;   Úimpl_np_hstackÄ  s    rX  c                 C   s&   t | d|dƒ}||ƒ}dd„ }||fS )Nz	np.vstackr÷  c                 S   sd   |j d }|d j}|dkr&dd„ }n.|dkrL|  tjd¡}t| ||||ƒS dd„ }|  ||||¡S )Nr   c                 S   s   t  t  | ¡d¡S r;  )r¸  r!  ÚhstackrR  r:   r:   r;   Únp_vstack_implÖ  s    z3_np_vstack.<locals>.codegen.<locals>.np_vstack_implr=   c                 S   s   t j| dd�S )Nr   r0  r1  rR  r:   r:   r;   rZ  ß  s    rT  )rg   r5   rK   rÄ   r  r[   rZ  r»   r:   r:   r;   r±  Ñ  s    


z_np_vstack.<locals>.codegenrU  rV  r:   r:   r;   Ú
_np_vstackÌ  s    r[  c                 C   s   t | tjƒrdd„ }|S d S )Nc                 S   s   t | ƒS r  )r[  rK  r:   r:   r;   rÀ   ê  s    zimpl_np_vstack.<locals>.implrE  rL  r:   r:   r;   Úimpl_np_vstackç  s    r\  c                 C   s&   t | d|dƒ}||ƒ}dd„ }||fS )Nz	np.dstackr  c                 S   sò   |j d }|j}|d j}|dkr:dd„ }|  ||||¡S |dkr°|  tjd¡}|j|jd d�}	tj	|	f|j žŽ }
t
| ||
||ƒ}|  tjd¡}t 	||	¡}t| |||f|ƒS |dkrÖ|  tjd¡}t
| ||||ƒS dd„ }|  ||||¡S d S )Nr   c                 S   s   t  | ¡ ddd¡S )Nr=   r  )r¸  rY  r(  rR  r:   r:   r;   rZ  ú  s    z3_np_dstack.<locals>.codegen.<locals>.np_vstack_implr=   rB  r÷  c                 S   s   t j| dd�S )Nr÷  r0  r1  rR  r:   r:   r;   rZ    s    )rÄ   rÆ   r[   rú  r£   r   ru   r¬  r   r    rN  r!  )rg   r5   rK   rÄ   r  r#  r[   rZ  r»   Zstack_rettyZ	stack_sigZ	stack_retrI  r:   r:   r;   r±  ô  s*    


ÿz_np_dstack.<locals>.codegenrU  rV  r:   r:   r;   Ú
_np_dstackï  s    "r]  c                 C   s   t | tjƒrdd„ }|S d S )Nc                 S   s   t | ƒS r  )r]  rK  r:   r:   r;   rÀ     s    zimpl_np_dstack.<locals>.implrE  rL  r:   r:   r;   Úimpl_np_dstack  s    r^  Úfillc                 C   s   dd„ }|S )Nc                 S   s   || d d …< d S r  r:   )rt  rq   r:   r:   r;   Ú	fill_impl$  s    zarr_fill.<locals>.fill_implr:   )rt  rq   r`  r:   r:   r;   Úarr_fill!  s    ra  Údotc                 C   s   dd„ }|S )Nc                 S   s   t  | |¡S r  )r¸  rb  )rt  Úotherr:   r:   r;   Údot_impl-  s    zarray_dot.<locals>.dot_implr:   )rt  rc  rd  r:   r:   r;   Ú	array_dot+  s    re  c                 C   s"   t | ƒst d|  ¡‚dd„ }|S )NzCannot np.fliplr on %s typec                 S   s4   t  | ¡}|jdk rtdƒ‚|d d …d d d…df S )Nr÷  r  r  .©r¸  r¹  r[   rœ   ©rö  rª  r:   r:   r;   rÀ   9  s    

znp_flip_lr.<locals>.implrh  ri  r:   r:   r;   Ú
np_flip_lr3  s    rh  c                 C   s"   t | ƒst d|  ¡‚dd„ }|S )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.r  .rf  rg  r:   r:   r;   rÀ   J  s    

znp_flip_ud.<locals>.implrh  ri  r:   r:   r;   Ú
np_flip_udD  s    ri  c                    sN   t |tjƒst |¡‚t|jƒ‰ tjtjˆ d�‰ˆ|ƒ}‡ ‡fdd„}||fS )zY Creates a tuple of slices for np.flip indexing like
    `(slice(None, None, -1),) * sz` rã  c                    sX   dd„ }t jˆg}tjˆf|žŽ }|  t j¡}|  ˆ¡}|ˆ ƒ|g}	|  ||||	¡}
|
S )Nc                 S   s*   |}t | ƒD ]}t||td d dƒƒ}q|S )Nr  )r2   r*   rþ   )ÚlengthÚempty_tuplerÐ   rY   r:   r:   r;   rÀ   `  s    z6_build_flip_slice_tuple.<locals>.codegen.<locals>.impl)r   ru   r   r    r�   Zget_constant_undefrú  )rg   r5   r    rÄ   rÀ   Zinner_argtypesZ	inner_sigZll_idx_typerk  Z
inner_argsrÏ   ©ry   Z
tuple_typer:   r;   r±  _  s    

z(_build_flip_slice_tuple.<locals>.codegen)	r|   r   r½  r   rà  r¡   rÂ   rÀ  Zslice3_type)r‚  ÚszrK   r±  r:   rl  r;   Ú_build_flip_slice_tupleU  s    

rn  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  )rn  r[   )rö  Úslr:   r:   r;   rÀ   z  s    
znp_flip.<locals>.impl)r|   r   r}   r   rÁ   ri  r:   r:   r;   Únp_flips  s    rp  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ƒrht |jjtjƒrhddd„}|S t |tj	ƒr–t
dd„ |jD ƒƒr–ddd„}|S d S )Nr   c                 S   s   t jt  | ¡||d�S r/  )r¸  Úarray_splitr¹  ©rÖ   Úindices_or_sectionsr»   r:   r:   r;   rÀ   „  s
    ýznp_array_split.<locals>.implc                 S   sP   t | j| |ƒ\}}t t |d g| |g|| d   ¡¡}tj| ||d�S )Nr=   r0  )ÚdivmodrQ   r¸  Zcumsumr«   rq  )rÖ   rs  r»   r  rí  r‰   r:   r:   r;   rÀ   Ž  s    ÿÿc              	   S   sp   t | jƒ}tdd| j|ƒ}g }d}|D ](}t||t||ƒƒ}| | | ¡ |}q&| | t||t|d ƒƒ ¡ |S ©Nznp.splitr»   r   )r+   r[   r¼   r*   rþ   rU   ©rÖ   rs  r»   Z	slice_tuprÐ   Úprevrp  rx   r:   r:   r;   rÀ   Ÿ  s    
c                 s   s   | ]}t |tjƒV  qd S r  ©r|   r   r~   )rƒ   Útr:   r:   r;   r  ¯  s     z!np_array_split.<locals>.<genexpr>c              	   S   st   t | jƒ}tdd| j|ƒ}g }d}t|ƒD ](}t||t||ƒƒ}| | | ¡ |}q*| | t||t|d ƒƒ ¡ |S ru  )r+   r[   r¼   r   r*   rþ   rU   rv  r:   r:   r;   rÀ   ±  s    
)r   )r   )r   )r   )r|   r   rÀ  ÚListTyper{  r~   ZIterableTypeZiterator_typerä   rÁ  rÂ  ©rÖ   rs  r»   rÀ   r:   r:   r;   Únp_array_split�  s*    


ÿþþ

ÿþ
r|  c                 C   sP   t | tjtjtjfƒr$ddd„}|S t |tjƒr>ddd„}|S t| ||d�S d S )Nr   c                 S   s   t jt  | ¡||d�S r/  )r¸  Úsplitr¹  rr  r:   r:   r;   rÀ   Å  s    znp_split.<locals>.implc                 S   s4   t | j| |ƒ\}}|dkr$tdƒ‚tj| ||d�S )Nr   z0array split does not result in an equal divisionr0  )rt  rQ   rœ   r¸  rq  )rÖ   rs  r»   ro  rí  r:   r:   r;   rÀ   Ë  s    ÿ  ÿr0  )r   )r   )r|   r   rÀ  rz  r{  r~   r|  r{  r:   r:   r;   Únp_splitÀ  s    


r~  c                 C   s   | |k pt  |¡ot  | ¡ S r  )r¸  Úisnanrí  r:   r:   r;   Ú	lt_floatsá  s    r€  Fc                 C   s†   | ||f}z
t | W S  tk
r€   | dkrLtj|r8tnd|dd�}|j}n$| dkrptj|r`tnd|d�}|j}|t |< | Y S X dS )z6
    Get a sort implementation of the given kind.
    r'   NT)ÚltÚ
is_argsortZis_np_arrayr(   )r�  r‚  )	Ú_sortsÚKeyErrorr'   Zmake_jit_quicksortr€  Zrun_quicksortr(   Zmake_jit_mergesortZrun_mergesort)rÇ  Úis_floatr‚  Úkeyrl  Úfuncr:   r:   r;   Úget_sort_funcé  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  r:   rÃ  ©Z	sort_funcr:   r;   Úarray_sort_impl  s    z#array_sort.<locals>.array_sort_impl)rÄ   rˆ  r|   re   r   rÆ  rú  )rg   r5   rK   rÄ   r|  rŠ  r:   r‰  r;   Ú
array_sort   s    
ÿr‹  c                 C   s   t | ƒst d¡‚dd„ }|S )NzArgument "a" must be array-likec                 S   s   |   ¡ }| ¡  |S r  )r¬  rl  )rö  rÏ   r:   r:   r;   Únp_sort_impl  s    z"impl_np_sort.<locals>.np_sort_implrh  )rö  rŒ  r:   r:   r;   Úimpl_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  r:   rÃ  r‰  r:   r;   Úarray_argsort_impl"  s    z)array_argsort.<locals>.array_argsort_implr=   rÉ  )	rÄ   rˆ  rÂ   r|   re   r   rÆ  Úreplacerú  )	rg   r5   rK   rÄ   r|  rÇ  rŽ  ZinnersigZ	innerargsr:   r‰  r;   Úarray_argsort  s    
þ ÿr�  c                 C   s   |j |j ks|jdkst‚|S )Nrª  )r   rm  r   )rg   r5   r¨  r©  rq   r:   r:   r;   Úarray_to_array.  s    r‘  c                 C   s4   dd„ }t ||ƒ}|  ||||g¡}t| ||j|ƒS )Nc                 S   s
   |   d¡S r½   )rº  r9  r:   r:   r;   rÀ   =  s    zarray0d_to_scalar.<locals>.impl)r    rú  r   rÆ   ©rg   r5   r¨  r©  rq   rÀ   rK   rÏ   r:   r:   r;   Úarray0d_to_scalar5  s    
r“  c                 C   s4   dd„ }t ||ƒ}|  ||||g¡}t| ||j|ƒS )Nc                 S   s   t | d ƒS r<  )rÏ  r9  r:   r:   r;   rÀ   H  s    z array_to_unichrseq.<locals>.impl)r    rú  r   rÆ   r’  r:   r:   r;   Úarray_to_unichrseqF  s    
r”  c                 C   s   t ‚dS )zR
    An intrinsic returning a derived array with the given shape and strides.
    Nr·   ©rö  rQ   r‘   r:   r:   r;   Úreshape_uncheckedS  s    r–  c                    s   dd„ ‰ ‡ fdd„}|S )Nc                 S   s   t | tjƒotdd„ | D ƒƒS )Nc                 s   s   | ]}t |tjƒV  qd S r  rx  r,  r:   r:   r;   r  ^  s     z>type_reshape_unchecked.<locals>.check_shape.<locals>.<genexpr>)r|   r   r  rÂ  ©rQ   r:   r:   r;   r#  \  s    ÿz+type_reshape_unchecked.<locals>.check_shapec                    sJ   t | tjƒsd S ˆ |ƒr ˆ |ƒs$d S t|ƒt|ƒkr8d S | jt|ƒdd�S )Nrª  r«  )r|   r   r}   r†   r¬  r•  ©r#  r:   r;   Útyper`  s    z%type_reshape_unchecked.<locals>.typerr:   )rg   r™  r:   r˜  r;   Útype_reshape_uncheckedZ  s    	rš  c                 C   s‚   |j d }|j}t|ƒ| ||d ƒ}t|ƒ| |ƒ}t ||d ¡}t ||d ¡}	t||j||	|j|jd� | 	¡ }
t
| |||
ƒS )Nr   r=   r÷  ró  )rÄ   rÆ   rc   r	   r¤   r´   r€   r’   r�   rÌ   r   )rg   r5   rK   rÄ   rµ   r#  rÖ   rÐ   rQ   r‘   rÏ   r:   r:   r;   Úimpl_shape_uncheckedl  s    
ûr›  c                    s`   |d t jfkrtdd„ ƒ‰ ntdd„ ƒ‰ |d t jfkr@tdƒ‚ntdd„ ƒ‰d	‡ ‡fdd„	}|S )
Nc                 S   s   | j S r  r—  ©r£  rQ   r:   r:   r;   r#  …  s    zas_strided.<locals>.get_shapec                 S   s   |S r  r:   rœ  r:   r:   r;   r#  ‰  s    z*as_strided() strides argument is mandatoryc                 S   s   |S r  r:   )r£  r‘   r:   r:   r;   Úget_strides”  s    zas_strided.<locals>.get_stridesc                    s   t | ˆ | |ƒˆ| |ƒƒ} | S r  )r–  )r£  rQ   r‘   ©r#  r�  r:   r;   Úas_strided_impl˜  s    z#as_strided.<locals>.as_strided_impl)NN)r   r'  r"   rC   )r£  rQ   r‘   rŸ  r:   rž  r;   Ú
as_strided‚  s    


r   c                    s  t |tjƒr>tt| jd ƒƒ‰tt| jd ƒƒ‰tdd„ ƒ‰n^t |tjƒr’t |jtjƒr’tt| jt	|ƒ ƒƒ‰tt| jt	|ƒ ƒƒ‰tdd„ ƒ‰n
t
 d¡‚t|ƒr²tdd„ ƒ‰ nLt |tjƒrÌtdd„ ƒ‰ n2t |tjƒrôt |jtjƒrôtd	d„ ƒ‰ n
t
 d
¡‚d‡ ‡‡‡fdd„	}|S )Nr=   c                 S   s   | fS r  r:   ©Úwindow_shaper:   r:   r;   Úget_window_shape©  s    z-sliding_window_view.<locals>.get_window_shapec                 S   s   | S r  r:   r¡  r:   r:   r;   r£  ²  s    z4window_shape must be an integer or tuple of integersc                 S   s   t t|ƒƒS r  )r    r2   ©r¢  r»   r[   r:   r:   r;   Úget_axis½  s    z%sliding_window_view.<locals>.get_axisc                 S   s   t dd||ƒgS )NÚsliding_window_viewr»   ©r¼   r¤  r:   r:   r;   r¥  Â  s    ÿc                    s   ‡ fdd„|D ƒS )Nc                    s   g | ]}t d dˆ |ƒ‘qS )r¦  r»   r§  rõ  rB  r:   r;   r…   Ì  s   ÿz9sliding_window_view.<locals>.get_axis.<locals>.<listcomp>r:   r¤  r:   rB  r;   r¥  Ê  s    
ÿz2axis must be None, an integer or tuple of integersc           
         sú   ˆ|ƒ}ˆ ||| j ƒ}t|ƒt|ƒkr.tdƒ‚ˆ}ˆ}t| j ƒD ](}t||| j| ƒ}t||| j| ƒ}q@| j }t||ƒD ]n\}}|dk r’tdƒ‚|| |k r¦tdƒ‚|| | d }t|||ƒ}t|||ƒ}t||| j| ƒ}|d7 }qzt| ||ƒ}	|	S )Nz2Must provide matching length window_shape and axisr   z-`window_shape` cannot contain negative valuesz4window_shape cannot be larger than input array shaper=   )	r[   r†   rœ   r2   r*   rQ   r‘   r‡   r–  )
r£  r¢  r»   Z	out_shapeZout_stridesrY   rû   r)  Ztrimmedr;  ©r¥  r£  Zshape_bufferZstride_bufferr:   r;   Úsliding_window_view_implÔ  s8    ÿÿÿ
z5sliding_window_view.<locals>.sliding_window_view_impl)N)r|   r   r~   rŸ   r2   r[   r"   rÀ  re   r†   r   rÁ   r   )r£  r¢  r»   r©  r:   r¨  r;   r¦  Ÿ  s>    ÿÿÿÿ'r¦  c                 C   s   t | tjƒrdd„ }|S d S )Nc                 S   s6   | j dkrdS | j dkr&t|  d¡ƒS d}t|ƒ‚d S )Nr   Fr=   z[The truth value of an array with more than one element is ambiguous. Use a.any() or a.all())ry   r  rº  rœ   )rt  r­   r:   r:   r;   rÀ     s    

zol_bool.<locals>.implr	  rÄ  r:   r:   r;   Úol_boolþ  s    	rª  c                    sn   t |ttjfƒst d¡‚t |ttjfƒs4t d¡‚t | tjƒsJt 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`   t ddˆ|ƒ}t ddˆ|ƒ}|dk r,|ˆ7 }|dk r<|ˆ7 }tˆ ||ƒ}t|||ƒ}t | |¡S )Nznp.swapaxesÚaxis1Úaxis2r   )r¼   r*   r¸  r  )rt  r«  r¬  Z
axes_tuple©Z	axes_listr[   r:   r;   rÀ     s    znumpy_swapaxes.<locals>.impl)
r|   r¡   r   r~   r   rÁ   r}   r[   rŸ   r2   )rt  r«  r¬  rÀ   r:   r­  r;   Únumpy_swapaxes  s    


r®  c                 C   sÀ  t dd| j|ƒ}t| jƒ}d||< tt||jƒƒD ]H\}\}}	|dkrL|	}
n"|	dkrZ|}
n||	krjtdƒ‚|}
t|||
ƒ}q2t||| j| ƒ}t 	| |¡} t 	||¡}|}t
|ƒdkrÚtt
|ƒƒD ]}t||| j| ƒ}qÂ|}t
|ƒdk�rtt
|ƒƒD ]}t||| j|d |  ƒ}qø|j| }t ||f | | j¡}td d d ƒf}t |¡D ]h}t |¡D ]V}| || |  }||| |  }||| |  }t|ƒD ]}|||  ||< �qœ�q`�qR|S )Nznp.take_along_axisr»   r=   z*`arr` and `indices` dimensions don't matchr   )r¼   r[   r    rQ   rÎ  r‡   rœ   r*   r¸  r¼  r†   r2   rs  re   rþ   r?  )rt  r‰   r»   ZNi_origZNk_origÚindices_broadcast_shapeZ	arr_shaperY   Zd1Zd2Únew_valZarr_broadcast_shapeÚNiÚNkÚJrÐ   Znp_s_ÚiiÚkkZa_1dZ
indices_1dZout_1dÚjr:   r:   r;   Ú_take_along_axis_impl-  sX    
ÿ  ÿ  ÿ
r·  c                    s  t | tjƒst d¡‚t |tjƒs,t d¡‚t |jtjƒsDt d¡‚t|ƒrRd}n| j}||jkrlt d¡‚t	t
|jƒƒ‰t|ƒr�‡fdd„}n„t|dƒ t |tjƒs°t d	¡‚|j}|d
k rÈ| j| }|d
k sÚ|| jkrät 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   r:   )r·  r5  ©rt  r‰   r»   )r¯  r:   r;   Útake_along_axis_impl~  s    ÿz1arr_take_along_axis.<locals>.take_along_axis_implr»   zaxis must be a literal valuer   zaxis is out of boundsc                    s   t | ||ˆ ˆˆƒS r  )r·  r¸  ©r±  r²  r¯  r:   r;   r¹  �  s    ÿ)r|   r   r}   r   rÁ   re   r~   r   r[   rŸ   r2   r   r½  r  rÂ   )rt  r‰   r»   Zarr_ndimr¹  r:   rº  r;   Úarr_take_along_axisi  s<    
ÿ

ÿ



r»  Tç        c                 C   sÐ   t | tjƒr`t | tjƒr$ddd„}qÌt | tjƒr<ddd„}qÌt | tjƒrTddd„}qÌt d¡‚nlt| ƒrÂt | j	tjƒr‚ddd„}qÌt | j	tjƒrœdd	d„}qÌt | j	tjƒr¶dd
d„}qÌt d¡‚n
t d¡‚|S )NTr¼  c                 S   s   | S r  r:   ©r£  r¬  Únanr:   r:   r;   rÀ   š  s    znan_to_num_impl.<locals>.implc                 S   sF   t  | ¡r|S t  | ¡r(t  t| ƒ¡jS t  | ¡rBt  t| ƒ¡jS | S r  )r¸  r  ÚisneginfÚfinfor3   r@  ÚisposinfrÓ  r½  r:   r:   r;   rÀ   ž  s    


c                 S   s*   t j| j|d�}t j| j|d�}t||ƒS )N)r¾  )r¸  Ú
nan_to_numr²  r¹  Úcomplex)r£  r¬  r¾  rÅ  rG  r:   r:   r;   rÀ   §  s    z4Only Integer, Float, and Complex values are acceptedc                 S   s   | S r  r:   r½  r:   r:   r;   rÀ   ³  s    c           	      S   s˜   t  | j¡j}t  | j¡j}t  | ¡}|r4t  |¡n|}|j}t|j	ƒD ]J}t  
|| ¡rd|||< qHt  || ¡r||||< qHt  || ¡rH|||< qH|S r  )r¸  rÀ  re   r@  rÓ  r¹  r¬  ró  r2   ry   r  r¿  rÁ  )	r£  r¬  r¾  Zmin_infZmax_infÚx_ÚoutputZoutput_flatrY   r:   r:   r;   rÀ   ¶  s    



c                 S   sD   t  | ¡}|rt  |¡n|}t j|jd|d� t j|jd|d� |S )NF)r¬  r¾  )r¸  r¹  r¬  rÂ  r²  r¹  )r£  r¬  r¾  rÄ  rÅ  r:   r:   r;   rÀ   Ç  s
    
z4The first argument must be a scalar or an array-like)Tr¼  )Tr¼  )Tr¼  )Tr¼  )Tr¼  )Tr¼  )
r|   r   rÖ  r~   rÆ  rÅ  r   rÁ   r   re   )r£  r¬  r¾  rÀ   r:   r:   r;   Únan_to_num_impl•  s,    ÿÿ
rÆ  )N)N)N)r  )r=   )N)N)NNN)NNN)N)N)N)N)N)N)N)N)r   )NNN)r  )N)N)N)r   )r   )r   )r   )F)NN)N)Tr¼  (›  r'  r™  rÊ  rÙ  Zllvmliter   Zllvmlite.irr   Únumpyr¸  Znumbar   r   Z
numba.corer   r   r   r	   r
   Znumba.np.numpy_supportr   r   r   r   r   r   r   r   r   r   Znumba.core.imputilsr   r   r   r   r   r   r   r   r   r   r   Znumba.core.typingr    Znumba.core.typesr!   Znumba.core.extendingr"   r#   r$   r%   r&   Z
numba.miscr'   r(   Znumba.cpythonr)   Znumba.cpython.unsafe.tupler*   r+   r,   Znumba.core.typing.npydeclr-   rŒ  r.   r�  r/   r0   r1   r<   r?   rc   ri   ro   rr   r{   r‚   rŠ   r´   r¶   r¼   rÃ   rÔ   rÑ   rÝ   ZArrayIteratorZBORROWEDrë   r  rÕ   r  rÚ  r~   ró   r  r  r  rM  ÚAnyr  r†   r  r}   r  r  r>  r  r(  r:  r>  rB  rM  rV  r  rq  ru  rx  ry  r{  r•  rž  r©  r®  r´  r¶  r·  r»  r¼  rÃ  rÈ  Zbroadcast_shapesrÔ  r>  rØ  r  rç  rê  rì  rý  ZVarArgrÿ  r  r  rè  Zlogspacer  Zrot90r  r  r"  r&  r'  r(  r*  rU   r2  r8  r+  r;  r<  rG  rI  r[  rZ  r\  rg  rQ   rj  Úuniquerp  r}  r|  rr  r  rƒ  r„  r‰  r³  rŽ  r�  Z
MemoryViewr’  r“  r”  r•  r–  r˜  r›  r�  rŸ  r¡  r¥  r£  r§  rû  rl  rª  r¬  r¯  r­  r°  r±  r¸  r¼  r¶  rÅ  rÆ  ZDTypeZNumberClassrÈ  rÎ  rÐ  rË  r×  rØ  rÛ  r½  rÜ  râ  rã  ræ  rê  ÚBytesrì  Úis_rð  rò  r÷  rû  r  r  r?  rF  rõ  rZ  rV  r[  r]  r^  r_  rø  rb  r`  rc  r?  re  rg  rd  rh  r  ri  ZNumpyNdIterTyperj  rk  rt  rm  rr  rz  r{  rº  r~  r„  rs  rˆ  r�  r�  r=  r‘  r’  r”  r•  r˜  r™  r›  rœ  r   r¡  r¥  rQ  r¦  r§  r¨  r©  rª  r®  r°  Úeyer´  Zdiagr¹  rº  rÃ  rÉ  ZarangerÐ  r	  rÔ  rÖ  r×  rØ  r¬  rÚ  rÞ  rá  râ  ræ  rç  rè  rê  rï  rð  rñ  rø  rù  rö  rü  r  r  r  r  r  r  r  r«   r  r  r  r   r!  r"  r#  r)  r'  Z
atleast_1dr-  Z
atleast_2dr.  Z
atleast_3dr/  r6  r=  r?  rA  rC  r,  rG  rH  rJ  Zcolumn_stackrM  rN  rO  ÚstackrP  rQ  rW  rY  rX  r[  Zvstackr\  r]  Zdstackr^  ra  re  r  rh  r  ri  rn  Úfliprp  rq  r|  r}  r~  rƒ  r€  rˆ  r‹  rl  r�  Zargsortr�  r‘  ZUnicodeCharSeqrÆ  rÅ  rX  ZNPTimedeltaZ
NPDatetimer“  r”  r–  Ztype_callablerš  r›  ÚlibZstride_tricksr   r¦  r  rª  r  r®  r·  Ztake_along_axisr»  rÂ  rÆ  r:   r:   r:   r;   Ú<module>   s¬  $4<	ÿ
E



ÿ
D

(



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

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

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


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

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