
    xKg'             
       H/   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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/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z; ddl<m=Z=m>Z> ddl1m?Z? ddl@mAZBmCZDmEZEmFZFmGZG d ZHd ZId ZJd ZKd ZLd ZMd ZNd ZOd ZP	 dJdZQd ZRd ZS e3eS      d        ZT e"dej                        d         ZVd! ZW e"d"ej                         e(e,j                        d#               ZZ	 dJd$Z[d% Z\d& Z] e"ej                  ej                  ej                         e"ej                  ej                  ej                        d'               Za e"ej                  ej                  ej                        d(        Zc e"ej                  ej                  ej                  ej                        d)        Zf e"egej                        d*        Zh e"d+ej                        d,        Zje d-k  r$ e"d.ej                  ej                        d/        Zk G d0 d1el      Zm G d2 d3em      Zn G d4 d5em      Zo G d6 d7em      Zp G d8 d9em      Zq G d: d;em      Zr G d< d=el      Zsd> Zt e"ej                  ej                  ej                        d?        Zud@ ZvdA ZwdB ZxdC ZydD ZzdE Z{dF Z|dG Z}e5dH        Z~e5dI        Ze2dJ        ZdK Z e3e	j                        dL        Ze2dM        Z e3e	j
                        dN        Z e3e	j                        dO        ZdP ZdQ Z e"dRej                        dS        ZdT Z e"dRej                  ej                        dU        Z e"dRej                   ej                  ej                              dV        Z e3e	j                         dJdW       Z e#ej                  dX      dY        Z e3e	j&                        dKdZ       Z e3e	j*                        dKd[       Z e3e	j.                        dLd\       Zd] Zd^ Z e"d_ej                  ej                        d`        Z e"d_ej                   ej                  ej                              da        Z e3e	j:                        db        Z e3e	j>                        dc        Z e3e	jB                        dJdd       Z e"deej                        df        Z e"e	jH                  ej                        dg        Z e"dhej                        di        Ze2dj        Ze2dk        Z e3e	jR                        dJdl       Z e4ej                  dm      dMdn       Zdo Z e3e	jZ                        dp        Z e3e	j^                        dq        Z e3e	jb                        dr        Z e3e	jf                        ds        Ze2dt        Z ejh                  ej                  du      dv        Ze5dw        Zdx Z e3edyz      d{        Z e"d|ej                  ejt                        d}        Z e#ej                  d~      d        Z e#ej                  d       e#ejz                  d      d               Z e#ej                  d       e#ejz                  d      d               Z e#ej                  d       e#ejz                  d      d               Z e#ej                  d      d        Z e#ej                  d       e#ejz                  d      d               Z e#ej                  d       e#ejz                  d      d               Z e#ejz                  d      d        Z e#ejz                  d      d        Z e#ejz                  d      d        Z e#ejz                  d      d        Z e#ej                  d      d        Z e#ej                  d      d        Z e&ej                  ej                         e&ej                  ej                        d               Zd Z e#ej                  d      d        Z e#ej                  d       e#ej                  d      d               Z e#ej                  d      d        Z e#ej                  d      d        Z e#ej                  d      d        Zd Z e4ej                  d       e4ej                  d      d               Zd Z  e#ej                  d      e׫         e#ej                  d      e׫        e"dej                  ej                        d        Z e$ej                        d        Z e"dej                  ej`                        d        Z e$ej                        d        Z e%ej                        d        Z e"dej                  ej`                        d        Z e"dej                  ej                        d        Z e"dej                  ej`                  ej                        d        Z e"dej                  ej                  ej                        d        Z e'ej                        d        Z e'ej                        d        Z e'ej                        d        Z e"ej                  ej                  ej                        d        Z e6ej                  d      d        Zd Zd Z	 	 dMdZ	 dJdZd Zd Zd Z e#ej                  d      d        Z e"d"ej                         e(e,j                        dÄ               Z e"ej                  ej                  ej                        dĄ        Z e"ej                  ej                  ej                  ej                        dń        Z e"egej                        dƄ        Z e"e	j                  ej                        dǄ        Z e"d"ej                         e(e,j                        dȄ               Z e"e ej                  ej                               e"e	j                   ej                  ej                              dɄ               Z e"eej                         e"e	j                  ej                        dʄ               Z e"d"ej                          e(e,j                        d˄               Z e"e	j                  ej                        d̄        Z e"d"ej                         e(e,j                        d̈́               Z e"ej                  ej                  ej                        d΄        Zdτ Z e?ej                  dЫ      dф        Z	d҄ Z
e5dӄ        ZdԄ ZdՄ Zdք Zdׄ Ze5d؄        Z e3e	j"                        efdل       Ze5dڄ        Z e3e	j*                        dJdۄ       Ze5d܄        Z e4ej                  dݫ      dބ        Z e3e	j2                        efd߄       Z e3e	j6                        dJd       Z e3e	j:                        dJd       Z e3e	j>                        dJd       Z  e3e	jB                        dJd       Z" e3e	jF                        dJd       Z$ e3e	jJ                        dJd       Z&d Z' ejf                  e'      d        Z( ejf                  e	jR                        ddefd       Z* e3e	jV                        dNd       Z, e3e	jZ                        d        Z. e3e	j^                        dNd       Z0 e3e	jb                         e4ej                  d      d               Z2d Z3 e3e	jh                        dMd       Z5 e3e	jl                        dKd       Z7d Z8e5d        Z9 e"dej                        d        Z: e3e	jv                        d        Z<d Z=e5d        Z> e3e	j~                        d        Z@ e3e	j                        d        ZB e"dej                  ejt                         e"dej                  ej`                        d               ZCe5d        ZD e3e	j                        efd       ZF e3e      dJd       ZG e3e      dJd       ZHd  ZId ZJd ZKd ZLd ZMd ZNd ZOd ZPe5d        ZQ e3e	j                        dJd	       ZSd
 ZTd ZUd ZVd ZWe5d        ZX e3e	j                        d        ZYd ZZd Z[ e3e	j                        d        Z] e3e	j                        d        Z_ e3e	j                        d        Zad Zbd Zcd Zdd Zee5d        Zf e3e	j                        dNd       Zhd Zie5d        Zj e3e	j                        d        Zld Zme5d        Zn e3e	j                        dNd        Zpd! Zqe5d"        Zr e3e	j                        d#        Zte5d$        Zu e3e	j                        d%        Zwe d-k\  r  e3e	j                        ew       e5d&        Zy e3e	j                        d'        Z{ ejh                  ej                  d(      d)        Z| ejh                  ej                  d*      d+        Z} e3e	j                        d,        Z e3e	j                         d-        Ze5d.        Z e3e	j                        d/        Z e3e	j
                        dNd0       Z e3e	j                        dNd1       Z e3e	j                        d2        Z e3e	j                        d3        Z e3e	j                        d4        Zi Zd5 ZdOd6Zd7 Z e"d8ej                        d9        Z e3e	j(                        d:        Z e"d;ej                  ej`                         e"e	j,                  ej                  ej`                        d<               Z e&ej                  ej                        d=        Z e&ej                  ej2                         e&ej                  ej4                         e&ej                  ej                         e&ej                  ej6                         e&ej                  ej8                         e&ej                  ej:                         e&ej                  ej<                        d>                                                  Z e&ej                  ej2                        d?        Zd@ Z ejD                  e      dA        Z e"eej                  ej                  ej                        dB        Z ejf                  e	jJ                  jL                  jN                        dPdC       Z ejf                  e	jJ                  jL                  jP                        dJdD       Z e3e      dE        Z e3e	jV                        dF        Ze2dG        Z e3e	j\                        dH        Z e3e	j`                        dQdI       Zy(R  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
from_dtypecarrayfarrayis_contiguous
is_fortrancheck_is_integertype_is_scalar
lt_complex	lt_floats)type_can_asarrayis_nonelikenumpy_version)lower_builtinlower_getattrlower_getattr_genericlower_setattr_generic
lower_castlower_constantiternext_implimpl_ret_borrowedimpl_ret_new_refimpl_ret_untrackedRefType)	signature)StringLiteral)register_jitableoverloadoverload_method	intrinsicoverload_attribute)	quicksort	mergesort)slicing)tuple_setitembuild_full_slice_tuple)overload_classmethod)parse_dtypeparse_shape_parse_nested_sequence_sequence_of_arrays_choose_concatenation_layoutc                     t        |j                  |      t        |j                  |      g}| j                  j                  |      }|j	                  d|       y)zz
    Set the "range" metadata on a load instruction.
    Note the interval is in the form [lower_bound, upper_bound).
    rangeN)r   typemoduleadd_metadataset_metadata)builderloadlower_boundupper_boundrange_operandsmds         U/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/np/arrayobj.pyset_range_metadatarC   ,   sK    
 tyy+6tyy+68N		$	$^	4Bgr"    c                 ^    d|j                   j                  dz
  z  dz
  }t        | |d|       y)zF
    Mark the result of a load instruction as positive (or zero).
       r   N)r8   widthrC   )r<   r=   r?   s      rB   mark_positiverH   7   s.     1,-2Kwa5rD   c                       j                   t        j                        j                   G  f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                   <     e Zd Z fdZefd       Z xZS )make_array.<locals>.ArrayStructc                 d   t        
	      }	 | j                  j                  d|      }| j                  j                  	   }| j                  |      }|#t        j                  | j                  |d      }n|} || j                  |f      }||fS # t        $ r t        |   |      cY S w xY w)N	__array__T)zfill)r$   _contextget_functionNotImplementedErrorsuper
_make_refsdata_model_manager_get_be_typer
   alloca_once_builder)selfrefsig
array_impl	datamodelbe_type	outer_refArrayStruct	__class__
array_typereal_array_types          rB   rS   z*make_array.<locals>.ArrayStruct._make_refsM   s    OZ8C@!]]77SI

 88DI''	2G{#//w6:<	  	 T]]YL9Cc>! ' @[$:3??@s   B B/.B/c                 H   | j                   }dk(  rj                  | d      S | j                  d      }g }t              D ]H  }t	        j
                  ||d|      }|j                  |      }|j                  |       t        ||       J t	        j                  ||      S )z\
            Override .shape to inform LLVM that its elements are all positive.
            r   shape)
rW   __getattr___get_ptr_by_namer7   r
   gep_inboundsr=   appendrH   
pack_array)	rX   r<   ptrdimsidimptrr=   basendims	          rB   rd   z%make_array.<locals>.ArrayStruct.shapea   s    
 mmGqy''g66 ''0CD4[ --gsAqA||F+D!gt,	 ! %%gt44rD   )__name__
__module____qualname__rS   propertyrd   __classcell__)r`   r_   ra   rn   ro   rb   s   @rB   r_   rK   K   s    	"( 
	5 
	5rD   r_   )as_arrayr
   create_struct_proxyro   )ra   r_   rn   ro   rb   s   `@@@@rB   
make_arrayrw   ?   sE     !))O&&7DD+5 +5d +5Z rD   c                 Z    | j                  |j                        }| j                  |      S )zB
    Return the item size for the given array or buffer type.
    )get_data_typedtypeget_abi_sizeof)contextra   lltys      rB   get_itemsizer~   {   s+       !1!12D!!$''rD   c                 `    |j                   rdnd}| j                  ||j                  ||      S )z3
    Load the item at the given array pointer.
    NrF   align)alignedunpack_valuerz   )r|   r<   arraytyrj   r   s        rB   	load_itemr      s6     OODE&+   - -rD   c                 b    |j                   rdnd}| j                  ||j                  |||      S )z4
    Store the item at the given array pointer.
    NrF   r   )r   
pack_valuerz   )r|   r<   r   valrj   r   s         rB   
store_itemr      s1     OODEgw}}c3eLLrD   c                     |j                   r;| j                  |||t        j                        }t	        j
                  |||      }|S | j                  |||t        j                        }|S )zM
    Fix the integer index' type and value for the given dimension size.
    )signedcastr   intpr-   	fix_indexuintp)r|   r<   idxtyidxsizeinds         rB   fix_integer_indexr      s]     ||ll7C

;d3 J ll7C<JrD   c                    t        |t        j                        rn|j                  dk(  r_t        |j                  t        j
                        sJ  t        |      | ||      }t        | |||j                        }|j                  |fS ||fS )zS
    Normalize the index type and value.  0-d arrays are converted to scalars.
    r   )	
isinstancer   Arrayro   rz   Integerrw   r   data)r|   r<   r   r   idxaryidxvals         rB   normalize_indexr      sv     %%%**/%++u}}555"E"7GS97GUFKK@{{F""czrD   c                     t        |      r4t        t        ||      D cg c]  \  }}t        | |||       c}} \  }}||fS c c}}w )z^
    Same as normalize_index(), but operating on sequences of
    index types and values.
    )lenzipr   )r|   r<   index_typesindicesr   r   s         rB   normalize_indicesr      s`    
 7|"7:;7P%'7P &5Wgu58&:7P%'  (W 	%'s   A
c                 "   | j                   }| j                  }| j                  }	t        j                  t        j
                  dd      }
|j                  |
   }t        |j                        }t        |	j                        }||z  |k7  r6||z
  }d| j                   dt        |      dkD  rdnd d| d}t        |      |*t        |j                  |	j                  d
            d	      }|j                  t        j                        }t!        |t"        t$        f      rt'        j(                  |||      }t!        |t"        t$        f      rt'        j(                  |||      }t!        |t*              r ||      }t-        |||||      }|.t        |j                  |	j                  d            d	      |d<   n||d<   |j/                  t        j                  d      }t'        j0                  |||j2                  j4                        }|D ]  }|j7                  ||dg      } ||d<   t        |j9                               }||k7  rt        dj;                  ||z
              |j=                         D ]  \  }}t?        | ||        | S )z
    Helper function for populating array structures.
    This avoids forgetting to set fields.

    *shape* and *strides* can be Python tuples or LLVM arrays.
    rF   CzThe datamodel for type z is missing fields  .Nmeminfo)rd   stridesr   itemsizer   parentnswflagsnitemszmissing {0}) rO   rW   
_datamodelr   r   float64rT   set_fields_fe_typer   
ValueErrorr   get_value_typeget_typer   r   tuplelistr
   ri   intdictget_constantunpack_tupler8   countmulkeysformatitemssetattr)arrayr   rd   r   r   r   r   r|   r<   r\   standard_arraystandard_array_type_datamodelrequired_fieldsdatamodel_fieldsmissingmsgintp_tattrsr   unpacked_shapeaxlen
got_fieldskvs                           rB   populate_arrayr      sq    nnGnnG  I [[37N$+$>$>~$N!7??@O9,,- 	**>!$44((8 9!'lQ.sB7q	Do711y)+,02 ##EJJ/F%%'""7E6:'E4=)$$Wgv>(C (#u " 	#E ~"7#9#9x($*+/1h !h!!%**a0F))'5%**:J:JKNVU5':  E(O UZZ\"J_$--o
.JKLL 1q!  LrD   c                 n   |j                   }|j                  }|j                  t        j                  d      }t        j                  ||j                  | j                        }|D ]  }|j                  ||dg      } ||_
        |j                  t        j                  t        ||             |_        y)z
    Update some auxiliary information in *array* after some of its fields
    were changed.  `itemsize` and `nitems` are updated.
    rF   r   r   N)rO   rW   r   r   r   r
   r   rd   ro   r   r   r~   r   )arytyr   r|   r<   r   r   r   s          rB   update_array_infor      s    
 nnGnnG !!%**a0F))'5;;

KNVU5':  EL))%***6w*FHENrD   c                     t               )z/Constrain axis values to valid positive values.rQ   )	func_namearg_namero   axiss       rB   normalize_axisr     s    

rD   c                     t        | t              st        j                  d      t        |t              st        j                  d      | j                   d|j                   df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                 F    |dk  r||z  }|dk  s||k\  rt              |S Nr   r   )r   r   ro   r   r   s       rB   implz&normalize_axis_overloads.<locals>.impl#  s/    !8DLD!8tt|S/!rD   )r   r%   r	   TypingErrorliteral_value)r   r   ro   r   r   r   s        @rB   normalize_axis_overloadsr     sr    i/  !CDDh.  !BCC ""
#;x/E/E.F G4 	4 
 KrD   getiterc                    |j                   \  }|\  }| j                  ||j                        }| j                  t        j
                  d      }t        j                  ||      }||_        ||_	        | j                  r| j                  j                  |||       |j                         }	t        | ||j                  |	      }
|
S r   )argsmake_helperreturn_typer   r   r   r
   alloca_once_valueindexr   
enable_nrtnrtincref	_getvaluer!   )r|   r<   rZ   r   r   r   iterobjzeroindexptrresouts              rB   getiter_arrayr   .  s    IWGU!!'3??;G

A.D(($7HGMGM 7GU3



C 7GS__c
BCJrD   c           
         t        j                  ||j                  |j                        }t        j                  ||j                  |j                        }|j                  |d   |      }t        j                  ||j                  |      }	|dd }
|dd }t        |t        j                        r"t        | |||||	|
|      }|j                         S |
rJ t        | |||	      S )z1 Evaluate `ary[idx]`, where idx is a single int. r   r   rF   N)r
   r   rd   ro   r   r   pointer_addr   r   r   Buffer	make_viewr   r   )r|   r<   r   r   aryr   shapesr   offsetdataptrview_shapesview_stridesretarys                rB   _getitem_array_single_intr  F  s     !!'399EJJGF""7CKKuzzJG[[S)F!!'388V<G*K12;L+u||,7GUC"K?!! '5'::rD   iternextc           	      p   |j                   \  }|\  }|j                  }| j                  |||      } t        |      | ||j                        }	t        j                  ||	j                  d      \  }
|j                  |j                        }|j                  d||
      }|j                  |       |j                  |      5  t        | ||j                  ||	|      }|j                  |       t        j                   ||      }|j#                  ||j                         d d d        y # 1 sw Y   y xY w)NvaluerF   r   <)r   ra   r   rw   r   r
   r   rd   r=   r   icmp_signed	set_validif_thenr  
yield_typeyield_increment_indexstore)r|   r<   rZ   r   resultitertyiterr   r   r   r   r   is_validr  nindexs                  rB   iternext_arrayr  [  s    xxHVFTG!!'6!>G
*W
gwgmm
DC""7CIIQ?GFLL'E""3v6H
X		")Wf//#u
 	e((%8fgmm, 
#	"	"s   AD,,D5c           	         | j                  t        j                  d      }| j                  t        j                  d      }t        j                  ||j
                  |j                        }	t        j                  ||j                  |j                        }
g }g }g }t        |D cg c]  }t        |      s| c}      }d}t        ||      D ]  \  }}|t        j                  u rm|j                  t        |      z
  dz   |z   }t        |      D ]@  }|j                  |       |j                  |	|          |j                  |
|          |dz  }B t        |t        j                        r| j!                  |||      }t#        j$                  | |||       t#        j&                  |||	|          |j                  |j(                         t#        j*                  ||      }t#        j,                  |||
|         }|j                  |       |j                  |       nt        |t        j.                        rBt1        | ||||	|         }|rt        j2                  | |||	|   |       |j                  |       nAt        |      r(|j                  |       |j                  |       |dz  }nt5        d|      |dz  } ||j                  k  sJ ||j                  k  r=|j                  |	|          |j                  |
|          |dz  }||j                  k  r=t        j6                  | ||||dd      }|||fS c c}w )z
    Perform basic indexing on the given array.
    A (data pointer, shapes, strides) tuple is returned describing
    the corresponding view.
    r   rF   r  unexpected index type: F
wraparoundboundscheck)r   r   r   r
   r   rd   ro   r   r   r   r   ellipsisr7   rh   r   	SliceTyper   r-   guard_invalid_slice	fix_slicestartget_slice_length
fix_strider   r   do_boundscheckrQ   get_item_pointer)r|   r<   r   r   r   r   r  r   oner   r   output_indicesoutput_shapesoutput_stridesr   num_newaxesaxindexvalr   	n_missingrl   sliceshstr   r   s                             rB   basic_indexingr.  w  s    

A.D


uzz1
-C!!'399ejjAF""7CKKDGNMNkFks[5EskFGK	
Bw4%ENN"

S\1A5CI9%%%d+$$VBZ0%%gbk2a	 &
 eU__-''h'GE''%GgufRj9!!%++.))'59B##GUGBK@B  $!!"%u}}-#GWeX$*2J0C&&wfRj"M!!#&  %!!$'!GB%U&LMM
aA 5F 
uzz/VBZ(gbk*
a uzz/ &&w'527ULG ]N33a Gs   &M7Mc           	           t        |      | |      }t        |||||j                  |j                  |j                         |S )zF
    Build a view over the given array with the given parameters.
    r   rd   r   r   r   r   )rw   r   r   r   r   )	r|   r<   r   r   r   r   r   r   r  s	            rB   r   r     sF    
 %Z$Wg6F6"LL;;**& MrD   c           
          t        | |||||| j                        \  }}}	t        |t        j                        r"t        | |||||||	      }
|
j                         S |rJ t        | |||      S )zp
    Return the result of indexing *ary* with the given *indices*,
    returning either a scalar or a view.
    r  )r.  enable_boundscheckr   r   r   r   r   r   )r|   r<   r   r   r   r   r   r   r   r   r  s              rB   _getitem_array_genericr4    s     	w['#*#=#=	? 'G[, +u||,7GUC"K?!! '5'::rD   c           	          |j                   \  }}|\  }}|j                  dk\  sJ  t        |      | ||      }t        | ||j                  |||f|f      }t        | ||j                  |      S )z4
    Basic indexing with an integer or a slice.
    rF   )r   ro   rw   r4  r   r    	r|   r<   rZ   r   r   r   r   r   r   s	            rB   getitem_arraynd_intpr7    su     88LE5HC::??
*U
GWc
2C
 '3??!&eXv?CWgsDDrD   c           
      z   |j                   \  }}|\  }} t        |      | ||      }|j                  }t        j                  ||t        |            }	t        | |||	      \  }}	t        d |D              rt        | |||||||	      S t        | ||j                  ||||	      }
t        | ||j                  |
      S )z2
    Basic or advanced indexing with a tuple.
    r   c              3   P   K   | ]  }t        |t        j                           y wNr   r   r   ).0tys     rB   	<genexpr>z&getitem_array_tuple.<locals>.<genexpr>   s     
=2:b%++&   $&)r   rw   r   r
   r   r   r   anyfancy_getitemr4  r   r    )r|   r<   rZ   r   r   tuptyr   tupr   r   r   s              rB   getitem_array_tuplerD    s    
 88LE5HC
*U
GWc
2C++K""7Cs5zBG,Wg-8'CK 
=
==WgsD"Cg? 	? !'3??!&['CCWgsDDrD   c           	         |j                   \  }}}|\  }}}	t        |t        j                        r.|j                  }
t	        j
                  ||t        |            }n|f}
|f} t        |      | ||      }t        | ||
|      \  }
}	 t        | ||||
|| j                        \  }}}t        |      }|rt        | ||||
|      S | j                  ||	||j                        }	t!        | |||	       y# t        $ r d}Y Mw xY w)zH
    array[a] = scalar_or_array
    array[a,..,b] = scalar_or_array
    r   r2  TN)r   r   r   	BaseTupler
   r   r   rw   r   r.  r3  boolrQ   fancy_setslicer   rz   r   )r|   r<   rZ   r   r   r   valtyr   r   r   r   r   r   r   r   use_fancy_indexings                   rB   setitem_arrayrK  
  s&    ((E5%MCc%)kk&&w3u:Fh&
*U
GWc
2C -Wg-8'CK*7GUCg'.'A'AC 	! "&\ gwT)74 	4 ,,wUEKK
8CwW5  "!"s   
 C5 5DDc                     |j                   \  }|\  }t        |      } || ||      }|j                  }|j                  |d      }t	        | ||j
                  |      S r   )r   rw   rd   extract_valuer"   r   )	r|   r<   rZ   r   r   r   arysttyshapearyr   s	            rB   	array_lenrP  3  s\    xxHUFSG
'7C
(CyyH


!
,CgwEErD   z
array.itemc           	      l   |j                   \  }|\  } t        |      | ||      }|j                  }|j                  |j	                  d||j                  d            d      5  d}| j                  j                  |t        |f       d d d        t        | |||j                        S # 1 sw Y   !xY w)N!=rF   Flikelyz>item(): can only convert an array of size 1 to a Python scalar)r   rw   r   r
  r  r8   	call_convreturn_user_excr   r   r   )r|   r<   rZ   r   r   r   r   r   s           rB   
array_itemrW  >  s    XXFEDC
*U
GWc
2CZZF	,,T66;;q>J % 
 
'N))':vF
'
 Wguchh77
' 
's   %%B**B3)   r   zarray.itemsetc           	         |j                   \  }}|\  }}||j                  k(  sJ  t        |      | ||      }|j                  }|j	                  |j                  d||j                  d            d      5  d}	| j                  j                  |t        |	f       d d d        t        | ||||j                         | j                         S # 1 sw Y   2xY w)NrR  rF   FrS  z/itemset(): can only write to an array of size 1)r   rz   rw   r   r
  r  r8   rU  rV  r   r   r   get_dummy_value)
r|   r<   rZ   r   r   rI  r   r   r   r   s
             rB   array_itemsetr[  N  s    xxuS###j#6__W00vv{{1~N$)  +CC--gzC6J+
 	7GUC:&&((+ +s   8%CCc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	Indexerzq
    Generic indexer interface, for generating indices over a fancy indexed
    array on a single dimension.
    c                     t         )ze
        Prepare the indexer by initializing any required variables, basic
        blocks...
        r   rX   s    rB   preparezIndexer.preparei  
    
 "!rD   c                     t         )z=
        Return this dimension's size as an integer.
        r   r_  s    rB   get_sizezIndexer.get_sizep  
     "!rD   c                     t         )z;
        Return this dimension's shape as a tuple.
        r   r_  s    rB   	get_shapezIndexer.get_shapev  rd  rD   c                     t         )z}
        Return a half-open [lower, upper) range of indices this dimension
        is guaranteed not to step out of.
        r   r_  s    rB   get_index_boundszIndexer.get_index_bounds|  ra  rD   c                     t         )aW  
        Start indexation loop.  Return a (index, count) tuple.
        *index* is an integer LLVM value representing the index over this
        dimension.
        *count* is either an integer LLVM value representing the current
        iteration count, or None if this dimension should be omitted from
        the indexation result.
        r   r_  s    rB   	loop_headzIndexer.loop_head  s
     "!rD   c                     t         )z)
        Finish indexation loop.
        r   r_  s    rB   	loop_tailzIndexer.loop_tail  rd  rD   N)
rp   rq   rr   __doc__r`  rc  rf  rh  rj  rl   rD   rB   r]  r]  c  s%    
""""	""rD   r]  c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
EntireIndexerz:
    Compute indices along an entire array dimension.
    c                     || _         || _        || _        || _        || _        | j                   j                  t        j                        | _        y r:  )	r|   r<   r   r   dimr   r   r   ll_intp)rX   r|   r<   r   r   rr  s         rB   __init__zEntireIndexer.__init__  s?    
||225::>rD   c                 $   | j                   }|j                  | j                  j                  | j                        | _        t        j                  || j                        | _	        |j                         | _        |j                         | _        y r:  )r<   rM  r   rd   rr  r   r
   rV   rs  r   append_basic_blockbb_startbb_endrX   r<   s     rB   r`  zEntireIndexer.prepare  sc    ,,))$((..$((C	(($,,?
224002rD   c                     | j                   S r:  r   r_  s    rB   rc  zEntireIndexer.get_size  s    yyrD   c                     | j                   fS r:  r{  r_  s    rB   rf  zEntireIndexer.get_shape  s    		|rD   c                 <    | j                  d      | j                  fS r   rs  r   r_  s    rB   rh  zEntireIndexer.get_index_bounds      Q++rD   c                    | j                   }| j                   j                  t        | j                  d      | j                         |j                  | j                         |j                  | j                         |j                  | j                        }|j                  |j                  d|| j                        d      5  |j                  | j                         d d d        ||fS # 1 sw Y   ||fS xY wNr   >=FrS  )r<   r  r   rs  r   branchrw  position_at_endr=   r
  r  r   rx  )rX   r<   	cur_indexs      rB   rj  zEntireIndexer.loop_head  s    ,,8DLL!4djjAt}}%.LL,	__W00y$))L$)  +NN4;;'+ )##+ )##s   C..C:c                    | j                   }t        j                  ||j                  | j                              }|j                  || j                         |j                  | j                         |j                  | j                         y r:  )
r<   r
   r  r=   r   r  r  rw  r  rx  rX   r<   
next_indexs      rB   rl  zEntireIndexer.loop_tail  s^    ,,,,Wgll4::6NO
j$**-t}}%,rD   Nrp   rq   rr   rm  rt  r`  rc  rf  rh  rj  rl  rn  rD   rB   rp  rp    s*    ?3,
$-rD   rp  c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
IntegerIndexerz0
    Compute indices from a single integer.
    c                     || _         || _        || _        | j                   j                  t        j
                        | _        y r:  )r|   r<   r   r   r   r   rs  )rX   r|   r<   r   s       rB   rt  zIntegerIndexer.__init__  s1    ||225::>rD   c                      y r:  rn  r_  s    rB   r`  zIntegerIndexer.prepare      rD   c                 .    t        | j                  d      S NrF   )r   rs  r_  s    rB   rc  zIntegerIndexer.get_size  s    a((rD   c                      yNrn  rn  r_  s    rB   rf  zIntegerIndexer.get_shape  s    rD   c                     | j                   | j                  j                  | j                   | j                               fS r:  )r   r<   addrc  r_  s    rB   rh  zIntegerIndexer.get_index_bounds  s,    $,,**488T]]_EFFrD   c                     | j                   d fS r:  )r   r_  s    rB   rj  zIntegerIndexer.loop_head  s    xx~rD   c                      y r:  rn  r_  s    rB   rl  zIntegerIndexer.loop_tail  r  rD   Nr  rn  rD   rB   r  r    s+    ?)GrD   r  c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
IntegerArrayIndexerz;
    Compute indices from an array of integer indices.
    c                     || _         || _        || _        || _        || _        |j
                  dk(  sJ | j                   j                  t        j                        | _	        y r  )
r|   r<   r   r   r   ro   r   r   r   rs  )rX   r|   r<   r   r   r   s         rB   rt  zIntegerArrayIndexer.__init__  sO    
	zzQ||225::>rD   c                    | j                   }t        j                  || j                  j                        d   | _        t        j                  || j                        | _        |j                         | _
        |j                         | _        y r   )r<   r
   r   r   rd   idx_sizerV   rs  	idx_indexrv  rw  rx  ry  s     rB   r`  zIntegerArrayIndexer.prepare  sf    ,,,,Wdkk6G6GHK ,,WdllC224002rD   c                     | j                   S r:  r  r_  s    rB   rc  zIntegerArrayIndexer.get_size  s    }}rD   c                     | j                   fS r:  r  r_  s    rB   rf  zIntegerArrayIndexer.get_shape  s    rD   c                 <    | j                  d      | j                  fS r   r~  r_  s    rB   rh  z$IntegerArrayIndexer.get_index_bounds  r  rD   c                    | j                   }| j                   j                  t        | j                  d      | j                         |j                  | j                         |j                  | j                         |j                  | j                        }|j                  |j                  d|| j                        d      5  |j                  | j                         d d d        t        | j                  || j                  j                   | j                  | j"                  |      }t%        | j                  || j                  j                   || j&                        }||fS # 1 sw Y   xY wr  )r<   r  r   rs  r  r  rw  r  r=   r
  r  r  rx  r  r|   r   rz   r   r   r   )rX   r<   r  r   s       rB   rj  zIntegerArrayIndexer.loop_head  s   ,,8DLL!4dnnEt}}%.LL0	__i?  
 NN4;;'	
 *LL'4::#3#3TZZ
 "$,,"&**"2"2E499Fi
 
s   E''E0c                    | j                   }t        j                  ||j                  | j                              }|j                  || j                         |j                  | j                         |j                  | j                         y r:  )
r<   r
   r  r=   r  r  r  rw  r  rx  r  s      rB   rl  zIntegerArrayIndexer.loop_tail  sb    ,,,,W-4\\$..-IK
j$..1t}}%,rD   Nr  rn  rD   rB   r  r    s*    ?3 , *-rD   r  c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
BooleanArrayIndexerz>
    Compute indices from an array of boolean predicates.
    c                     || _         || _        || _        || _        |j                  dk(  sJ | j                   j                  t        j                        | _        t        | j                  d      | _
        y NrF   r   )r|   r<   r   r   ro   r   r   r   rs  r   r   )rX   r|   r<   r   r   s        rB   rt  zBooleanArrayIndexer.__init__(  sZ    
zzQ||225::>T\\1-	rD   c                    | j                   }t        j                  || j                  j                        d   | _        t        j                  || j                        | _        t        j                  || j                        | _	        |j                         | _        |j                         | _        |j                         | _        y r   )r<   r
   r   r   rd   r   rV   rs  r  r   rv  rw  bb_tailrx  ry  s     rB   r`  zBooleanArrayIndexer.prepare1  s    ,,(($++2C2CDQG	 ,,WdllC(($,,?
224113002rD   c           	         | j                   }t        j                  || j                        }t        j                  || j
                        5 }|j                  |      }t        | j                  || j                  j                  | j                  | j                  |j                        }|j                  ||j                  ||j                              }|j!                  ||       d d d        |j                  |      S # 1 sw Y   xY wr:  )r<   r
   r   r   	for_ranger   r=   r  r|   r   rz   r   r   r  zextr8   r  )rX   r<   r   loopcpreds         rB   rc  zBooleanArrayIndexer.get_size:  s    ,,))'499=w		2dU#A,gtzz'7'7

DKKD Aw||D!&&9:AMM!U# 3 ||E"" 32s   BDDc                 $    | j                         fS r:  rc  r_  s    rB   rf  zBooleanArrayIndexer.get_shapeI      !!rD   c                 <    | j                  d      | j                  fS r   r~  r_  s    rB   rh  z$BooleanArrayIndexer.get_index_boundsL  s     Q++rD   c                    | j                   }| j                   j                  | j                  | j                         | j                   j                  | j                  | j                         |j                  | j                         |j                  | j                         |j                  | j                        }|j                  | j                        }|j                  |j                  d|| j                        d      5  |j                  | j                         d d d        t        | j                  || j                  j                   | j                  | j"                  |      }|j                  |j%                  |            5  |j                  | j&                         d d d        t)        j*                  ||      }|j                  || j                         ||fS # 1 sw Y   xY w# 1 sw Y   KxY w)Nr  FrS  )r<   r  r   r  r   r  rw  r  r=   r
  r  r   rx  r  r|   r   rz   r   not_r  r
   r  )rX   r<   r  	cur_countr  
next_counts         rB   rj  zBooleanArrayIndexer.loop_headQ  sh   ,,499dnn5499djj1t}}%.LL0	LL,	__W00y$))L$)  +NN4;;'+ )LL'4::#3#3TZZ
 __W\\$/0NN4<<( 1 ,,Wi@
j$**-)##+ + 10s   G'G3'G03G<c                    | j                   }|j                  | j                         |j                  | j                         t	        j
                  ||j                  | j                              }|j                  || j                         |j                  | j                         |j                  | j                         y r:  )r<   r  r  r  r
   r  r=   r  r  rw  rx  r  s      rB   rl  zBooleanArrayIndexer.loop_taili  s    ,,t||$-,,W-4\\$..-IK
j$..1t}}%,rD   Nr  rn  rD   rB   r  r  #  s*    .3#",
$0-rD   r  c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
SliceIndexerz(
    Compute indices along a slice.
    c                     || _         || _        || _        || _        || _        || _        || _        | j                   j                  t        j                        | _
        t        | j                  d      | _        y r   )r|   r<   r   r   rr  r   r+  r   r   r   rs  r   r   )rX   r|   r<   r   r   rr  r   r+  s           rB   rt  zSliceIndexer.__init__y  s_    


||225::>T\\1-	rD   c                    | j                   }|j                  | j                  j                  | j                        | _        t        j                  | j                  || j                  | j                         t        j                  || j                  | j
                         t        j                  || j                  j                        | _        t        j                   || j"                        | _        t        j                   || j"                        | _        |j)                         | _        |j)                         | _        y r:  )r<   rM  r   rd   rr  dim_sizer-   r  r|   r   r+  r  r
   
is_neg_intstepis_step_negativerV   rs  r   r   rv  rw  rx  ry  s     rB   r`  zSliceIndexer.prepare  s    ,,--dhhnndhhG##DLL'4::$(JJ	0'4::t}}= ' 2 27DJJOO L(($,,?
(($,,?
224002rD   c                 V    t        j                  | j                  | j                        S r:  )r-   r  r<   r+  r_  s    rB   rc  zSliceIndexer.get_size  s    ''djjAArD   c                 $    | j                         fS r:  r  r_  s    rB   rf  zSliceIndexer.get_shape  r  rD   c                 d    t        j                  | j                  | j                        \  }}||fS r:  )r-   get_slice_boundsr<   r+  )rX   loweruppers      rB   rh  zSliceIndexer.get_index_bounds  s*    //djjIue|rD   c           	      (   | j                   }| j                   j                  | j                  j                  | j                         | j                   j                  | j
                  | j                         |j                  | j                         |j                  | j                         |j                  | j                        }|j                  | j                        }|j                  | j                  |j                  d|| j                  j                        |j                  d|| j                  j                              }|j                  |d      5  |j                  | j                          d d d        ||fS # 1 sw Y   ||fS xY w)Nz<=r  FrS  )r<   r  r+  r  r   r   r   r  rw  r  r=   selectr  r  stopr
  rx  )rX   r<   r  r  is_finisheds        rB   rj  zSliceIndexer.loop_head  s%   ,,4::++TZZ8499djj1t}}%.LL,	LL,	nnT%:%:%,%8%8y9=&J%,%8%8y9=&JK
 __[_7NN4;;' 8)## 8)##s   FFc                    | j                   }|j                  |j                  | j                        | j                  j
                  dg      }|j                  || j                         t        j                  ||j                  | j                              }|j                  || j                         |j                  | j                         |j                  | j                         y )Nr   r   )r<   r  r=   r   r+  r  r  r
   r  r   r  rw  r  rx  )rX   r<   r  r  s       rB   rl  zSliceIndexer.loop_tail  s    ,,[[djj!94::??(-w ! 0
j$**-,,Wgll4::6NO
j$**-t}}%,rD   Nr  rn  rD   rB   r  r  t  s+    	.3B"$$-rD   r  c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	FancyIndexerz4
    Perform fancy indexing on the given array.
    c           
      :   || _         || _        || _        t        j                  ||j
                  |j                        | _        t        j                  ||j                  |j                        | _        | j                   j                  t        j                        | _        g | _        g }t        |D cg c]  }t        |      s| c}      }	d}
d}t!        ||      D ]  \  }}|t        j"                  u rY|j                  t        |      z
  dz   |	z   }t%        |      D ],  }t'        |||||
      }|j)                  |       |
dz  }
|dz  }. rt+        |t        j,                        r7|j/                  |||      }t1        |||||
||      }|j)                  |       nDt+        |t        j2                        r;t5        ||||| j                  |
         }t7        |||      }|j)                  |       nt+        |t        j8                        r t;        |      |||      }t+        |j<                  t        j2                        rt?        ||||| j                  |
         }n5t+        |j<                  t        j@                        rtC        ||||      }nJ |j)                  |       n:t        |      r!| j                  j)                  |       |
dz  }
ntE        d|      |
dz  }
|dz  } |
|j                  k  sJ |
|j                  f       |
|j                  k  r5t'        |||||
      }|j)                  |       |
dz  }
|
|j                  k  r5t        |      |j                  k(  sJ t        |      |j                  f       || _#        y c c}w )Nr   rF   r  )$r|   r<   r   r
   r   rd   ro   r   r   r   r   r   rs  newaxesr   r   r   r  r7   rp  rh   r   r  r   r  r   r   r  r   rw   rz   r  Booleanr  AssertionErrorindexers)rX   r|   r<   r   r   r   r   r  r   r'  r(  new_axr)  r   r*  rl   indexerr+  r   r   s                       rB   rt  zFancyIndexer.__init__  s   
**7CIIuzzJ++GS[[%**M||225::>+J+3S9I3+JK"7K8OHe&!JJW59KG	y)A+GWeS"MGOOG,!GBaKF	 *
  %1++GUHE&wR',e5(E5==1'%(,B9('3?(E5;;/*E*7GXFekk5==91'72726++b/CG  U]];1'727AG 1(U###F+a$E%KLL!GBaKFQ  9V UZZ1"ejj!115::o#GWeS"EGOOG$!GB 5::o
 8}

*GS]EJJ,GG* m Ks   6NNc                 \   | j                   D ]  }|j                           | j                  j                  t        j
                  d      }| j                   D cg c]  }|j                          }}| j                  D ]  }|j                  ||f        t        |d      | _
        y c c}w )NrF   rn  )r  r`  r|   r   r   r   rf  r  insertsumindexers_shape)rX   rl   r#  	res_shapes       rB   r`  zFancyIndexer.prepare   s    AIIK  ll''

A6 -1MM:MqQ[[]M	: AQ'  ")R0 ;s   B)c                     | j                   S )z?
        Get the resulting data shape as Python tuple.
        )r  r_  s    rB   rf  zFancyIndexer.get_shape  s     """rD   c           	          t        |      | j                  j                  k(  sJ | j                  }t        j
                  }| j                  d      }| j                  d      }|}|}t        | j                  | j                  |      D ]  \  }	}
}|j                  ||j                  d|
|            }|	j                         \  }}|j                  ||      }|j                  ||j                  ||            }|j                  d||      }|j!                  ||j#                  |||            }|j!                  ||j#                  |||            } |j!                  ||      }|j#                  |||      }|j#                  |||      }||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   rF   ==r  )r   r   ro   r<   r
   	false_bitrs  r   r  r  or_icmp_unsignedrh  r   subr  r  r  )rX   r   r   r<   is_emptyr   r#  r  r  r  rd   stridelower_indexupper_indexlower_offsetupper_offsetis_downwardss                    rB   get_offset_boundszFancyIndexer.get_offset_bounds  s~    7|tzz...,,$$||All1o&)$--9L9L*1'3"GUF{{8#*#8#8ud#KMH (/'?'?'A$K";;v{;L";;vw{{;/LML"..sFDALKK '|/;/;!=>E KK '|/;/;!=>E'3& E8,xu5xu5e|rD   c                 B    t        d | j                  D         \  }}||fS )Nc              3   <   K   | ]  }|j                           y wr:  )rj  )r<  rl   s     rB   r>  z+FancyIndexer.begin_loops.<locals>.<genexpr>@  s     E}!}s   )r   r  )rX   r   countss      rB   begin_loopszFancyIndexer.begin_loops?  s$    Et}}EFrD   c                 X    t        | j                        D ]  }|j                           y r:  )reversedr  rl  )rX   rl   s     rB   	end_loopszFancyIndexer.end_loopsC  s    $--(AKKM )rD   N)
rp   rq   rr   rm  rt  r`  rf  r  r  r  rn  rD   rB   r  r    s(    @!D1&#$LrD   r  c                 b   t        j                  ||j                        }t        j                  ||j                        }	|j                  }
t        | |||||      }|j                          |j                  }|j                         }t        | |||      }|j                  }t        j                  || j                  t        j                  d            }|j                         \  }}t        j                  | ||
||	|j                   |d| j"                  	      }t%        | |||      }|j'                  |      }|j)                  ||g      }t+        | ||||       t        j,                  ||      }|j/                  ||       |j1                          t3        | |||j5                               S )Nr   Fr  )r
   r   rd   r   r   r  r`  r   rf  _empty_nd_implr   r   r   r   r  get_item_pointer2layoutr3  r   r=   gepr   r  r  r  r!   r   )r|   r<   rZ   r   r   r   r   r   r   r   r   r  out_ty
out_shapesr   out_dataout_idx_rj   r   curnext_idxs                         rB   rA  rA  H  s    !!'3995F""7CKK8G88D7GUC&1GOO __F""$J
'6:
>CxxH''(/(<(<UZZ(KMG $$&JGQ 
#
#GWdFG$)LL'e070J0JLC GWeS
1C ,,w
C
++h
&Cwc2&&w4HMM(G$GWfcmmoFFrD   c           
      "   |j                   \  }}|\  }} t        |      | ||      }|j                  dk(  rFt        | |||      \  }}t	        | ||j
                  |||f|f      }t        | ||j
                  |      S t        | ||||||f|f      S )z3
    Advanced or basic indexing with an array.
    r   )r   rw   ro   r   r4  r   r    rA  r6  s	            rB   fancy_getitem_arrayr  s  s    
 88LE5HC
*U
GWc
2CzzQ$WgucB
s$Wgs%*C%C6C '3??CHH WgsD"C%C6; 	;rD   c           	         |j                   }|j                  d      }|j                  d      }|j                  dv r"|}	|j                  ||j                        }
|	|
fS |}	|}
t        |j                        D ]  }|j                  ||   |j                  ||   |            }|j                  d||      }|j                  ||j                  |
|      |
      }
|j                  ||	|j                  |	|            }	 |j                  |
|      }
|j                  d|j                  |      }|j                  |||
      }
|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   rF   CFr  r  )r   r8   r  r   r   r7   ro   r  r  r  r  )r|   r<   arrtyarrr   r   r   r   r#  r  r  rl   max_axis_offset
is_upwardsr  s                  rB   offset_bounds_from_stridesr    sQ    ||H==D
))A,C||t Hcjj10 %<+ uzz"A &kk'!**1++fQi*EGO ,,T?DIJNN:#*;;uo#FOENN:#('++e_*MOE # E8,&&tSZZ>xu5xu5%<rD   c                     |j                  ||j                        }|j                  ||      }|j                  ||      }||fS )z
    Given [lower, upper) byte offsets and a base data pointer,
    compute the memory pointer bounds as pointer-sized integers.
    )ptrtointr8   r  )r|   r<   r  r  r   data_ptr_as_intr  ends           rB   compute_memory_extentsr    sD    
 &&tUZZ8OKK/E
++ou
-C#:rD   c                 F    t        | |||||      \  }}t        | ||||      S )zr
    Compute a half-open range [start, end) of pointer-sized integers
    which fully contain the array data.
    )r  r  )	r|   r<   r  r   r   r   r   r  r  s	            rB   get_array_memory_extentsr
    s2     .gws.4g?LE5!'7E5$GGrD   c                 n    |j                  |j                  d||      |j                  d||            }|S )z[
    Whether two memory extents [a_start, a_end) and [b_start, b_end)
    may overlap.
    r  )and_r  )r|   r<   a_starta_endb_startb_endmay_overlaps          rB   extents_may_overlapr    s>     ,,c7E2c7E2K rD   c                 2    j                   dt        j                        d j                  d      5  j	                  |j
                  |j                        } j                  j                  |      }	|	j                   j                  |	      }	j                  |	        j                  t        j                        }
t        j                  |
      5 }t        j                   j                   |      }t        j                   |	|      }j                  j#                  |      |       d d d        d d d         fd} fd}||fS # 1 sw Y   .xY w# 1 sw Y   2xY w)Nr   FrS  c                    t        j                  
      }j                  d      5 \  }}|5  j                  t        j                  j                        	| d      |       d d d        |5  j                  t        j                  j                  | d      |       d d d        d d d        t        j                  |            S # 1 sw Y   pxY w# 1 sw Y   :xY w# 1 sw Y   >xY w)NFrS  r  )r
   rV   if_elser  r  r=   r  r   )source_indicessrc_ptrif_copy	otherwiser<   r|   	copy_datacopy_layoutcopy_shapescopy_stridesptrtysrc_data
src_shapessrc_stridessrctyuse_copys       rB   src_getitemz&maybe_copy_source.<locals>.src_getitem  s    %%gu5__Xe_48L)--gw.5ll9.E.9<.9>9>	@
   --gw.8+.3llN9>@   5  '5',,w2GHH   54s:   C5=C.
C588C)0C5C&	"C5)C2	.C55C>c                      j                  d      5  j                        } j                  |       } j                  j	                  |        d d d        y # 1 sw Y   y xY w)NFrS  )r
  r=   bitcastr   free)r   r<   r|   r  r$  	voidptrtys    rB   src_cleanupz&maybe_copy_source.<locals>.src_cleanup  sQ    __Xe_4<<	*D??43DKKWd+ 544s   A AA')r8   r
   r   r
  r   r   r   r   allocater'  r  r   r   r   	loop_nestr  r  r=   )r|   r<   r$  r#  srcr!  r"  r   	allocsizer   r   r   r  dest_ptrr%  r*  r  r  r  r  r  r)  s   ```` ```        @@@@@@rB   maybe_copy_sourcer0    s`   MMEK))'8<IKL	%	0 KKcjj9	{{##GY7II	tU+dI& ''

3w
F;w//(0:K05gGG 00'41<l1<gGH MM',,w/: < 
1,I I(, , ##I <; 
1	0s&   	B)F2A"FFF
	FFc                    | j                  t        j                  d      }| j                  t        j                  d      }t        |      t        |      kD  r-t        |      t        |      z
  }|g|z  |z   }|g|z  |z   }||fS t        |      t        |      k  rt        |      t        |      z
  }|d| D cg c]  }|j	                  d||       }	}t        j                  |j                  |	t        j                        }
|j                  |j                  |
      d      5  d}| j                  j                  |t        |f       ddd       ||d }||d }||fS c c}w # 1 sw Y   xY w)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   rF   Nr  FrS  z,cannot broadcast source array for assignment)r   r   r   r   r  	functoolsreducer  r
   true_bitr
  r  rU  rV  r   )r|   r<   r   r   target_shaper   r#  nd_diffr,  
dim_is_oneacceptedr   s               rB   _bc_adjust_dimensionr9    ss    Q/D


u{{A
.C <3v;&l#c&k16)&7"W," 7? 
\	S[	(f+L 11 &x 02 0" ++D"c: 0 	 2##GLL*$+$4$46 __W\\(3E_B@C--gzC6J C !'(#7?2
 CBs   :E"'%E''E0c           
         g }g }| j                  t        j                  d      }| j                  t        j                  d      }t        ||      D 	
cg c]  \  }	}
|j	                  d|	|
       }}	}
|D 
cg c]  }
|j	                  d|
|       }}
t        ||      D cg c]  \  }}|j                  ||       }}}t        |||      D 	
cg c]  \  }}	}
|j                  ||	|
       }}	}}
t        ||      D 
cg c]  \  }}
|j                  |||
       }}}
||fS c c}
}	w c c}
w c c}}w c c}
}	}w c c}
}w )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   rF   rR  r  )r   r   r   r   r  r  r  )r|   r<   r   r   r5  	bc_shapes
bc_stridesr   r#  taroldmismatch
src_is_onexypredsps                    rB   _bc_adjust_shape_stridesrE  6  s^    IJQ/D


u{{A
.C !$L& 9; 9HC ##D#s3 9  ;AGH#'%%dC5JH,/*,EF,EDAqW\\!Q,EEF$'|V$DF$D[QS 3,$D  F !$E7 35 3fa ..D#. 3  5j  ;HFF5s   D(8D.#D3D9E c           	         t        j                  ||j                        }t        j                  ||j                        }t	        | ||||      \  }}t        | ||||      \  }}|j                  t        |      d      } t        |      | |      }t        ||j                  t        j                  ||      t        j                  ||      |j                  |j                  |j                         ||fS )zX
    Broadcast the given array to the target_shape.
    Returns (array_type, array)
    Aro   r  r0  )r
   r   rd   r   r9  rE  copyr   rw   r   r   ri   r   r   r   )	r|   r<   arrtyper   r5  r   r   new_arrtypenew_arrs	            rB   _broadcast_to_shaperM  M  s     !!'3995F""7CKK8G*7GVW+79OFG.w/6FOFG,,C$5c,BK%j%gw7G7 ++GV<"--gw?LL;;**& rD   c                 ^    |j                  |j                  dd      } |||      }d }||fS )NrG  T)ro   r  readonlyc                 n   |\  }}|j                   d   } t        |      | ||      }t        j                  ||      }t	        | ||||      \  }}t        |dt        | j                  |j                  j                  d            d              |j                         }	t        | ||j                  |	      S )Nr   r   )r   rw   r
   r   rM  r   r   r   r   r   r   r    r   )
r|   r<   rZ   r   r-  shape_r#  r  destr   s
             rB   codegenz$_numpy_broadcast_to.<locals>.codegenl  s    Vj#6%%gv6%gwsFL4 	h&&t'?'?'IJ! 	 nn '3??CHHrD   )rI  r   )	typingctxr   rd   retrZ   rS  s         rB   _numpy_broadcast_torV  g  s8    
**%++cD*
AC
eU
CI <rD   c                 D    |j                  d      } ||      }d }||fS )NTrO  c                     |\  }|j                   d   } t        |      | ||      }t        j                  |j                  j
                        |_        |j                         }t        | ||j                  |      S r   )	r   rw   r
   get_null_valuer   r8   r   r    r   )r|   r<   rZ   r   r-  r#  rR  r   s           rB   rS  z#get_readonly_array.<locals>.codegen  sh     z% '37,,T[[-=-=>nn '3??CHHrD   )rI  )rT  r   rU  rZ   rS  s        rB   get_readonly_arrayr[  ~  s/     ((D(
!C
c(CI <rD   c                    | j                   }t        |      }t        |      }||kD  rt        d      |D ]  }|dk  s	t        d       d}||z
  }||k  r1||   }||   }	||	k(  s|dk(  r|dz  }|dz  }nt        d      ||k  r0y y )NzDinput operand has more dimensions than allowed by the axis remappingr   z4all elements of broadcast shape must be non-negativerF   z=operands could not be broadcast together with remapped shapes)rd   r   r   )
r   
dest_shape	src_shapesrc_ndim	dest_ndimr   	src_index
dest_indexsrc_dimdest_dims
             rB   _can_broadcastre    s    I9~HJI) 1 2 	2!8 , - -  IX%J
h
I&j) h'Q,NI!OJ 4 5 5 h
rD   c                 \    t        j                  |       } t        | |       t        | |      S r:  )npasarrayre  rV  r   rd   s     rB   _default_broadcast_to_implrj    s'    JJuE5% ue,,rD   c           	      d   t        |       st        j                  d      t        |t        j
                        rd }|S t        |t        j                        rAt        |j                  t        j
                        sd}t        j                  |      t        S t        |t        j                        ra|j                  dkD  rRt        |D cg c]  }t        |t        j                         c}      sd| d}t        j                  |      t        S t        |t        j                        rc|j                  dk(  rTt        | t        j                        xr | j                  dk(  }t        |       s|rd }|S d}t        j                  |      d	|z  }t        j                  |      c c}w )
Nz-The first argument "array" must be array-likec                 0    t        j                  | |f      S r:  )rg  broadcast_tori  s     rB   r   z numpy_broadcast_to.<locals>.impl  s    ??55(33rD   z7The second argument "shape" must be a tuple of integersr   "z," object cannot be interpreted as an integerc                 B    t        j                  |       } t        |       S r:  )rg  rh  r[  ri  s     rB   r   z numpy_broadcast_to.<locals>.impl  s     

5))%00rD   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   UniTuplerz   rj  Tupler   allIntegerLiteralr   ro   r   )r   rd   r   r   typis_scalar_arrays         rB   numpy_broadcast_torv    se   E"   "1 2 	2 %'	4	E5>>	*%++u}}5KC$$S))))	E5;;	'EKK!OUKUcJsE$8$89UKLeWHIC$$S))))	E5;;	'EKK1,<$UEKK8LUZZ1_% O1
 K DC$$S))   %%+ Ls   !F-c                     t        t        |            D ]O  }|t        |      z
  |z   }||   }|dk  rt        d      |dk(  r/| |   dk(  r|| |<   =| |   |k7  sFt        d       y )Nr   #negative dimensions are not allowedrF   z=shape mismatch: objects cannot be broadcast to a single shape)r7   r   r   )rmrd   rl   r   tmps         rB   numpy_broadcast_shapes_listr|    s~    3u:E
NQAh7BCC!8Q419AaDqTS[ 2 3 3 rD   c                  |  	 t        |       D ]  \  }}t        |t        j                        }t        |t        j                        xr$ t        |j
                  t        j                        }t        |t        j                        xr t        |j                        dk(  }|r|r|rd| d| }t        j                  |       d| D ]Y  }t        |t        j                        rt        d      *t        |t        j                        sEt        t        |            [ dk(  rd S dz  		fd}|S )Nr   z	Argument z* must be either an int or tuple[int]. Got rF   c                       yr  rn  r   s    rB   <lambda>z+ol_numpy_broadcast_shapes.<locals>.<lambda>  s    RrD   rF   c                     dgz  }}t        |       D ]M  }t        |t              rt        |      dkD  rt	        ||       /t        |t
              s@t	        ||f       O t        |      D ]  \  }}t        |||      } |S r  )r   r   r   r   r|  r   	enumerater.   )r   ry  rC  argr   elemrz  tup_inits         rB   r   z'ol_numpy_broadcast_shapes.<locals>.impl  s    aAC%d+c5)c#hl/1c:S)/1sf=	 ,
 'q\	T#Cd3 *JrD   )r  r   r   r   rp  rz   rq  r   r	   r   maxrF  )
r   r   r  is_intis_int_tupleis_empty_tupler   r   rz  r  s
           @@rB   ol_numpy_broadcast_shapesr    s    dOSC/!#u~~6 1syy%--0 	#C5M#cii.A:M,.se $ C$$S)) $ 	
Ac5==)Aq	AU__-As3x A	  	Av!8	 rD   c                     t        |       D ])  \  }}t        |      rt        j                  d| d       d }d }| D ]]  }t	        |t
        j                  t
        j                  f      r|j                  }n|}||}A||k7  sGt        j                  d|         dt        |       D ]  \  }}t	        |t
        j                        rt        |j                        7t	        |t
        j                  t
        j                  t
        j                  f      rt        d      }t        j                  d|        dz  fd}|S )	Nz
Argument "z" must be array-likezTMismatch of argument types. Numba cannot broadcast arrays with different types. Got r   rF   zUnhandled type r   c                  `   dgz  }t        |       D ],  }t        |t        j                  |      j                         . }t              D ]  }t        ||||         } g }t        |       D ]:  }|j                  t        j                  t        j                  |      |             < |S r  )	r   r|  rg  rh  rd   r7   r.   rh   rm  )r   rd   r   rC  rl   outsrz  r  s         rB   r   z$numpy_broadcast_arrays.<locals>.impl>  s    
 a#D)E'q"**U2C2I2IJ * qAQa1C  #D)EKK

5(93?@ *rD   )r  r   r	   r   r   r   r   rF  rz   ArrayCompatibler  ro   Numberr  )r   r   r  unified_dtypedtr   rz  r  s         @@rB   numpy_broadcast_arraysr    sB    dOS$$$z# 75 &5 6 6 $
 M	BcEKK9:BB Mb $$ &,,06&3 4 4  	
AdOSc5001Asxx AellEMM5??KLAq	A$$se%<== $ axH( KrD   c                    ()* |j                   \  }}*|\  }}( t        |       |      }t        j                  |j                        }	t        j                  |j
                        }
|j                  }t         ||||      }|j                          t        *t        j                        r*j                  )|j                         } t        *       (      (t         *(|      \  *(t        j                  (j                        }t        j                  (j
                        }(j                  }t        j                  }t!        |      t!        |      k(  sJ t#        ||      D ](  \  }}j%                  |j'                  d||            }* j)                  |d      5  d} j*                  j-                  t.        |f       ddd       t1         *(|||      \  }}|j3                  |
|j4                        \  }}t7         |||      \  }}t9         ||||      }t;         |*(|||      \  }}nt        *t        j<                        rǉ*j                  )|j                         }t!        |      dk(  sJ  j?                  t         tA        t        jB                  *            } |(f      }j'                  d|d   |      }j)                  |d      5  d} j*                  j-                  t.        |f       ddd        ()*fd}d	 }n
*)(fd
}d } jE                  t        jF                  d      } |jI                         \  }!}"tK        |"      }"|jL                  D ]  }#|"jO                  |#|         |"D $cg c]  }$|$|$	 }%}$ ||%      }& jQ                  |&)|j                        }&t        jR                   ||	|
|jT                  |!d jV                  	      }'tY         ||&|'       |j[                           |         j]                         S # 1 sw Y   axY w# 1 sw Y   /xY wc c}$w )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.
    rR  FrS  z0cannot assign slice from input of different sizeNrF   r   c                     | \  }j                  t        j                  t        t        j
                              } ||f      S r:  )rP   operatorgetitemr$   r   r   )r  r   getitem_implr<   r|   r-  	src_dtyper#  s      rB   r%  z#fancy_setslice.<locals>.src_getitem  sF    !DC"//  )UEJJ7L  #s44rD   c                       y r:  rn  rn  rD   rB   r*  z#fancy_setslice.<locals>.src_cleanup      rD   c                     S r:  rn  )r  r-  s    rB   r%  z#fancy_setslice.<locals>.src_getitem  s    JrD   c                       y r:  rn  rn  rD   rB   r*  z#fancy_setslice.<locals>.src_cleanup  r  rD   r  )/r   rw   r
   r   rd   r   r   r  r`  r   r   r   rz   rf  rM  r  r   r   r  r  r
  rU  rV  r   r
  r  r   r  r  r0  SequencerP   r$   r   r   r   r  r   r  r  r   r  r  r3  r   r  rZ  )+r|   r<   rZ   r   r   r   r   r  r   dest_shapesdest_strides	dest_datar  index_shaper!  r"  r   shape_errorur   r   	src_startsrc_end
dest_lower
dest_upper
dest_startdest_endr$  r%  r*  len_implseq_lenr   dest_indicesr  rl   r  r  r   r/  r-  r  r#  s+   ``                                      @@@rB   rH  rH  U  s#    hhOE1eKCC
*U
GWc
2C&&w		:K''=LI7GUC&1GOO%&KK	'')j#6('5#)46
s))'399=
**7CKK@88 '';3z?222
K0DAq!++k&-&9&9$1&EGK 1 __[_7DC--gzC6J 8
 6gw69:6A8M	7 ")!:!:<;><<"I
J5gw6@*6? A
H 'wG'18= $5Wgx5:C5@($L [ 
E5>>	*KK	 '');1$$$''Yuzz5-IJ7SF+))$AH__[_7DC--gzC6J 8	5 	5	 			 Q/D"..0L& &\F
 __a  "(9A1=aN9
n
%C ,,wY
<C (('9)4l).|495<5O5O	QH
 wX6M""$$A 87B 87V :s$   6%P:5%QQ&Q:QQc           
         |j                   d   }|j                   dd  }|d   }|dd  }t        ||      D 	cg c]'  \  }}	| j                  ||	|t        j                        ) }}}	t        j                  |||d   j                        }
t        j                  t        j                  t        |            }t        j                  |j                  ||      }||
f}||fS c c}	}w )Nr   rF   rz   r   )r   r   r   r   r   r
   ri   r8   rp  r   r   r$   r   )r|   r<   rZ   r   r   dimtysr   rk   r=  r   rd   shapetynew_signew_argss                 rB   vararg_to_tupler    s    HHQKEXXab\F
q'C8D vt,.,C LL#r5::6, 	 . wd1gll;Enn5::SY?Gsw?GEzHH.s   ,C"zarray.transposec                 >    t        | ||j                  d   |d         S r   )array_Tr   r|   r<   rZ   r   s       rB   array_transposer    s    7GSXXa[$q'::rD   c                     t        |       t        t        |             k7  rt        d      t        |      }| D ]   }||k\  st        |      |kD  st        d       ||    |d d  ||    |d d  y )Nzrepeated axis in transposez2axis is out of bounds for array of given dimension)r   r   r   abs)r   rd   r   rr  rA  s        rB   permute_arraysr    st    
4yCD	N"566
e*C8s1v| / 0 0 
 T{E!HGAJrD   c           
      v   |j                   d   } t        |      | ||d         }|j                   d   |d   }}|j                  |j                  }	}| j	                  t
        j                        }
t        j                  |
|      }||j                  |j                  g}|D cg c]  }t        j                  ||       }}t        ||      D ]  \  }}|j                  ||        t        j                  |	dd      }| j!                  t
        j                  | j#                  |
            }|D cg c]  } t        |      | |       }}t        ||      D ]T  \  }}t%        ||j'                  ||
j)                               | j!                  t
        j                  |      g|g|d        V | j+                  |t,        t/        j0                  t
        j2                  |||      |D cg c]  }|j5                          c}        t        |j6                        | |      }t%        ||j8                  |j;                  |d         |j;                  |d         |j<                  |j>                  |j@                         |j5                         }tC        | ||j6                  |      S c c}w c c}w c c}w )Nr   rF   r   rz   ro   r  r   rd   r   r   r   rX  r0  )"r   rw   r   rz   r   r   r   r   	ArrayTyperd   r   r
   rV   r   r  r   r   r{   r   r'  
as_pointercompile_internalr  r   r$   voidr   r   r   r=   r   r   r   r    )r|   r<   rZ   r   r   r   axistyr   num_axisrz   rs  ll_ary_sizearysr  ll_arysr-  dst	np_ary_tynp_itemsizenp_arysnp_aryll_aryarU  r   s                            rB   array_transpose_tupler    sc   HHQKE
*U
GWd1g
6C88A;QDFllFLLeH$$UZZ0G,,w1K #))S[[)DBFG$Qw""7K8$GG g&Sc3 ' %a<I&&uzz'.'='=g'FHK AEE1$z)$Wg6GE gw/v#OOFG4F4F4HI%225::xHI +} +#	% 0 Wn#--ejj.7IO5<=WakkmW=? &*S__
%gw
7C3 gaj1"<<
3LL;;**& --/CWgsDDO H F  >s   $J,4J1,J6c                 @    t        | |||      \  }}t        | |||      S r:  )r  r  r|   r<   rZ   r   r  r  s         rB   array_transpose_varargr  ?  s(    '#tDGX '7HEErD   c                 |    t        | t        j                        rt        j                  d      |dd}|S dd}|S )Nz#np.transpose does not accept tuplesc                 "    | j                         S r:  	transposer  axess     rB   np_transpose_implz*numpy_transpose.<locals>.np_transpose_implK  s    ;;= rD   c                 $    | j                  |      S r:  r  r  s     rB   r  z*numpy_transpose.<locals>.np_transpose_implN  s    ;;t$$rD   r:  )r   r   rF  r	   UnsupportedError)r  r  r  s      rB   numpy_transposer  E  sA    !U__%%%&KLL|	! 	% rD   Tc                 4   |j                   dk  r|}n t        |      | ||      } t        |      | |      }t        j                  ||j                  |j                         }t        j                  ||j
                  |j                         }t        ||j                  t        j                  ||d d d         t        j                  ||d d d         |j                  |j                  |j                         |j                         }t        | |||      S )NrF   r0  )ro   rw   r
   r   rd   r   r   r   ri   r   r   r   r   r    )	r|   r<   rt  r  r   r   rU  r   r   s	            rB   r  r  T  s    
xx1}jogw6jogw/%%gsyy#((C&&wSXXFsHH$//"F&11'74R4=I #"{{!jj	* mmoWgsC88rD   c                 4   t        | t        j                        st        j                  d      t        |t        j                        st        j                  d      t        |t
        t        j                  f      st        j                  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 integerc                 \    t        j                  | ||      }t        j                  d|      S )Ng      $@)rg  linspacepower)r  r  numrB  s       rB   r   znumpy_logspace.<locals>.implq  s%    KKtS)xxa  rD   2   )r   r   r  r	   r   r   r   )r  r  r  r   s       rB   numpy_logspacer  h  ss    eU\\*  !NOOdELL)  !NOOcC/0  !NOO! KrD   c                    t        | t        j                        sd}t        j                  |      t        |t        j                        sd}t        j                  |      t        |t
        t        j                  f      sd}t        j                  |      t        d | |fD              r:t        t        j                  t        |       t        |      d             dfd	}|S dd}|S )Nz%The argument "start" must be a numberz$The argument "stop" must be a number%The argument "num" must be an integerc              3   P   K   | ]  }t        |t        j                           y wr:  r   r   Complexr<  r  s     rB   r>  z"numpy_geomspace.<locals>.<genexpr>       
C]c:c5==)]r?  c                    | dk(  s|dk(  rt        d       	|       }  	|      }| j                  dk(  |j                  dk(  z  }t        j                  |       dk(  t        j                  |      dk(  z  }d}|r| j                  } |j                  }d}|r	|  } | }| }t        j
                  |       }t        j
                  |      }t        j                  |||      }|dkD  r| |d<   |dkD  r||d<   ||z  S )Nr   &Geometric sequence cannot include zeror  rF   y              ?)r   realrg  signimaglog10logspace)
r  r  r  both_imaginaryboth_negativeout_signlogstartlogstopr  result_dtypes
            rB   r   znumpy_geomspace.<locals>.impl  s    zTQY !IJJ 'E%D#jjAo$))q.ANWWU^r1bggdmr6IJMH

yyu$9xxHhhtnG[[7C8F Qw!q	7!%F2Jf$$rD   c                 \   | dk(  s|dk(  rt        d      t        j                  |       dk(  t        j                  |      dk(  z  }d}|r	|  } | }| }t        j                  |       }t        j                  |      }t        j                  |||      }|dkD  r| |d<   |dkD  r||d<   ||z  S )Nr   r  r  rF   )r   rg  r  r  r  )r  r  r  r  r  r  r  r  s           rB   r   znumpy_geomspace.<locals>.impl  s    zTQY !IJJWWU^r1bggdmr6IJMHu$9xxHhhtnG[[7C8F Qw!q	7!%F2Jf$$rD   r  )r   r   r  r	   r   r   r   r@  r   rg  result_typer   )r  r  r  r   r   r  s        @rB   numpy_geomspacer  x  s    eU\\*5  %%dELL)4  %%cC/05  %%

CeT]
CC!"..%19$#G H	%d K+	%* KrD   c                    t        |t        t        j                  f      st	        j
                  d      t        | t        j                        st	        j
                  d      | j                  dk  rt	        j                  d      dd}|S )Nz*The second argument "k" must be an integerz'The first argument "m" must be an arrayrX  Input must be >= 2-d.c                 B   |dz  }|dk(  r| d d  S |dk(  r*t        j                  t        j                  |       dd      S |dk(  r(t        j                  t        j                  |             S |dk(  r*t        j                  t        j                  | dd            S t        )N   r   rF   rX     )rg  swapaxesfliplrflipudr  )rz  r   s     rB   r   znumpy_rot90.<locals>.impl  s    E6Q4K!V;;ryy|Q22!V99RYYq\**!V99R[[Aq122  rD   r  )	r   r   r   r   r	   r   r   ro   NumbaValueError)rz  r   r   s      rB   numpy_rot90r	    sr     a#u}}-.  !MNNa%  !JKKvvz$$%<==! KrD   c                    | j                  t        j                        }|j                         }| j                  t        j                        }	t        j                  |	||||||||	g      }
t        j                  |j                  |
d      } ||j                        }t        j                  ||j                  d      dd      }t        j                  ||j                  d      dd      } ||      }t        j                  ||dd      }t        j                  ||dd      } |	d      }|j                  ||||||||j                  |g      }|S )a  
    Call into Numba_attempt_nocopy_reshape() for the given array type
    and instance, and the specified new shape.

    Return value is non-zero if successful, and the array pointed to
    by *newstrides* will be filled up with the computed results.
    numba_attempt_nocopy_reshaperd   r   r   )r   r   r   r  intcr   FunctionTyper
   get_or_insert_functionr9   ro   rg   rf   callr   )r|   r<   r   r   newndnewshape
newstridesrs  ll_intp_starll_intcfntyfnndrd   r   
is_f_orderr   s                    rB   _attempt_nocopy_reshaper    sE    $$UZZ0G%%'L$$UZZ0G??7||% D 
	'	'(F
HB 
	B  #*>*>w*GANE""7C,@,@,K#$a)GENE##GXq!<H%%gz1a@JJ
,,rBw!8ZLL*6 7C JrD   c                     d}d}t        |      D ]  \  }}|dk  r|dz  }|}||z  } |dk(  r| |k7  rt        d      y |dk(  r-|dk(  rd}| dk(  }n| |z  }| |z  dk(  }|st        d      ||<   y t        d      )Nr   rF   z)total size of new array must be unchangedzmultiple negative shape values)r  r   )	origsizerd   num_neg_value
known_sizer(  r   neg_axinferredoks	            rB   normalize_reshape_valuer!    s    MJ5!Aq5QMF!OJ " z!HII " 
!	?HQB:-HJ&!+BHII f 9::rD   zarray.reshapec           	         |j                   d   }|j                  }|j                   d   }|d   }| j                  t        j                        }t        j                  ||j                        }	 t        |      | ||d         }
t        j                  ||	      }|j                  ||       t        j                  |j                  dd      } t        |      | |      }| j                  t        j                  | j                  |            }t!        ||j#                  ||j%                               | j                  t        j                  |j                        g|g|d        |
j&                  }| j)                  |t*        t-        j.                  t        j0                  t        j2                  |      ||j5                         g       |j                  }t        j                  ||	      }t7        | |||
|||      }|j9                  d||j;                  d            }|j=                  |      5  d}| j>                  jA                  |tB        |f       d d d         t        |      | |      }t!        ||
jD                  |jG                  |      |jG                  |      |
jH                  |
jJ                  |
jL                         |j5                         }tO        | ||j                  |      S # 1 sw Y   xY w)	Nr   rF   r   r  r  r  zincompatible shape for arrayr0  )(r   r   r   r   r   r   r  r   rw   r
   rV   r  r   rz   r   r{   r   r'  r  r   r  r!  r   r$   r  r   r   r  r  r8   r
  rU  rV  rQ   r   r=   r   r   r   r    )r|   r<   rZ   r   r   rettyr  rd   rs  ll_shaper   r  shape_ary_ty	shape_aryshape_itemsizer   r  r  r   failr   rU  r   s                          rB   array_reshaper)    sy   HHQKEOOEhhqkGGE$$UZZ0G||GW]]3H
*U
GWd1g
6C ""7H5HMM%" ;;W]]3GL(
<(':I))%***1*@*@*IKN9'2D2D2FG!..uzz7==IJ*+*! ::D W&=#--ejj.3kk<I"I$7$7$9:< MME$$Wh7J	 '5#u!):
7B  r2771:6D		,))'3FO 
 *U
GW
-C3 h/"<<
3LL;;**& --/CWgsDD 
	s   4%K33K<c                 @    t        | |||      \  }}t        | |||      S r:  )r  r)  r  s         rB   array_reshape_varargr+  ]  s(    '#tDGX'7H==rD   c                     d }|S )Nc                 $    | j                  |      S r:  )reshape)r  r  s     rB   np_reshape_implz#np_reshape.<locals>.np_reshape_imple  s    yy""rD   rn  )r  r  r/  s      rB   
np_reshaper0  c  s    #rD   c                 .   t        |       sd}t        j                  |      t        |t        j
                        r$t        |j                  t        j                        s1t        |t        j                        sd}t        j                  |      d }|S )N#The argument "a" must be array-likezBThe argument "new_shape" must be an integer or a tuple of integersc                 0   t        j                  |       } t        j                  |       } t        |t              r4d}t        j                  |      D ]  }||z  }|dk  sd}t        |       n|dk  rd}t        |      |}| j                  dk(  r.t        j                  |      j                  | j                        S | | j                  z   }| }t        |dz
        D ]  }t        j                  || f      } |d | }t        j                  ||      S )NrF   r   z0All elements of `new_shape` must be non-negative)rg  rh  ravelr   r   r   r   zerosastyperz   r7   concatenater.  )	r  	new_shapenew_size
dim_lengthr   msg2repeatsr   rl   s	            rB   r   znumpy_resize.<locals>.implz  s    JJqMHHQKi'H jj3
J&>LC$S/)	 4 1}I && H66Q;88I&--agg66I'(w{#A..#q*C $)8nzz#y))rD   )r   r	   r   r   r   rp  rz   r   )r  r8  r   r   s       rB   numpy_resizer=  j  st     A3  %%	5>>2	7y%--0%  %%*8 KrD   c                    t        |       st        j                  d      t        |      st        j                  d      t        |      rdd}|S t	        |t
        j                        st        j                  d      dd}|S )Nz+The first argument "arr" must be array-likez/The second argument "values" must be array-likec                     t        j                  t        j                  |             } t        j                  t        j                  |            }t        j                  | |f      S r:  )rg  r4  rh  r7  r   valuesr   s      rB   r   znp_append.<locals>.impl  sB    ((2::c?+CXXbjj01F>>3-00rD   z,The third argument "axis" must be an integerc                 4    t        j                  | |f|      S Nr   rg  r7  r@  s      rB   r   znp_append.<locals>.impl  s    >>3-d;;rD   r:  )r   r	   r   r   r   r   r   )r   rA  r   r   s       rB   	np_appendrF    s     C   !NOOF#   ". / 	/ 4	1 K $.$$ &/ 0 0	<KrD   zarray.ravelc                     d }d }|j                   d   j                  dk(  r|}n|}| j                  ||||      }t        | ||j                  |      }|S )Nc                 8    | j                  | j                        S )zNo copy version)r.  r   r   s    rB   
imp_nocopyzarray_ravel.<locals>.imp_nocopy  s    {{388$$rD   c                 "    | j                         S )zCopy version)flattenrI  s    rB   imp_copyzarray_ravel.<locals>.imp_copy  s    {{}rD   r   r   )r   r  r  r!   r   )r|   r<   rZ   r   rJ  rM  impr   s           rB   array_ravelrO    s_    %
 xx{S  

"
"7Cd
;C
7GS__c
BCJrD   c                 0    d }| j                  ||||      S )Nc                 "    | j                         S r:  )r4  r  s    rB   np_ravel_implznp_ravel.<locals>.np_ravel_impl  s    wwyrD   )r  )r|   r<   rZ   r   rS  s        rB   np_ravelrT    s      ##G]CFFrD   zarray.flattenc                 d    d }| j                  ||||      }t        | ||j                  |      }|S )Nc                 T    | j                         j                  | j                        S r:  )rI  r.  r   rI  s    rB   rN  zarray_flatten.<locals>.imp  s    xxz!!#((++rD   )r  r!   r   )r|   r<   rZ   r   rN  r   s         rB   array_flattenrW    s8    , 
"
"7Cd
;C
7GS__c
BCJrD   c                    |t        j                  |       n|}t        j                  | ||      \  }}}t        j                  |j                        D ]*  }||   }	||   }
||   }t        t        |	|
      |      ||<   , |S r:  )rg  
empty_likebroadcast_arraysndindexrd   minr  )r  a_mina_maxr   rU  a_ba_min_ba_max_br   val_a	val_a_min	val_a_maxs               rB   _np_clip_implre    s     "k"--
sC//5%@C'CII&E
EN	EN	UI.	:E
	 ' JrD   c                     t        j                  | j                        D ]-  }| |   }||   }|rt        ||      ||<   t	        ||      ||<   / |S r:  )rg  r[  rd   r\  r  )r  buse_minr   r   rb  val_bs          rB   _np_clip_impl_nonerj    sU    AGG$%%UE*CJUE*CJ % JrD   c                 &   t        |       st        j                  d      t        |t        j
                        s t        |      st        j                  d      t        |t        j
                        s t        |      st        j                  d      t        |t        j                        s"t        |      sd}t        j                  |      |d u xs t        |t        j
                        }|d u xs t        |t        j
                        }|r|rdd}|S t        |t        j                        }t        |t        j                        }	|r|	rdd}
|
S |r|	s|rdd}|S dd}|S |s|	r|rdd	}|S dd
}|S |rdd}|S |rdd}|S dd}|S )Nr2  z6The argument "a_min" must be a number or an array-likez6The argument "a_max" must be a number or an array-likez5The argument "out" must be an array if it is providedc                     t        d      )Nz&array_clip: must set either max or minr   r  r]  r^  r   s       rB   
np_clip_nnznp_clip.<locals>.np_clip_nn	  s    EFFrD   c                     |t        j                  |       n|}t        j                  | j                        D ]   }| |   }t	        t        ||      |      ||<   " |S r:  )rg  rY  r[  rd   r\  r  r  r]  r^  r   rU  r   rb  s          rB   
np_clip_ssznp_clip.<locals>.np_clip_ss	  sV     '*k"--"sCAGG,% UE!2E:E
 - JrD   c                     |t        j                  |       n|}t        j                  | j                        D ]  }| |   }t	        ||      ||<    |S r:  )rg  rY  r[  rd   r  rp  s          rB   
np_clip_snznp_clip.<locals>.np_clip_sn'	  O     +.+bmmA&3ZZ0EeHE!$UE!2CJ 1 
rD   c                 J    t        j                  | |      }t        | |||      S r:  rg  	full_likere  )r  r]  r^  r   
a_min_fulls        rB   
np_clip_saznp_clip.<locals>.np_clip_sa4	  s%    
  \\!U3
$Q
E3??rD   c                     |t        j                  |       n|}t        j                  | j                        D ]  }| |   }t	        ||      ||<    |S r:  )rg  rY  r[  rd   r\  rp  s          rB   
np_clip_nsznp_clip.<locals>.np_clip_ns?	  rt  rD   c                 J    t        j                  | |      }t        | |||      S r:  rv  )r  r]  r^  r   
a_max_fulls        rB   
np_clip_asznp_clip.<locals>.np_clip_asL	  s%    
  \\!U3
$Qz3??rD   c                     |t        j                  |       n|}t        j                  | |      \  }}t        ||d|      S )NTrg  rY  rZ  rj  )r  r]  r^  r   rU  r_  ra  s          rB   
np_clip_naznp_clip.<locals>.np_clip_naX	  s=    *-+bmmA&3!221e<W)#wcBBrD   c                     |t        j                  |       n|}t        j                  | |      \  }}t        ||d|      S )NFr  )r  r]  r^  r   rU  r_  r`  s          rB   
np_clip_anznp_clip.<locals>.np_clip_an`	  s=    *-+bmmA&3!221e<W)#wsCCrD   c                     t        | |||      S r:  )re  rm  s       rB   
np_clip_aaznp_clip.<locals>.np_clip_aah	  s     %Quc::rD   r:  )	r   r	   r   r   r   NoneTyper   r   r  )r  r]  r^  r   r   a_min_is_nonea_max_is_nonern  a_min_is_scalara_max_is_scalarrq  rs  ry  r{  r~  r  r  r  s                     rB   np_clipr    s   A  !FGGuenn- '   #4 6 	6 uenn- '   "4 5 	5 sEKK(K,<E  %% TMFZu~~%FMTMFZu~~%FM	G  5O 5O?		 		 @ 	 @  C D ; rD   clipc                     dd}|S )Nc                 2    t        j                  | |||      S r:  )rg  r  rm  s       rB   r   zarray_clip.<locals>.impls	  s    wwq%,,rD   NNNrn  )r  r]  r^  r   r   s        rB   
array_clipr  q	  s    -KrD   c           	      v   |j                   |j                   k(  sJ |j                  |j                  k(  sJ t        |j                        }t        d      t        d      t        d      t        j                  fd}| j                  t        j                  t        | |            }| j                  t        j                  t        | |            }| j                  t        j                  |j                         }	t        j                  ||j                  d      dd      }
t        j                  ||j                  d      dd      }t        j                  t        j                  dd	      }| j                  |      }t        j                  || j                  t        j                  |j                         g      }| j                  | j                  t        j                              }| j                  t        j                  |      }t        j                  ||g      } || |      }t!        ||
|||d
        || |      }t!        |||||d
       |j#                         }|j#                         }|	||||| j                  t        j                  |      g}t%        t        j&                  t        j                  ||t        j                  t        j                  t        j                        }| 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.
    rG  r   Fc                 "   |	k(  r!|d   |k(  r	 
      }n|d   |k(  r       }||k7  r|	k(  s| dk(  ry|
k(  r| dz
  }nd}||k  r!||z  dk7  ry||z  }||xx   |z  cc<   |||<   y||kD  r||   |z  }||z  dk7  ry||z  ||<   |||<   y	 y)Nr  r   FrF   Trn  )r  rk   r   old_itemsizenew_itemsizer  rl   newdim
bytelength
any_layoutc_layoutf_layoutint8s            rB   rN  z_change_dtype.<locals>.imp	  s     Zr{l*h|+h<'Vz-AR1WXQAA,& |+1!\1FGvG%GAJ"  L( a</J\)a/ L0DG%GAJ  rD   rd   r   r   rF   r  Nr  )ro   r  ordr   r  r   r   r~   r
   rg   rf   r   rw   ri   r{   ry   r   r   r$   booleanr  r   r    r   )r|   r<   oldtynewtyr   
new_layoutrN  r  r  r  
shape_datastrides_datashape_strides_array_typearyclsshape_constantsizeof_intpstrides_constantr&  strides_aryrd   r   r   rZ   r   r  r  r  r  s                           @@@@rB   _change_dtyper  x	  s    ::###<<5<<'''U\\"JSJ3xH3xH::D.` ''

(4We(DFL''

(4We(DFL 
		ejj%**	5B%%gs/C/CG/L&',J''(+(<(<Y(GAOL  %{{!CP 89F'')0)=)=ejj>Cjj*J )KLN (()>)>uzz)JKK&&uzz;?K))'K=Aw(I9"'+'! '*K;$'+'! !E##%Gwl  Z8:D EMMJJ,,JJJJJJC 
"
"7Cd
;CeS!
GWcoos
CCJrD   c                 L    t        |       st        j                  d      d }|S )Nz+The argument to np.shape must be array-likec                 @    t        j                  |       j                  S r:  )rg  rh  rd   rR  s    rB   r   znp_shape.<locals>.impl	  s    zz!}"""rD   r   r	   r   r  r   s     rB   np_shaper  	  s&    A  !NOO#KrD   c                 L    t        |       st        j                  d      d }|S )Nz*The argument to np.size must be array-likec                 @    t        j                  |       j                  S r:  )rg  rh  r   rR  s    rB   r   znp_size.<locals>.impl
  s    zz!}!!!rD   r  r  s     rB   np_sizer   
  s&    A  !MNN"KrD   c                     d }|S )Nc                     t        j                  | j                               }t        |d d       }t	        |dd        D cg c]  \  }}||   |k7  s| }}}t        j
                  ||z         S c c}}w r  )rg  sortr4  r   r  r   )arrg  headrl   rA  tails         rB   np_unique_implz!np_unique.<locals>.np_unique_impl
  sl    GGBHHJAbqE{'!".<.da!A$!).<xxt$$ =s   A3A3rn  )r  r  s     rB   	np_uniquer  
  s    %
 rD   c                    d }t        | t        j                  t        j                  t        j                  t        j
                  t        j                  f      rt        |t        j                        rt        S t        |t        j                  t        j                  f      r&t        |j                  t        j                        r|S t        j                  d      y )Nc                 @   t        j                  |t         j                        }|j                  d   dk(  rt	        | |d         S t        j
                  |dk        rt        d      t        j                  |       }|j                         }|j                  d   }|j                  |j                  k7  rt        d      t        j                  t        j                  |      |j                        }d}t        |      D ]  }||   |||||   z    |||   z  } |S )Nrz   r   rF   rx  z(operands could not be broadcast together)rg  rh  int64rd   np_repeat_impl_repeats_scalerr@  r   r4  emptyr  rz   r7   )	r  r<  repeats_arrayasaaraveln	to_returnposrl   s	            rB   !np_repeat_impl_repeats_array_likez4np_repeat.<locals>.np_repeat_impl_repeats_array_like
  s    

7"((;q!Q&0M!4DEE66-!#$BCCjjmLLO<<=...:< <HHRVVM2#))D	qA6<QiIcC-"223=##C  rD   zIThe repeats argument must be an integer or an array-like of integer dtype)r   r   r   ListrF  r  r  r   r  rz   r	   r   )r  r<  r  s      rB   	np_repeatr  
  s    
, !ekkjjoollmm	  gu}}-00%++uzz!:;'--788  01 	1rD   c                    |dk  rt        d      t        j                  |       }|j                         }|j                  d   }|dk(  r!t        j
                  d|j                        S |dk(  rt        j                  |      S t        j
                  ||z  |j                        }t        |      D ]  }||   |||z  |dz   |z    |S )Nr   rx  r  rF   )	r   rg  rh  r4  rd   r  rz   rI  r7   )r  r<  r  r  r  r  rl   s          rB   r  r  C
  s    {>??
**Q-CYY[FQA!|xx++	AwwvHHQ[		:	qA9?Ia'kQUg$56 rD   repeatc                     d }|S )Nc                 .    t        j                  | |      S r:  )rg  r  )r  r<  s     rB   array_repeat_implz'array_repeat.<locals>.array_repeat_implW
  s    yyG$$rD   rn  )r  r<  r  s      rB   array_repeatr  U
  s    % rD   c                 :    t        j                  |      }d }||fS )z"Computes the itemsize of the dtypec                     | j                  |j                  d   j                        }| j                  |j                        } || j	                  |            S r   )ry   r   rz   r   r{   )cgctxr<   rZ   llargsr}   llintps         rB   rS  z%_intrin_get_itemsize.<locals>.codegenb
  sJ    ""388A;#4#45$$S__5e**4011rD   )r   r   )tyctxrz   rZ   rS  s       rB   _intrin_get_itemsizer  ]
  s#     **U
C2 <rD   c                      y r:  rn  )r  rz   s     rB   _compatible_viewr  i
      rD   generic)targetc                     d }|S )zDDetermines if the array and dtype are compatible for forming a view.c                    t        |      }|| j                  k7  r| j                  dk(  rd}t        |      	 | j                  dz
  }| j                  |   dk7  }| j
                  dk7  }| j                  |   | j                  k7  }|r|r|rd}t        |      || j                  k  r%|dk(  s| j                  |z  dk7  rd}	t        |	      y | j                  |   | j                  z  }
|
|z  dk7  rd}t        |      y y )Nr   zOChanging the dtype of a 0d array is only supported if the itemsize is unchangedrF   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   ro   r   rd   r   r   )r  rz   
dtype_sizemsg1r   p1p2p3r;  msg3r  msg4s               rB   r   z ol_compatible_view.<locals>.impls
  s   )%0
#vv{7 &&  66A:D!#B1B4AJJ.Brb2 &&AJJ&?ajj:&=&BID$T** 'C
 3J&!+1D %T**	 ,9 $rD   rn  r  rz   r   s      rB   ol_compatible_viewr  m
  s    "+F KrD   z
array.viewc                    |j                   d   }|j                  } t        |      | ||d         } t        |      | |      }t        |j                  j
                        }t        |      D ]N  }	t        ||	      }
|	dk(  r.|j                  j                  }|j                  |
|      |_        Bt        ||	|
       P t        dk\  r\| j                  }|j                  t              }|j!                  |g |j                   i       }| j#                  ||      } |||       t%        | ||||      }|j'                  d|t)        |j                  d            }|j+                  |      5  d}| j,                  j/                  |t0        |f       d d d        |j3                         }t5        | ||j                  |      S # 1 sw Y   1xY w)Nr   r   )rF      r  z"new type not compatible with array)r   r   rw   r   r   r   sortedgetattrr   r8   r'  r   r   typing_contextresolve_value_typer  get_call_typerP   r  r  r   r
  rU  rV  r   r   r    )r|   r<   rZ   r   r   r#  r   rU  fieldsr   r   r  r  r  _compatible_view_sigr   r   r(  r   r   s                       rB   
array_viewr  
  s   HHQKEOOE
*U
GWd1g
6C
*U
GW
-C''(FF^c1o;HHMMEsE2CHCC    &&''(89#11%388rJ##D*>?Wd	ws	;B  r8BGGQ+?@D		2))':vF 
 --/CWgsDD 
	s   +%G  G	rz   c                 >    | j                         }t        | |||      S r:  )rZ  r"   r|   r<   rt  r  r   s        rB   array_dtyper  
  s!    

!
!
#CgwS99rD   rd   c                 `    t        |      } || ||      }|j                  }t        | |||      S r:  )rw   rd   r"   r|   r<   rt  r  r   r   r   s          rB   array_shaper  
  s5     oGGWe,E
++CgwS99rD   r   c                 `    t        |      } || ||      }|j                  }t        | |||      S r:  )rw   r   r"   r  s          rB   array_stridesr  
  s5     oGGWe,E
--CgwS99rD   ro   c                 r    | j                  t        j                  |j                        }t	        | |||      S r:  )r   r   r   ro   r"   r  s        rB   
array_ndimr  
  s/     

uzz388
4CgwS99rD   r   c                 `    t        |      } || ||      }|j                  }t        | |||      S r:  )rw   r   r"   r  s          rB   
array_sizer  
  s3    oGGWe,E
,,CgwS99rD   r   c                 `    t        |      } || ||      }|j                  }t        | |||      S r:  )rw   r   r"   r  s          rB   array_itemsizer  
  s5     oGGWe,E
..CgwS99rD   nbytesc                     t        |      } || ||      }|j                  |j                  |j                        }t	        | |||      S )z"
    nbytes = size * itemsize
    )rw   r   r   r   r"   r  s          rB   array_nbytesr   
  sD     oGGWe,E
++ellENN
3CgwS99rD   
contiguousc                 r    | j                  t        j                  |j                        }t	        | |||      S r:  )r   r   r  	is_contigr"   r  s        rB   array_contiguousr     s-    


u}}cmm
<CgwS99rD   c_contiguousc                 r    | j                  t        j                  |j                        }t	        | |||      S r:  )r   r   r  is_c_contigr"   r  s        rB   array_c_contiguousr    -    


u}}coo
>CgwS99rD   f_contiguousc                 r    | j                  t        j                  |j                        }t	        | |||      S r:  )r   r   r  is_f_contigr"   r  s        rB   array_f_contiguousr    r	  rD   rO  c                 t    | j                  t        j                  |j                         }t	        | |||      S r:  )r   r   r  mutabler"   r  s        rB   array_readonlyr    s/    


u}}#++o
>CgwS99rD   ctypesc                     t        |      } || ||      }t        j                  |      }| j                  ||      }|j                  |_        |j
                  |_        |j                         }t        | |||      S r:  )rw   r   ArrayCTypesr   r   r   r   r    )	r|   r<   rt  r  r   r   actctinfor   s	            rB   array_ctypesr    sp    oGGWe,E


C
 C  #.F**FK]]FN



CWgsC88rD   r   c                     | j                  |||      }|j                  }|j                  || j                  t        j
                              }t        | |||      S Nr  )r   r   r  r   r   r   r"   )r|   r<   rt  r  r  r   s         rB   array_ctypes_datar  '  sT      #U ;F
++C


3 6 6uzz B
CCgwS99rD   c                     | j                  |||      }|j                  }|j                  || j                  |            }t	        | |||      S r  )r   r   r'  r   r"   )r|   r<   fromtytotyr   r  r   s          rB   array_ctypes_to_pointerr  0  sP       & <F
++C
//#w55d;
<Cgwc::rD   c                     t        |      |||      }t        j                  t        j                  |j                        }|j                  |j                  |j                              }t        t        j                  ||t        j                        }|j                  |j                  |j                  t        j                  |      g}|j                  || ||      }	|	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  )rw   r   rp  r   ro   r{   r   rz   r$   bool_rd   r   r   r  )
checkerr|   r<   r   r   tup_intpr   	check_sig
check_argsr  s
             rB   _call_contiguous_checkr$  9  s     *U
GWC
8C~~ejj%**5H%%g&<&<U[[&IJH%++x5::FI))S[[&&uzz8<>J(('9)35IrD   r   c                     | j                  |t        j                  |            }||_        |j	                         }| j
                  j                  |||       t        | |||      S r:  )r   r   
ArrayFlagsr   r   r   r   r!   )r|   r<   rt  r  flagsobjr   s         rB   array_flagsr(  S  s[    ""7E,<,<S,ABHHO



CKKwU+GWc377rD   c                 :   |j                   j                  dk7  r<| j                  |||      }t        t        | ||j                   |j
                        }n9|j                   j                  dk(  }| j                  t        j                  |      }t        | |||      S )Nr   r  )
ra   r  r   r$  r   r   r   r   r  r"   )r|   r<   rt  r  r'  r   r   s          rB   array_flags_c_contiguousr*  \  s     ~~#&&w5&A$]GW%(^^X__F nn##s*""5==#6gwS99rD   c                 x   |j                   j                  dk7  r<| j                  |||      }t        t        | ||j                   |j
                        }nX|j                   j                  }|j                   j                  dkD  r|dk(  n|dv }| j                  t        j                  |      }t        | |||      S )Nr  r  rF   r  )ra   r  r   r$  r   r   ro   r   r   r  r"   )r|   r<   rt  r  r'  r   r  r   s           rB   array_flags_f_contiguousr,  j  s    
~~#&&w5&A$Z'%(^^X__F &&"~~22Q6fmFdN""5==#6gwS99rD   r  c                     |j                   t        j                  v rt        | |||d      S |j                   t        j                  v rt        | |||      S t        dj                  t        j                               )Nr  attrzunsupported .real for {})	rz   r   complex_domainarray_complex_attrnumber_domainr    rQ   r   r8   )r|   r<   rt  r  s       rB   array_real_partr3  {  se    
yyE(((!'7CVLL	e))	) '3>>!"<"C"CDJJ"OPPrD   r  c                 2   |j                   t        j                  v rt        | |||d      S |j                   t        j                  v rt        |j                  d      |      }t        | |||g      \  }}t        | |||      }t        j                  ||j                  |j                  |j                  |j                        d       t        | ||j                   |j#                               S t%        dj'                  t(        j                               )Nr  r.  TrX  r   zunsupported .imag for {})rz   r   r0  r1  r2  r$   rI  _parse_empty_like_argsr  r
   memsetr   r   r   r   r!   r   r   rQ   r   r8   )r|   r<   rt  r  rZ   rJ  r   r   s           rB   array_imag_partr7    s    
yyE(((!'7CVLL	e))	)$/50'3PWgw?w'++cll69jj+BCD	F#// #1 	1 ""<"C"CDJJ"OPPrD   c                    |dvs|j                   t        j                  vrt        dj	                  |            t        |      } || ||      }|j                   j                  }| j                  | j                  |            }|j                  j                  |      }	| j                  |      j                         }
|j                  |j                  |
      }|dk(  r,|j                  | t!        j"                  d      d      g      }|j%                  |d      } t        |      | |      }t'        ||	      }t)        j*                  |||       t-        | |||j/                               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      rF   rG  rz   r  )r   r   )rz   r   r0  rQ   r   rw   underlying_floatr{   ry   r   r8   r   r  r'  r   r  r   IntTyperI  r   r
   copy_structr    r   )r|   r<   rt  r  r/  r   r   fltysizeof_fltyr   
llfltptrtyr   resulttyr  repls                  rB   r1  r1    sE   8 ##syy8L8L'L!"="D"DT"JKKoGGWe,E 99%%D(()>)>t)DEK~~"";/H ''-88:Jooejj*5G v~++g

2q(9':; xxd3x/H!Z!'73FWx0Dt,Wgx9I9I9KLLrD   conj	conjugatec                     d }|S )Nc                 ,    t        j                  |       S r:  )rg  rC  r   s    rB   r   zarray_conj.<locals>.impl  s    wws|rD   rn  r   r   s     rB   
array_conjrI    s    KrD   c                 "    | j                         S r:  )rZ  )r|   r<   dtypetydtypevals       rB   
dtype_typerM    s    ""$$rD   r8   kindstatic_getitemc                     |j                   }t        |t        j                        r% | j	                  |      d      }t        | |||      S d}t        j                  |      )zThis handles the "static_getitem" when a Numba type is subscripted e.g:
    var = typed.List.empty_list(float64[::1, :])
    It only allows this on simple numerical types. Compound types, like
    records, are not supported.
    NzlUnreachable; the definition of __getitem__ on the numba.types.abstract.Type metaclass should prevent access.)r   r   r   r   r   r"   r	   LoweringError)r|   r<   rZ   r   r#  r   r   s          rB   static_getitem_number_clazzrR    s^     OOE%% ,g$$U+D1!'7E3??L""3''rD   c           
         t        |      } || ||      }|j                  }t        |t        j                        st        d|d|d      |j                  |      }|j                  |      }	t        |t        j                        r6|j                  |j                  |j                  |j                  z   d      }
n|j                  |d      }
t        |
      } || |      }| j                  t        j                  |	      }t        j                  ||j                  ||j                  j                         }t        |t        j                        rt        j"                  ||j$                  |j                        }||j$                  D cg c]"  }| j                  t        j                  |      $ c}z  }t        j"                  ||j&                  |j                        }||j&                  D cg c]"  }| j                  t        j                  |      $ c}z  }| j)                  | j+                  |j                              }n8|j$                  }|j&                  }| j)                  | j+                  |            }t-        ||||| j                  t        j                  |      |j.                  |j0                         |j3                         }t5        | ||
|      S c c}w c c}w )	zq
    Generic getattr() implementation for record arrays: fetch the given
    record member, i.e. a subarray.
    z
attribute z of z not definedrG  r  r:  )r   r0  )rw   rz   r   r   RecordrQ   typeofr   NestedArrayrI  ro   r   r   r
   r   r   r8   r   rd   r   r{   ry   r   r   r   r   r    )r|   r<   rt  r  r/  r   r   rectyperz   r   restyrarytyraryconstoffset
newdataptrrd   rl   r   datasizer   s                       rB   array_record_getattrr^    sZ    oGGWe,EiiGgu||,!%)3#0 1 	1NN4 E^^D!F%**+++CHHuzz$9#  G uS1F'7#D&&uzz6:K$$[tyy~~J %**+$$Wekk388Du{{K{!'&&uzz15{KK&&wsxxHOAG((Q7OO))'*?*?*LM --))'*?*?*FG4""#00XF ==,,( ..
CWguc::' L Ps   'K)8'K.c                 v    |d   }t        |t              st        t        | ||j                  d   |d   |      S r  )r   strrQ   r^  r   )r|   r<   rZ   r   r   s        rB   array_record_getitemra  6  s:    GEeS!!!#((1+tAwNNrD   c           
         | j                  ||       |j                  |      }|j                  |      }t        |t        j
                        r5t        |      } || |      }|j                  }	|j                  D 
cg c]"  }
| j                  t        j                  |
      $ }}
|j                  D 
cg c]"  }
| j                  t        j                  |
      $ }}
t        j                  |||| j                  |	            }t        ||t        j                   ||      t        j                   ||      | j                  t        j                  |j"                        dd       |j%                         }t'        | |||      S t        j                  |||| j                  |            }|j(                  rdnd}| j+                  ||||      }t'        | |||      S c c}
w c c}
w )zT
    Generic getattr() implementation for records: get the given record member.
    Nr0  rF   )sentry_record_alignmentr   rU  r   r   rV  rw   rz   rd   r   r   r   r
   get_record_memberry   r   ri   r   r   r    r   r   )r|   r<   rt  r  r/  r   elemtyr   r   rz   r   r  r  newdatar   dptrr   s                    rB   record_getattrrh  ?  s   
 ##C.ZZFZZF&%++, 6"GW%LL"  =>G((Q7  	 " nn&$ ?@g**5::q9$ 	 &++GUF,3,A,A%,HJ$$Wh7&&w
;))%**fkkB	
 mmo '3<<((%)0)>)>v)FH""7FD%@ '3<<-"&s   >'G5'G#c           	         |j                   \  }}|\  }}| j                  ||       |j                  |      }	|j                  |      }
t	        |
t
        j                        r t        j                  |      | ||d         }|j                  }t        j                  |||	|j                  j                        }t        j                  |||| j                  t
        j                  |
j                                yt        j                  |||	| j#                  |
            }| j%                  ||||
      }|j&                  rdnd}| j)                  ||
|||       y)zT
    Generic setattr() implementation for records: set the given record member.
    rF   r  Nr   )r   rc  r   rU  r   r   rV  r
   rv   r   rd  r8   pointeememcpyr   r   r   ry   r   r   r   )r|   r<   rZ   r   r/  rt  rI  r  r   r   re  
val_structr-  rR  rg  r   s                   rB   record_setattrrm  g  s1   
 JCKFC##C.ZZFZZF&%++,7W007>B1gG
oo((&&),)9)9;wc++EJJF	H ((&&)0)>)>v)FHll7C77FCUCrD   c                     | j                  |j                  d   |d         } || ||j                  d   |d   |d         S )3
    Record.__getitem__ redirects to getattr()
    r   rF   )get_getattrr   )r|   r<   rZ   r   r   s        rB   record_static_getitem_strrq    sE    
 sxx{DG4D#((1+tAwQ@@rD   c                 2   |j                   d   j                  }t        |j                   d   j                        }| j	                  |j
                  ||         }| j                  |j                   d   |      } || ||j                   d   |d   ||         S )ro  rF   r   )r   r   r   r  insert_const_stringr9   rp  )r|   r<   rZ   r   r   r  ll_fieldr   s           rB   record_static_getitem_intru    s    
 ((1+
#
#C#((1+$$%F**7>>6#;GHsxx{H5D#((1+tAwsDDrD   static_setitemc                     |j                   \  }}}|\  }}}	t        |j                  ||      }
| j                  ||
      }|J  ||||	f      S )3
    Record.__setitem__ redirects to setattr()
    )r   r$   r   get_setattr)r|   r<   rZ   r   rectyr  rI  recr   r   getattr_sigr   s               rB   record_static_setitem_strr}    s_    
 hhOE1eMCcCOOUE:KsK0D#s$$rD   c                     |j                   \  }}}|\  }}}	t        |j                  ||      }
t        |j                   d   j                        }| j                  ||   |
      }|J  ||||	f      S )rx  r   )r   r$   r   r   r  ry  )r|   r<   rZ   r   rz  r  rI  r{  r   r   r|  r  r   s                rB   record_static_setitem_intr    s{    
 hhOE1eMCcCOOUE:K#((1+$$%Fvc{K8D#s$$rD   c                 (    | j                  |||      S )zB
    Create a constant array (mechanism is target-dependent).
    )make_constant_array)r|   r<   r=  pyvals       rB   constant_arrayr    s    
 &&wE::rD   c                     t        j                  t        j                  d      |j                        } |t	        |j                                     }t        j                  ||      S )zG
    Create a record constant as a stack-allocated array of bytes.
       )r   r  r<  r  	bytearraytostringr
   r   )r|   r<   r=  r  ltyr   s         rB   constant_recordr    sI    
 ,,rzz!}ell
3C
i()
*C$$Wc22rD   c                     t        j                  t        |      t         j                        }| j	                  |||      S )zM
    Create a constant array from bytes (mechanism is target-dependent).
    r  )rg  r   r  uint8r  )r|   r<   r=  r  bufs        rB   constant_bytesr    s2    
 ((9U#288
4C&&wC88rD   c                 x    |j                   \  }}||k7  rt        j                  S d }| j                  ||||      S )Nc                     | j                   |j                   k(  xrH | j                  |j                  k(  xr- | j                  j                  |j                  j                  k(  S r:  )rd   r   r  r   r  rg  s     rB   array_is_implzarray_is.<locals>.array_is_impl  sI    177" /		QYY&/.	0rD   )r   r
   r  r  )r|   r<   rZ   r   atybtyr  s          rB   array_isr    s@    xxHC
cz   0
 ##G]CFFrD   __hash__c                     d S )Nc                      y r:  rn  rG  s    rB   r  zol_array_hash.<locals>.<lambda>  s    trD   rn  rG  s    rB   ol_array_hashr    s    rD   c                     t        | d      S )zq
    Return the Structure representation of the given *flatiterty* (an
    instance of types.NumpyFlatType).
    flat_make_flattening_iter_cls)
flatitertys    rB   make_array_flat_clsr    s    
 %Z88rD   c                     t        | d      S )zv
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdEnumerateType).
    ndenumerater  nditertys    rB   make_array_ndenumerate_clsr    s    
 %X}==rD   c                    | j                  t        j                  d      }|j                  d      }	| |j	                  t
        j                  |       t        t        |            D ]  }
t        j                  |||
      }t        j                  ||j                  |            }||
   }|j                  d||      }t        j                  ||      5  |j	                  ||       | ||
       |j                  |	       d d d        |j	                  ||       | ||
        | |j	                  t
        j                  |       |j                  |	       |j!                  |	       y # 1 sw Y   mxY w)Nr   end_incrementr  )r   r   r   rv  r  r
   
false_byter  r7   rg   r  r=   r  	if_likelyr  	true_byter  )r|   r<   ro   rd   r   end_flagloop_continue
loop_breakr   bbendrr  idxptrr   r   	in_boundss                  rB   _increment_indicesr     s:   

A.D&&7Eg(((3d$%%gw<%%gw||F/CDc
''S%8	w	2MM#v&(c"NN5! 3 	dF#!sO %" g''2NN5E" 32s   .E//E8	c                     t        j                  ||j                  |j                        }t	        | ||j                  |||       y r:  )r
   r   rd   ro   r  )r|   r<   r  r   r   r  rd   s          rB   _increment_indices_arrayr  !  s4      #))UZZ@EwUGXNrD   c                 v   	
  j                   
 j                  t         j                        	 j                  r
nd G d dt
              } G d d|       G  fdd|       G d d	|       G d
 d|       G d d|       G 	
 f
ddt        j                               }|S )zq
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdIterType).
    rF   c                   R    e Zd ZdZd Zd Zej                  d        Zd Z	d Z
d Zy)	$make_nditer_cls.<locals>.BaseSubIterzF
        Base class for sub-iterators of a nditer() instance.
        c                 P    || _         || _        || _        || _        ||z
  | _        y r:  )nditermember_name	start_dimend_dimro   )rX   r  r  r  r  s        rB   rt  z-make_nditer_cls.<locals>.BaseSubIter.__init__6  s+     DK*D&DN"DL)+DIrD   c                 F    t        | j                  | j                  |       y r:  )r   r  r  )rX   rj   s     rB   set_member_ptrz3make_nditer_cls.<locals>.BaseSubIter.set_member_ptr=  s    DKK!1!137rD   c                 B    t        | j                  | j                        S r:  )r  r  r  r_  s    rB   
member_ptrz/make_nditer_cls.<locals>.BaseSubIter.member_ptr@  s    4;;(8(899rD   c                      y r:  rn  )rX   r|   r<   s      rB   init_specificz2make_nditer_cls.<locals>.BaseSubIter.init_specificD  r  rD   c                      y r:  rn  rX   r|   r<   logical_dims       rB   r  z2make_nditer_cls.<locals>.BaseSubIter.loop_continueG  r  rD   c                      y r:  rn  r  s       rB   r  z/make_nditer_cls.<locals>.BaseSubIter.loop_breakJ  r  rD   N)rp   rq   rr   rm  rt  r  r2  cached_propertyr  r  r  r  rn  rD   rB   BaseSubIterr  1  s:    		,	8 
	"	"	: 
#	:			rD   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)$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                     |j                  t        j                  d      }| j                  t	        j
                  ||             y r   )r   r   r   r  r
   r   )rX   r|   r<   r   s       rB   r  z2make_nditer_cls.<locals>.FlatSubIter.init_specificS  s3    ''

A6D 9 9'4 HIrD   c                 r    |j                  | j                        }|j                  |j                  |g      S r:  )r=   r  r  r   )rX   r|   r<   r   r  r   r   s          rB   compute_pointerz4make_nditer_cls.<locals>.FlatSubIter.compute_pointerW  s+    LL1E;;sxx%11rD   c                     || j                   dz
  k(  rN|j                  | j                        }t        j                  ||      }|j                  || j                         y y r  )ro   r=   r  r
   r  r  )rX   r|   r<   r  r   s        rB   r  z2make_nditer_cls.<locals>.FlatSubIter.loop_continue[  sM    dii!m+T__5//?eT__5	 ,rD   c                 H   |dk(  r=|j                  t        j                  d      }|j                  || j                         y || j
                  dz
  k(  rN|j                  | j                        }t        j                  ||      }|j                  || j                         y y Nr   rF   )	r   r   r   r  r  ro   r=   r
   r  )rX   r|   r<   r  r   r   s         rB   r  z/make_nditer_cls.<locals>.FlatSubIter.loop_breakb  s}    a++EJJ:dDOO4		A-T__5//?eT__5	 .rD   N)rp   rq   rr   rm  r  r  r  r  rn  rD   rB   FlatSubIterr  M  s    	
	J	2	6		6rD   r  c                   "    e Zd ZdZ fdZd Zy)+make_nditer_cls.<locals>.TrivialFlatSubIterzx
        Sub-iterator walking a contiguous array in physical order,
        *without* support for broadcasting.
        c                 "    j                   rJ y r:  )need_shaped_indexing)rX   r|   r<   r  s      rB   r  z9make_nditer_cls.<locals>.TrivialFlatSubIter.init_specifics  s    44444rD   c                 v    t        |      dk  sJ t        |             |j                  |j                  |      S r  )r   r  r   rX   r|   r<   r   r  r   s         rB   r  z;make_nditer_cls.<locals>.TrivialFlatSubIter.compute_pointerv  s2    w<1$2c'l2$;;sxx11rD   N)rp   rq   rr   rm  r  r  r  s   rB   TrivialFlatSubIterr  m  s    	
	5	2rD   r  c                       e Zd ZdZd Zy)'make_nditer_cls.<locals>.IndexedSubIterzA
        Sub-iterator walking an array in logical order.
        c                 l    t        |      | j                  k(  sJ t        j                  |||||d      S NFr  )r   ro   r
   r"  r  s         rB   r  z7make_nditer_cls.<locals>.IndexedSubIter.compute_pointer  s:    w<499,,,++GWeS,3G GrD   Nrp   rq   rr   rm  r  rn  rD   rB   IndexedSubIterr  z  s    		GrD   r  c                       e Zd ZdZd Zy)'make_nditer_cls.<locals>.ZeroDimSubIterz5
        Sub-iterator "walking" a 0-d array.
        c                     |j                   S r:  )r   r  s         rB   r  z7make_nditer_cls.<locals>.ZeroDimSubIter.compute_pointer  s    88OrD   Nr  rn  rD   rB   ZeroDimSubIterr    s    		rD   r  c                       e Zd ZdZd Zy)&make_nditer_cls.<locals>.ScalarSubIterz8
        Sub-iterator "walking" a scalar value.
        c                     |S r:  rn  r  s         rB   r  z6make_nditer_cls.<locals>.ScalarSubIter.compute_pointer  s    JrD   Nr  rn  rD   rB   ScalarSubIterr    s    		rD   r  c                      
 e Zd ZdZej
                   fd       Z	fdZfdZd Z	d Z
	fdZd Zd	 Zy
)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           	          g }j                   rnd}t        j                        D ]0  \  }}|\  }}}}d|z  }	||   }
|j                   |
| |	||             2 |S )N)r  indexed0dscalarzindex%d)r  r  r  rh   )rX   l	factoriesrl   r  rN  r  r  r  r  factoryr  r  r  r  r  r  s              rB   subitersz(make_nditer_cls.<locals>.NdIter.subiters  s    A080M0M0$2-#0	I $H$5$563.1+i!'!m#D/{IwGH	 7
 HrD   c                    |j                  t        j                  d      }|j                  |t        j                  |      |      | _        t        |      D ]K  \  }}t        |t        j                        r!d|z  }t        j                  |||         }	t        | ||	       M | j                  ||||      }t        j                  t        j                        }
d}d}t        |      D ]O  \  }}t        |t        j                        s!|j                  k(  s1||   j                  }||   j                   } n; dk(  sJ |j                  ||
d      }|j                  t        j                  d      }d }t#        ||      D ]  \  }}t        |t        j                        s!|j                  dkD  s1t%        t        j&                  t        j                  t        j                  |j                        |
      }|j)                  ||||j                  |f        t        j*                  ||      }dk(  r|ddd   }|j-                  d	||      }|j/                  |t        j0                  t        j2                        }j4                  s|f}t7        |      k(  sJ t        j8                  ||j:                  
      }t=              D ]+  }t        j>                  |||      }|jA                  ||       - || _!        t        jD                  |||j:                        | _        t        j                  ||      | _#        | jH                  D ]  }|jK                  ||        y)zY
            Initialize the nditer() instance for the specific array inputs.
            r   scalar%dNrn  rF   c                     t        |       }t        |      D ]'  }| |   |t        |      |z
  |z      k7  st        d       y )Nz2nditer(): operands could not be broadcast together)r   r7   r   )rd   
main_shaper  rl   s       rB   check_shapezBmake_nditer_cls.<locals>.NdIter.init_specific.<locals>.check_shape  sJ    JqAQx:c*o.AA.E#FF( *> ? ? "rD   r  r  r  r{  )&r   r   r   
make_tuplerq  arraysr  r   r   r
   r   r   _arrays_or_scalarsrp  ro   rd   r   r   r$   noner  r   r  r  r  r  r  r   rV   r8   r7   rg   r  r   ri   	exhaustedr  r  )rX   r|   r<   arrtysr  r   rl   r=  r  slotmain_shape_tyr  main_nitemsr  r  r   rZ   r   shape_is_emptyr  r   rr  r  subiterr  ro   r  nshapess                           rB   r  z-make_nditer_cls.<locals>.NdIter.init_specific  s    ''

A6D ",,Wekk&6I-35DK #6*2!"ekk2",q.K"44WfQiHDD+t4 + ,,WgvvNF "NN5::t<MJK%f-5eU[[1ejjD6H!'J"()"2"2K	 . qy y$//K
%225::qA? "&&1
seU[[1ejj1n#EJJ$)NN5::uzz$J$13C ,,Wk-0399j2IK 2 ))':>F}" %00{DIN~w7H7H'.'9'9;I 00 &v;')))))'4997KGW~ --gwDdF+ & #DL ++GVTYYGDJ$66w	JDN  ==%%gw7 )rD   c                 2   |j                  d      }t        j                  ||j                  | j                              }t        j
                  ||      5  |j                  d       |j                  |       ddd       j                  }t        j                  || j                        }| j                  ||||      }| j                  }|j                  d       | j                  |||||      }	|	D 
cg c]  }
|
j                          }	}
t        |	      dk(  r|j                  |	d          n,|j                  |j!                  |j"                  |	             t        j                  || j$                        }t'        ||t        |      ||| j                  t)        j*                  | j,                  ||      t)        j*                  | j.                  ||             |j                  |       |j1                  |       y# 1 sw Y   xY wc c}
w )zJ
            Compute next iteration of the nditer() instance.
            r  FNTrF   r   )rv  r
   as_bool_bitr=   r  if_unlikelyr	  r  r  r   r  r   _make_viewsr   r   r  r  r  rd   r  r2  partial_loop_continue_loop_breakr  )rX   r|   r<   r  r  r  r  r  r   viewsr   rd   r  s               rB   iternext_specificz1make_nditer_cls.<locals>.NdIter.iternext_specific  s    ..u5E  ++G,3LL,HJI$$Wi8  'u% 9 __F))'4;;?F,,WgvvNFllG T"$$WgwOE,12EqQ[[]EE25zQeAh'g00(:M:M168 9 (($**=EwUU&(001D1D1818 :  )001A1A1818 :! NN5!##E*? 98 3s   #H9HHc                     | j                   D ]E  }|j                  |cxk  r|j                  k  s#n &|j                  ||||j                  z
         G y r:  )r  r  r  r  rX   r|   r<   rr  r  s        rB   r  z.make_nditer_cls.<locals>.NdIter._loop_continue%  s@    }}==C5#++5%%gwcmm8KL %rD   c                     | j                   D ]E  }|j                  |cxk  r|j                  k  s#n &|j                  ||||j                  z
         G y r:  )r  r  r  r  r	  s        rB   r  z+make_nditer_cls.<locals>.NdIter._loop_break*  s>    }}==C5#++5NN7GS3==5HI %rD   c                 <   dgz  }j                   }| j                  }j                  }	t        |	t        j
                        rt        |	      }	n|	g}	t              D 
cg c](  }
|j                  t        j                  |||
            * }}
t        ||      D ]c  \  }}|\  }}}}||j                  |j                   }dk(  r|ddd   }|D ],  }
||
   J | j                  ||||	|
   ||
   ||
   |      ||
<   . e t        d |D              sJ |S c c}
w )z:
            Compute the views to be yielded.
            Nr  r  c              3       K   | ]  }|  y wr:  rn  r<  r   s     rB   r>  z>make_nditer_cls.<locals>.NdIter._make_views.<locals>.<genexpr>H  s     (%Qq%s   )r  r  r  r   r   rF  r   r7   r=   r
   rg   r   r  r  
_make_viewrr  )rX   r|   r<   r   r  r  r  r  r  rettysrl   r  r  r  array_indicessub_indicesr  narraysr  r  s                   rB   r  z+make_nditer_cls.<locals>.NdIter._make_views/  sC    FW$E((H}}H((F&%//2f  %g0 .1 ||G$8$8'1$MN .  0 !$Hh 7W),&1a%g&7&7HS="-dd"3K&A 8+++#w/5ay/5ay&)W NE!H ' !8 (%((((L0s   "-Dc                    t        |t        j                        r|j                  dk(  sJ |j	                  |||||      } |j                  |      ||      }	t        ||      }
|j                  |t        j                  t        j                  d      d      }|j                  |t        j                  t        j                  d      d      }t        |	||||
d       |	S )zD
            Compute a 0d view for a given input array.
            r   rn  N)r   )r   r   r   ro   r  rw   r~   r  rp  r   r   )rX   r|   r<   r   r#  r  r   r  rj   viewr   rd   r   s                rB   r  z*make_nditer_cls.<locals>.NdIter._make_viewK  s    
 eU[[1ejjAoEE))'7GUCPC,7%%e,Wg>D#GU3H&&wuzz10M')+E((%..Q2O)+-G 4eWhMKrD   c                    g }t        t        ||            D ]j  \  }\  }}t        |t        j                        r*|j                   |j                  |      |||             M|j                  t        | d|z               l |S )Nr  r  )r  r   r   r   r   rh   rw   r  )	rX   r|   r<   r  r  r  rl   r  r   s	            rB   r  z2make_nditer_cls.<locals>.NdIter._arrays_or_scalars_  s     A#,S-@#A<E3eU[[1HH6W//6w7>=@B C HHWT:>:; $B HrD   N)rp   rq   rr   rm  r2  r  r  r  r  r  r  r  r  r  )
r  r  r  r  r  r  r  ro   r  r  s
   rB   NdIterr    sO    	 
	"	"	 	 
#	M	8^(	+T	M
	J
	8	(	rD   r  )ro   r  r   r  r  objectr
   rv   )r  r  r  r  r  r  r  r  r  r  ro   r  s   `  @@@@@@@@@rB   make_nditer_clsr  '  s    
 ==D__F(//"G33dGf 86k 6@2[ 2G G  V V,,X6 Vp MrD   c                 `    | j                    G fddt        j                  |             }|S )zr
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdIndexType).
    c                   &    e Zd ZdZ fdZ fdZy)%make_ndindex_cls.<locals>.NdIndexIterz,
        .ndindex() implementation.
        c                    |j                  t        j                  d      }t        j                  ||j
                  |j                  t        j                              }t        j                  |t        j                        }t              D ]  }t        j                  |||      }|j                  ||       ||   }	|j                  d|	|      }
t        j                  ||
      5  |j                  t        j                  |       d d d         || _        || _        t        j                   |||j
                        | _        y # 1 sw Y   xY wNr   r{  r  )r   r   r   r
   rV   r8   r   r  r7   rg   r  r  r  r  r   r  ri   rd   )rX   r|   r<   r   r   r   r  rr  r  r  dim_is_emptyro   s              rB   r  z3make_ndindex_cls.<locals>.NdIndexIter.init_specific{  s   ''

A6D))'499/6/C/CEJJDH0JKG  11'7;M;MNIT{ --gwDdF+ "#;&44T8TJ((,?MM'"3"3Y? @? # #DL&DN ++GVTYYGDJ @?s   +!EE	c           
      n   |j                  t        j                  d      }|j                  d      }t	        j
                  ||j                  | j                              }t	        j                  ||      5  |j                  d       |j                  |       d d d        t              D cg c]2  }|j                  t	        j                  || j                  |            4 }}|D ]  }	t        ||	        |j                  t	        j                   |||j"                               |j                  d       t	        j$                  || j&                        }
t)        |||
| j                  | j                         |j                  |       |j+                  |       y # 1 sw Y   xY wc c}w )Nr   r  FT)r   r   r   rv  r
   r   r=   r  r  r	  r  r7   rg   r   rH   r  ri   r8   r   rd   r  r  )rX   r|   r<   r  r   r  r  rr  r   r=   rd   ro   s              rB   r  z7make_ndindex_cls.<locals>.NdIndexIter.iternext_specific  sj   ''

A6D..u5E++G,3LL,HJI$$Wi8  'u% 9 #(+/ #.3 ||G$8$89=9<%> ? #.  /  gt,   MM',,WgtyyIJT"(($**dCEwu#||T^^= NN5!##E*' 98/s   8#F%07F2%F/N)rp   rq   rr   rm  r  r  ro   s   rB   NdIndexIterr  v  s    		H,	+rD   r!  )ro   r
   rv   )r  r!  ro   s     @rB   make_ndindex_clsr"  o  s.    
 ==D5+g11(; 5+n rD   c                     dv sJ | j                   }|j                  dk(  r" G fddt        j                  |             }|S  G fddt        j                  |             }|S )N)r  r  r   c                   2    e Zd ZdZ fdZ fdZd Zd Zy)6_make_flattening_iter_cls.<locals>.CContiguousFlatIterzZ
            .flat() / .ndenumerate() implementation for C-contiguous arrays.
            c                    |j                  t        j                  d      }t        j                  ||      | _        |j                  | _        	dk(  rt        j                  ||j                  |j                  t        j                  |j                              }t        |j                        D ]+  }t        j                  |||      }|j                  ||       - || _        y y )Nr   r  r{  )r   r   r   r
   r   r   r   r  rV   r8   ro   r7   rg   r  r   )
rX   r|   r<   r  r   r   r   rr  r  rN  s
            rB   r  zD_make_flattening_iter_cls.<locals>.CContiguousFlatIter.init_specific  s    ++EJJ:$66wE
 "ll=(%11$11%**ejjIKG  %UZZ0!(!5!5gw!LdF3  1 $+DL )rD   c                 $   |j                   }|j                  }|j                  | j                        }|j	                  d||      }	|j                  |	       t        j                  ||	      5  |j                  |j                  |g      }
t        ||||
      }dk(  r|j                  |       n| j                  }t        |      D cg c](  }|j                  t        j                  |||            * }}t        j                  ||      }|j                  t        j                   |||g             t#        |||||       t        j$                  ||      }|j'                  || j                         d d d        y c c}w # 1 sw Y   y xY w)Nr  r  )ro   r   r=   r   r  r	  r
   r  r  r   r   r  r   r7   rg   ri   make_anonymous_structr  r  r  )rX   r|   r<   r  r   r  ro   r   r   r  rj   r  r   rr  idxvalsidxtuplerN  s                   rB   r  zH_make_flattening_iter_cls.<locals>.CContiguousFlatIter.iternext_specific  sr   zzTZZ0"..sE6B  *&&w9!++chh8C%gwsCEv~e, #',, /4Dk#; /:s $+<<0D0DWELEH1J $K /:   #; $+#5#5gw#G#99';CU:KMN 1'514g? $33GUCEMM%4) :9#; :9s    /AF-F8B FFFc                 X    |j                  |j                  |g      }t        ||||      S r:  )r  r   r   rX   r|   r<   r  r   r   rj   s          rB   r  z>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.getitem  s)    kk#((UG4 '5#>>rD   c                 \    |j                  |j                  |g      }t        |||||       y r:  )r  r   r   rX   r|   r<   r  r   r   r  rj   s           rB   setitemz>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.setitem  s(    kk#((UG47GUE3?rD   N)rp   rq   rr   rm  r  r  r  r/  rN  s   rB   CContiguousFlatIterr%    s    +25<?@rD   r1  c                   4    e Zd ZdZd Z fdZd Zd Zd Zy)+_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                    |j                  t        j                  d      }|j                  }|j                  }t        j                  ||j                  |      }t        j                  ||j                  |j                  t        j                  |j                              }	t        j                  ||j                  |j                  t        j                  |j                              }
t        j                  |t
        j                        }t        |      D ]  }t        j                  ||	|      }t        j                  ||
|      }|j                  ||       |j                  ||       ||   }|j                  d||      }t        j                   ||      5  |j                  t
        j"                  |       d d d         |	| _        |
| _        || _        y # 1 sw Y   xY wr  )r   r   r   r   ro   r
   r   rd   rV   r8   r   r  r7   rg   r  r  r  r  r   pointersr  )rX   r|   r<   r  r   r   r   ro   r   r   r5  r  rr  r  ptrptrr  r  s                    rB   r  z9_make_flattening_iter_cls.<locals>.FlatIter.init_specific  s   ++EJJ:xxzz --gsyy$G!--TYYW-A-A%**BG**.NO #..TYYW-A-A%**BG**.NO $55g6=6H6HJ	 !;C$11'7CHF$11'8SIFMM$/MM$/  &c{H#*#8#8x#NL ,,WlCg&7&7C DC '  ' (!* DCs    !G!!G*	c           
      H   |j                   }t        j                  ||j                  |      }t        j                  ||j                  |      }| j
                  }	| j                  }
|j                  t        j                  d      }|j                  d      }t        j                  ||j                  | j                              }t        j                  ||      5  |j                  d       |j!                  |       d d d        |j                  d       t        j"                  ||
|dz
        }|j                  |      }t%        ||||      }dk(  r|j'                  |       nyt)        |      D cg c](  }|j                  t        j"                  ||	|            * }}t        j*                  ||      }|j'                  t        j,                  |||g             t/        t)        |            D ]>  }t        j"                  ||	|      }t        j0                  ||j                  |            }||   }||   }|j3                  d||      }t        j4                  ||      5  |j7                  ||       t        j"                  ||
|      }|j                  |      }t        j8                  |||      }|j7                  ||       t)        |dz   |      D ]+  }t        j"                  ||
|      }|j7                  ||       - |j!                  |       d d d        |j7                  ||       A |j7                  t        j:                  | j                         |j!                  |       |j=                  |       y # 1 sw Y   xY wc c}w # 1 sw Y   }xY w)Nr   r  FTrF   r  r  )ro   r
   r   rd   r   r   r5  r   r   r   rv  r   r=   r  r  r	  r  rg   r   r  r7   ri   r(  r  r  r  r  r  r   r  r  )rX   r|   r<   r  r   r  ro   r   r   r   r5  r   r  is_exhaustedlast_ptrrj   r  rr  r)  r*  r  r   r   r  r  r6  	inner_dimrN  s                              rB   r  z=_make_flattening_iter_cls.<locals>.FlatIter.iternext_specific&  s&   zz --gsyy$G!..wTJ,,==++EJJ:2259  '22W\\$..9 ;((,?$$U+NN5) @   & #//4!8Lll8,!'7E3?6>MM%( +0+7 +63  '||G,@,@AHAD-F  G +6  7  '11'7CHMM55g7?6GIJ $E$K0C$11'7CHF!11'29,,v2FHC #3KE$S\F ' 3 3Ce DI **7I>c62!(!5!5gx!M%ll62%11'3Gc62).sQw)=I%,%9%9':B:C&EF $MM#v6	 *>
  u- ? MM$// 14 g//@u%''.k @?7& ?>s   #N7-N*B2NNN!	c           	         |j                   }t        j                  ||j                  |      }t        j                  ||j                  |      }g }	t        t        |            D ];  }
|	j                  |j                  |||
                |j                  |||
         }= |	j                          t        j                  |||j                  |||j                  |	      }|S )Nr   )ro   r
   r   rd   r   r  r7   rh   uremudivreverser  r   r  )rX   r|   r<   r  r   r   ro   r   r   r   rr  rj   s               rB   _ptr_for_indexz:_make_flattening_iter_cls.<locals>.FlatIter._ptr_for_indexk  s    zz --gsyyM!..w4P #E$K0CNN7<<vc{#CD#LLs<E 1 !//#((06079 
rD   c                 H    | j                  |||||      }t        ||||      S r:  )r?  r   r,  s          rB   r  z3_make_flattening_iter_cls.<locals>.FlatIter.getitem|  s+    ))'7E3N '5#>>rD   c                 L    | j                  |||||      }t        |||||       y r:  )r?  r   r.  s           rB   r/  z3_make_flattening_iter_cls.<locals>.FlatIter.setitem  s*    ))'7E3N7GUE3?rD   N)	rp   rq   rr   rm  r  r  r?  r  r/  r0  s   rB   FlatIterr3    s%    +BC/J"?@rD   rB  )ra   r  r
   rv   )r  rN  ra   r1  rB  s    `   rB   r  r    sr    ****&&JCB	@'"="=j"I B	@H #"E	@w22:> E	@N rD   r  c                 >   t        t        j                  |            } || |      }||_        | j	                  |      } || ||j                  d            }|j                  | |||       |j                         }t        | |t        j                  |      |      S Nr   )rY   )	r  r   NumpyFlatTyper   rw   rf   r  r   r    )r|   r<   r  r   flatiterclsflatiterarrclsr   s           rB   make_array_flatiterrI    s    %e&9&9%&@AK7G,HHN&F
'x'@'@'I
JC7GUC8



CWgu/B/B5/I3OOrD   c                     |j                   \  }|\  }t        |      } || ||      }|j                  }| j                  |      }	 |	| ||j                        }
|j                  | |||
|       y r  )r   r  ra   rw   r   r  )r|   r<   rZ   r   r  r  rG  rF  r  rH  r   s              rB   iternext_numpy_flatiterrK    sq     88LZJX%j1K7G8<H!!E&F
'
8CwVDrD   c                    |j                   d   }|\  }}t        |      } || ||      }|j                  }| j                  |      }	 |	| ||j                        }
|j                  | |||
|      }t        | ||j                  |      S Nr   r  )r   r  ra   rw   r   r  r    r   )r|   r<   rZ   r   r  rG  r   rF  r  rH  r   r   s               rB   iternext_numpy_getitemrN    s    !JOHe%j1K7G8<H!!E&F
'
8C


7GUC
?CWgsDDrD   c                    |j                   d   }|\  }}}t        |      } || ||      }|j                  }	| j                  |	      }
 |
| ||j                        }|j                  | ||	|||       | j                         S rM  )r   r  ra   rw   r   r/  rZ  )r|   r<   rZ   r   r  rG  r   r  rF  r  rH  r   s               rB   iternext_numpy_getitem_anyrP    s     !J!HeU%j1K7G8<H!!E&F
'
8CWguc5%@""$$rD   c                     |j                   d   }t        |      } || ||d         }| j                  |j                        } || ||j                        }|j
                  S rM  )r   r  rw   ra   r   r   )	r|   r<   rZ   r   r  rF  rG  rH  r   s	            rB   iternext_numpy_getitem_flatrR    s]    !J%j1K7G47;H
 5 56F
'
8C::rD   c                 P   |j                   \  }|\  }t        t        j                  |            } || |      }||_        | j                  |      } || ||j                  d            }|j                  | |||       |j                         }	t        | ||j                  |	      S rD  )r   r  r   NumpyNdEnumerateTyper   rw   rf   r  r   r    r   )
r|   r<   rZ   r   r  r   	nditerclsr  rH  r   s
             rB   make_array_ndenumeraterV    s    XXFEDC*5+E+Ee+LMIw(FFL&F
'v'>'>w'G
HC
'5#6



CWgsDDrD   c                     |j                   \  }|\  }t        |      } || ||      }|j                  }| j                  |      }	 |	| ||j                        }
|j                  | |||
|       y r  )r   r  ra   rw   r   r  )r|   r<   rZ   r   r  r  r  rU  r  rH  r   s              rB   iternext_numpy_nditerrX    sq     JXHV*84Iwv6FE&F
'
6C
Wguc6BrD   c           
      t   t        |j                  |      D cg c]'  \  }}| j                  |||t        j                        ) }}}t        t        j                  t        |                  } || |      }|j                  | ||       |j                         }	t        | ||j                  |	      S c c}}w )zndindex(*shape))r   r   r   r   r   r"  NumpyNdIndexTyper   r  r   r    r   )
r|   r<   rZ   r   argtyr  rd   rU  r  r   s
             rB   make_array_ndindexr\    s    
  #388T242 \\'3uzz:2 
 4 !!7!7E
!CDIw(F
'51



CWgsDD4s   ,B4c           	         |j                   j                  }|dkD  re|j                  d   j                  }|d   }t	        j
                  |||      }|D cg c]$  }| j                  |||t        j                        & }}ng }t        t        j                  t        |                  }	 |	| |      }
|
j                  | ||       |
j                         }t        | ||j                   |      S c c}w )zndindex(shape)r   )r   ro   r   rz   r
   r   r   r   r   r"  rZ  r   r  r   r    )r|   r<   rZ   r   ro   r   rC  rd   r   rU  r  r   s               rB   make_array_ndindex_tupler^    s     ??Dax!!1g$$Wc48!#!S gsE5::>! 	 #  !7!7E
!CDIw(F
'51



CWgsDD#s   )C.c                 z    |j                   \  }|\  }t        |      } || ||      }|j                  | ||       y r  )r   r"  r  )r|   r<   rZ   r   r  r  r  rU  s           rB   iternext_numpy_ndindexr`    s@     JXHV *Iwv6F
Wgv6rD   c                 H   |j                   }|j                  }t        |j                  d   t        j
                        rt        j                  ||d         }n|d   g} t        |      | |      }|j                  | |||       |j                         }t        | |||      S )z
    nditer(...)
    r   )r   r  r   r   r   rF  r
   r   r  r  r   r    )	r|   r<   rZ   r   r  r  r  r  r   s	            rB   make_array_nditerrb  '  s    
 H__F#((1+u/%%gtAw7q'&_X&w8F
'66:



CWgx==rD   c                 v    |j                   \  }|\  } t        |      | ||      }|j                  | ||       y r  )r   r  r  )r|   r<   rZ   r   r  r  r  s          rB   iternext_numpy_nditer2rd  ;  s=     JXHV&_X&wvFF
Wgv6rD   c                     |j                   \  }}t        j                  t        j                  d      t	        ||k(              }t        | ||j                  |      S r  )r   r   r   r<  r   r"   r   )r|   r<   rZ   r   arg1arg2r   s          rB   dtype_eq_implrh  E  sE    JD$
++bjjmS%6
7CgwEErD   c                    t        |      } || |      }| j                  |j                        }| j                  t        j
                  t        | |            }| j                  t        j
                  d      }t        t        j                  d      d      }	|D ]H  }
|j                  ||
      }|j                  |d      }|j                  |	|j                  |d            }	J |j                  dk(  rd}n|j                  dk(  rO|g}t        |dd       D ]&  }|j!                  |j#                  |d   |             ( t%        t        |            }np|j                  dk(  r=|g}|dd D ]&  }|j!                  |j#                  |d   |             ( t%        |      }n$t'        dj)                  |j                              |j                  ||      }|j                  |d      }|j                  |	|j                  |d            }	|j+                  |	d	
      5  | j,                  j/                  |t0        d       ddd       |j                  }| j3                  |      }| j                  t        j4                  |      }| j7                         ||f}t	        j8                  t        j:                        }t	        j<                  t?        |            }tA        ||t        j
                  t        j4                        }| jC                  |tD        ||      }| jF                  jI                  ||      }| jK                  t        j
                        }tM        jN                  |||      }tM        jN                  |||      }tQ        ||jS                  ||jU                               ||||       |S # 1 sw Y   yxY w)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.
    rF   r   rn  r   Nr  r  z3Don't know how to allocate array with layout '{0}'.FrS  )z[array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.)r=  r  )+rw   ry   rz   r   r   r   r~   r   r   r<  smul_with_overflowrM  r  ro   r  r  rh   r   r   rQ   r   r
  rU  rV  r   get_preferred_array_alignmentuint32rZ  MemInfoPointervoidptrTypeRefr8   r$   r  _call_allocatorr   meminfo_datar   r
   ri   r   r'  r  )r|   r<   rJ  r   r  r   datatyper   arrlenoverflowr   arrlen_multr   dimension_sizeallocsize_multr.  rz   	align_valr   r   miparytypeclassargtypesr   r   r   shape_arraystrides_arrays                               rB   r  r  O  s5     F
'
"C$$W]]3H##EJJWg0NOH !!%**a0F

1q)H00;&&{A6;;g++K;
  ||q	3	*&vabz2NNN7;;wr{NCD 3)*	3	*$SbkNNN7;;wr{NCD *.!AHH ! 	!
 //AN%%na8I{{8W%:%:>1%MNH	%	0 	))Z-	
 
1 MME55e<I  y9E##%y%8D


u}}
-C==g/LlEJJEH&&w4PG;;##GW5D##EJJ/F$$Wf@K&&wFCM3h.A.A.CD$($"$ JA 
1	0s   "N88O	_allocatec                     d }|S )zTImplements a Numba-only default target (cpu) classmethod on the array
    type.
    c                     t        ||      S r:  )intrin_alloc)clsr.  r   s      rB   r   z _ol_array_allocate.<locals>.impl  s    Iu--rD   rn  )r  r.  r   r   s       rB   _ol_array_allocater    s    
.KrD   c                 &    | j                  ||      S )z9Trampoline to call the intrinsic used for allocation
    )r~  )rJ  r   r   s      rB   rp  rp    s     T5))rD   c                 p    d }t        j                  t         j                        }t        |||      }||fS )z3Intrinsic to call into the allocator for Array
    c                 J    |\  }}| j                   j                  |||      }|S r:  )r   meminfo_alloc_aligned)r|   r<   r$   r   r.  r   r   s          rB   rS  zintrin_alloc.<locals>.codegen  s)    !E++33GYNrD   )r   rm  rn  r$   )rT  r.  r   rS  ry  rZ   s         rB   r  r    s5    
 

u}}
-C
CE
*C<rD   c           	         d }t        |t        j                        r&d}| j                  |||t        j                        g}n@t        |t        j
                        sJ |j                  }t        j                  |||      }g }|D ]&  }|j                   || ||j                  |             ( | j                  |t        j                  d      }	t        |      D ]X  }
|j                  d||
   |	      }t        j                  ||      5  | j                  j!                  |t"        d       ddd       Z |S # 1 sw Y   fxY w)z;
    Parse the shape argument to an array constructor.
    c                    | j                  t        j                        }|j                  }t	        j
                  |      }t        |d|dz
  z  dz
        }|j                  |k  r|j                  ||      }|S |j                  |k\  ru|j                  d||      }	|j                  |	d      5  | j                  j                  |t        d       ddd       |j                  |kD  r|j                  ||      }|S |}S # 1 sw Y   0xY w)z0Cast src to intp only if value can be maintainedrF   >FrS  )z#Cannot safely convert value to intpN)r   r   r   rG   r   r<  r   sextr  r
  rU  rV  r   trunc)
r|   r<   src_tr-  r   
intp_widthintp_irmaxvalr   	is_largers
             rB   safecast_intpz#_parse_shape.<locals>.safecast_intp  s    ''

3\\
**Z('Q*q.%8A$=?;;#,,sG,C 
 [[J&++Cf=I59!!11Z< :
 {{Z'mmC1 
 
 :9s   ."C??DrF   r   r   r  )znegative dimensions not allowedN)r   r   r   r   r   rF  r   r
   r   rh   r8   get_constant_genericr7   r  r  rU  rV  r   )r|   r<   r=  r   r  ro   passed_shapesr   r   r   rr  is_negs               rB   _parse_shaper    s   * "emm$ gsB

CD"eoo...xx,,WcFFmGWaffa@A  ''Q?DT{$$S&+t<  &1--%I 21  M 21s   "D::E	c                 b    |j                   d   }|d   }|j                  }|t        | |||      fS )zL
    Parse the arguments of a np.empty(), np.zeros() or np.ones() call.
    r   )r   r   r  )r|   r<   rZ   r   arrshapetypearrshaperJ  s          rB   _parse_empty_argsr    s9     88A;LAwHooGL'<JJJrD   c                    |j                   d   }t        |t        j                        rQ t	        |      | ||d         }t        j                  ||j                  |j                        }|j                  |fS |j                  dfS )z_
    Parse the arguments of a np.empty_like(), np.zeros_like() or
    np.ones_like() call.
    r   r  r   rn  )
r   r   r   r   rw   r
   r   rd   ro   r   )r|   r<   rZ   r   arytyper   r   s          rB   r5  r5    sr    
 hhqkG'5;;'!j!'7$q'B%%gsyyM&&""rD   c                 n    t        |t        j                        rd|  d}t        j                  |      y )NzIf np.z0 dtype is a string it must be a string constant.)r   r   UnicodeTyper	   r   )fnamerz   r   s      rB   _check_const_str_dtyper    s7    %**+ugMN  %% ,rD   c                 <    |j                   } ||||      }d }||fS )Nc                 `    t        | |||      \  }}t        | |||      }|j                         S r:  )r  r  r   r  r<   rZ   r  rJ  r   r   s          rB   rS  znumpy_empty_nd.<locals>.codegen  s2    +E7CHUGWf=}}rD   instance_type)r  ty_shapety_dtypety_retty_refty_rettyrZ   rS  s          rB   numpy_empty_ndr  
  s,    ))H
8X|
4C <rD   c                 v   t        d|       |t        u s7t        |t        j                        r|j
                  t        u st        |      rt        j                  }nt        |      }t        |       }|'|%t        j                  ||d      t        ffd	}|S d|  d| d}t        j                  |      )Nr  r   r  c                     t        | |      S r:  )r  )rd   rz   r#  s     rB   r   zol_np_empty.<locals>.impl$  s    !%66rD   z.Cannot parse input types to function np.empty(, ))r  floatr   r   Function
typing_keyr   doublety_parse_dtypety_parse_shaper   r	   r   )rd   rz   nb_dtypero   r   r   r#  s         @rB   ol_np_emptyr    s    7E*	E5>>	*u/?/?5/H<<!%(% D 0(cB# 	7>ugRwaP  %%rD   c                 <    |j                   } ||||      }d }||fS )Nc                 `    t        | |||      \  }}t        | |||      }|j                         S r:  )r5  r  r   r  s          rB   rS  z$numpy_empty_like_nd.<locals>.codegen1  s2    0fMUGWf=}}rD   r  )r  ty_prototyper  r  r  rZ   rS  s          rB   numpy_empty_like_ndr  ,  s,    ))H
<<
8C <rD   c                    t        d|       t        |      st        |      }n)t        | t        j
                        r| j                  }n| }|dt        | t        j
                        r2| j                  dk7  r| j                  nd}| j                  ||d      n6t	        j
                  |dd      nd|  d| d	}t        j                  |      dfd
	}|S )NrY  rG  r   F)rz   r  rO  r   z3Cannot parse input types to function np.empty_like(r  r  c                     t        | |      S r:  )r  )r   rz   r#  s     rB   r   zol_np_empty_like.<locals>.implL  s    "3u55rD   r:  )r  r   r  r   r   r   rz   r  rI  r	   r   )r   rz   r  r  r   r   r#  s         @rB   ol_np_empty_liker  8  s    </u!%(	C	%99c5;;'#&::#4SZZ#FHH8FUHKEKK!S1E  #uBugQ0  %%6KrD   c                 :    t        j                  |      }d }||fS )Nc                      t        |j                  d         | ||d         }t        j                  ||j                  |j                  |j                  |j                        d       y r   )rw   r   r
   r6  r   r   r   r   )r  r<   rZ   r  r   s        rB   rS  z(_zero_fill_array_method.<locals>.codegenU  sO    %j!%eWfQi@w'++cllCJJ*O	rD   )r   r  )r  rX   rZ   rS  s       rB   _zero_fill_array_methodr  Q  s!    
**T
C <rD   
_zero_fillc                     d }|S )z?Adds a `._zero_fill` method to zero fill an array using memset.c                     t        |        y r:  )r  r_  s    rB   r   z ol_array_zero_fill.<locals>.impl_  s
    %rD   rn  )rX   r   s     rB   ol_array_zero_fillr  \  s    &KrD   c                 0    t        d|       t        fd}|S )Nr5  c                 T    t        j                  | |      }|j                          |S Nr  )rg  r  r  )rd   rz   r   s      rB   r   zol_np_zeros.<locals>.implh  s!    hhuE*
rD   )r  r  rd   rz   r   s      rB   ol_np_zerosr  d  s    7E*  KrD   c                 &    t        d|       dd}|S )N
zeros_likec                 T    t        j                  | |      }|j                          |S r  )rg  rY  r  )r  rz   r   s      rB   r   zol_np_zeros_like.<locals>.implt  s!    mmAU+
rD   r:  r  r  s      rB   ol_np_zeros_liker  o  s    </ KrD   c                 &    t        d|       dd}|S )N	ones_likec                     t        j                  | |      }|j                  }t        t	        |            D ]  }d||<   	 |S Nr  rF   rg  rY  r  r7   r   )r  rz   r   arr_flatr   s        rB   r   zol_np_ones_like.<locals>.impl  s<    mmAU+88X'CHSM (
rD   r:  r  r  s      rB   ol_np_ones_liker  {  s    ;. KrD   c                 ^    t        d|       t        |      st        |      n|dfd	}|S )Nfullc                     t        j                  |       }|j                  }t        t	        |            D ]  }|||<   	 |S r:  rg  r  r  r7   r   )rd   
fill_valuerz   r   r  r   r  s         rB   r  zimpl_np_full.<locals>.full  s=    hhuh'88X'C&HSM (
rD   r:  )r  r   r  )rd   r  rz   r  r  s       @rB   impl_np_fullr    s0    65)u!%( KrD   c                 &    t        d|       dd}|S )Nrw  c                     t        j                  | |      }|j                  }t        t	        |            D ]  }|||<   	 |S r:  r  )r  r  rz   r   r  r   s         rB   rw  z$impl_np_full_like.<locals>.full_like  s<    mmAu%88X'C&HSM (
rD   r:  r  )r  r  rz   rw  s       rB   impl_np_full_liker    s    ;. rD   c                 &    t        d|       dd}|S )Nonesc                     t        j                  | |      }|j                  }t        t	        |            D ]  }d||<   	 |S r  r  )rd   rz   r   r  r   s        rB   r   zol_np_ones.<locals>.impl  s<    hhuE*88X'CHSM (
rD   r:  r  r  s      rB   
ol_np_onesr    s     65) KrD   c                 z    t        d|       t        |      st        |      nt        j                  dfd	}|S )Nidentityc                 f    t        j                  | | f      }t        |       D ]	  }d|||f<    |S r  )rg  r5  r7   )r  rz   r   rl   r  s       rB   r  z"impl_np_identity.<locals>.identity  s7    hh1vx(qAC1I 
rD   r:  )r  r   r  r   r  )r  rz   r  r  s      @rB   impl_np_identityr    s4    :u-u!%(<<
 OrD   c                      y r:  rn  NMs     rB   _eye_none_handlerr    r  rD   c                 J    t        |t        j                        rd }|S d }|S )Nc                     | S r:  rn  r  s     rB   r   z$_eye_none_handler_impl.<locals>.impl      HrD   c                     |S r:  rn  r  s     rB   r   z$_eye_none_handler_impl.<locals>.impl  r  rD   )r   r   r  )r  r  r   s      rB   _eye_none_handler_implr    s&    !U^^$	
 K	KrD   c                 :   |t        |t        j                        rt        j                  t
              nVt        |t        j                  t        j                  f      rt        t        |d|            nt        j                  |      d dt
        ffd	}|S )Nrz   r   c                    t        | |      }t        j                  | |f      }|dk\  r+t        | ||z
        }t	        |      D ]  }d||||z   f<    |S t        | |z   |      }t	        |      D ]  }d|||z
  |f<    |S r  )r  rg  r5  r\  r7   )	r  r  r   rz   _Mr   drl   r  s	           rB   r   znumpy_eye.<locals>.impl  s    q!$hh2w#6ArAvA1X !Aq1uH  
 AE2A1X !AE1H 
rD   )
r   r   r  rg  rz   r  	DTypeSpecr  r   r  )r  r  r   rz   r   r  s        @rB   	numpy_eyer    sn     }
5%..9XXe_	EEOOU\\:	;geWe45XXe_!5  KrD   c                     t        |       st        j                  d      t        | t        j
                        r)| j                  dvrt        j                  d      dd}|S y )N#The argument "v" must be array-like)rF   rX  zInput must be 1- or 2-d.c                 h   | j                   dk(  r| j                  }|d   t        |      z   }t        j                  ||f| j
                        }|dk\  r"t        ||z
        D ]  }| |   ||||z   f<    |S t        ||z         D ]  }| |   |||z
  |f<    |S | j                  \  }}|dk  r||z   }|dkD  r||z
  }t        t        ||      d      }t        j                  || j
                        }|dk\  rt        |      D ]  }| |||z   f   ||<    |S t        |      D ]  }| ||z
  |f   ||<    |S r  )
ro   rd   r  rg  r5  rz   r7   r  r\  r  )r   r   r   r  rU  rl   rowscolss           rB   	diag_implzimpl_np_diag.<locals>.diag_impl  sP   vv{GGaD3q6Mhh1vqww/6"1q5\()!Aq1uH *
 
 #1q5\()!AE1H *
WW
dq5!8Dq5!8DD$+hhq!''*6"1X!"1a!e8A &
 
 #1X!"1q5!8A &
rD   r  )r   r	   r   r   r   r   ro   NumbaTypeError)r   r   r  s      rB   impl_np_diagr    sZ    A  !FGG!U[[!66''(BCC	6 ? "rD   c                    t        | t        j                        sd}t        j                  |      t        | j
                  t        j                        sd}t        j                  |      t        |       dz  fd}|S )Nz5The argument "dimensions" must be a tuple of integersr  c                     t        j                  f| z   t         j                        }d}| D ]K  }t        j                  |t         j                        j	                  t        ||            }|||<   |dz  }M |S )Nr  r   rF   )rg  r  r  aranger.  r.   )
dimensionsr   rl   rr  r   r  rd   s        rB   r   znumpy_indices.<locals>.impl$  ss    hhtj(9C))Crxx088eQ,C CFFA  
rD   )r   r   rp  r	   r   rz   r   r   )r  r   r   r  rd   s      @@rB   numpy_indicesr    so    j%..1E  %%j&&6E  %%JA1HE
 KrD   c                     t        |       sd}t        j                  |      t        |t        t
        j                  f      sd}t        j                  |      dd}|S )Nr  z#The argument "k" must be an integerc                 d   t        j                  |       } | j                         } t        |       }t	        |      }||z   }t        j
                  ||f| j                        }t        j                  d|       }t        j                  d|      }t        |      D ]  }| |   |||z   ||z   f<    |S r   )	rg  rh  r4  r   r  r5  rz   maximumr7   )	r   r   r   abs_kr  r   rl   jts	            rB   r   znumpy_diagflat.<locals>.impl=  s    JJqMGGIFAIhh1vqww'JJq1"JJq!qA !!CAq1u  
rD   r  )r   r	   r   r   r   r   r   )r   r   r   r   s       rB   numpy_diagflatr
  3  sU    A3  %%a#u}}-.3  %% KrD   takec                 `   t        | t        j                        rt        |t        j                        rd }|S t	        d | |fD              r|j
                  dk(  fd}|S t        | t        j                        r0t        |t        j                  t        j                  f      rd }|S y y )Nc                     || j                   dz
  kD  s|| j                    k  rt        d      | j                         |   S )NrF   Index out of bounds)r   
IndexErrorr4  )r  r   s     rB   	take_implznumpy_take.<locals>.take_implS  s<    !&&1*%AFF7): !677779W%%rD   c              3   P   K   | ]  }t        |t        j                           y wr:  r;  r  s     rB   r>  znumpy_take.<locals>.<genexpr>Y  s     
@<C:c5;;'<r?  r  c                    t        j                  |j                  | j                        }r|j	                         }n|}t        j
                  |      }d}| j                         }|D ]<  }|| j                  dz
  kD  s|| j                   k  rt        d      ||   ||<   |dz   }> |j                  |j                        S Nr  r   rF   r  )
rg  r  r   rz   rI  r  r4  r  r.  rd   )	r  r   rU  walkeritrl   r  rA  F_orders	           rB   r  znumpy_take.<locals>.take_impl\  s    ((7<<qww7C  6"BA779D
#qAFF7{$%:;;aAE	 
 ;;w}}--rD   c                    t        j                  |      }t        j                  |j                  | j                        }t        j
                  |      }d}| j                         }|D ]<  }|| j                  dz
  kD  s|| j                   k  rt        d      ||   ||<   |dz   }> |j                  |j                        S r  )
rg  r   r  r   rz   r  r4  r  r.  rd   )r  r   convertrU  r  rl   r  rA  s           rB   r  znumpy_take.<locals>.take_implo  s    hhw'G((7<<qww7C7#BA779D
#qAFF7{$%:;;aAE	 
 ;;w}}--rD   )r   r   r   r   rr  r  r  rF  )r  r   r  r  s      @rB   
numpy_taker  N  s     !U[[!j%--&H	& 

@Aw<
@@..C'	. !U[[!wU__ =>	.  ? "rD   c                     | D cg c]  }t        |t        j                        r|! }}t        d |D              rt        j                  }|S t        d |D              rt        j
                  }|S t        t        ddt        j                  t              j                  z  z        }|D cg c]  }t        j                  |       }}t        ||gz         }|S c c}w c c}w )Nc              3   P   K   | ]  }t        |t        j                           y wr:  r  r<  r  s     rB   r>  z _arange_dtype.<locals>.<genexpr>  s     
8A:a'r?  c              3   P   K   | ]  }t        |t        j                           y wr:  )r   r   Floatr  s     rB   r>  z _arange_dtype.<locals>.<genexpr>  s     8AZ5;;'r?  zint%sr  )r   r   r  r@  
complex128r   r  rg  rz   r   r   	unliteralr  )r   r  boundsrz   NPY_TYrA  unliteral_boundss          rB   _arange_dtyper$  ~  s    CAZ5>>%BaFC

8
88  & L% 
88	8" L 1rxx}/E/E+E FG 9??1EOOA.?$y01L- D& @s   CC.C"c          	        	
 t        |t        j                        r|j                  }t        |t        j                        r|j                  }t        |t        j                        r|j                  }|t        j                  }|t        j                  }|t        j                  }t        | t        j
                        r~t        |t        j                  t        j
                  f      rTt        |t        j                  t        j
                  f      r*t        |t        j                  t        j                  f      sy t        |t        j                        rt        | ||      	n|j                  	t        | ||fD cg c]  }t        |t        j                         c}      
t        | dd       t        |dd       t        |dd       d	
fd	}|S c c}w )Nr   c                   n| }n|}n|}||nd}|d|}	}n||}	}|dk(  rt        d      |	|z
  |z  }
t        t        j                  |
j                              }du r?t        t        j                  |
j
                              }t        t        ||      d      }nt        |d      }t        j                  |      }|}t        |      D ]  }|||z  z   ||<    |S )NrF   r   zMaximum allowed size exceededT)r   r   mathceilr  r  r  r\  rg  r  r7   )r  r  r  rz   	lit_startlit_stoplit_step_step_start_stopnitems_cnitems_rnitems_ir   r   r   rl   start_value
step_value
stop_value
true_dtypeuse_complexs                    rB   r   znp_arange.<locals>.impl  s    #.#:K	!+!7:T!+!7:T$0ayEF%xEFA:<==FNe+tyy/0 $499X]]34HXx0!4F1%Fhhvz*vAAI&CF 
rD   r  )r   r   Optionalr8   r  r  r  r  r$  rz   r@  r  r  )r  r  r  rz   rA  r   r2  r3  r4  r5  r6  s         @@@@@rB   	np_aranger8    sg   $'yy$'yy%(

|zz|zz}

uell+tennell;<tennell;<55>>5??"CD%("5$5
[[
!&d 35 31 "!U]]3 35 6K %$7K5J5J < KK5s   !G"c                    t        d | |fD              sy t        |t        t        j                  f      sd}t        j                  |      t        d | |fD              rt        j                  nt        j                  dfd	}|S )Nc              3   P   K   | ]  }t        |t        j                           y wr:  )r   r   r  r  s     rB   r>  z!numpy_linspace.<locals>.<genexpr>  s     Fz#u||,r?  r  c              3   P   K   | ]  }t        |t        j                           y wr:  r  r  s     rB   r>  z!numpy_linspace.<locals>.<genexpr>  r  r?  c                     t        j                  |      }| dz  } |dz  }|dk(  r|S |dz
  }|dkD  r8|| z
  }t        j                  ||      }t        d|      D ]  }| ||z  z   ||<    n| |d<   |dkD  r||d<   |S )Ng      ?r   rF   r  )rg  r  divider7   )	r  r  r  r   divdeltar  rl   rz   s	           rB   r  z numpy_linspace.<locals>.linspace  s    hhsE" cz!8JAg75LE99UC(D1c]!d(+A # CF7CG
rD   r  )
rr  r   r   r   r   r	   r   r@  r  r   )r  r  r  r   r  rz   s        @rB   numpy_linspacer@    ss    FFFcC/05  %%

CeT]
CC  , OrD   c           
         |j                   d   } t        |      | ||d         }t        j                  ||j                        }|j
                  }t        | |||      }|j                  }	|j                  }
|j                  dv sJ |j                  |j                  k(  r0t        j                  ||
|	|j                  |j                  d       nt        j                  ||j                        }t        j                  ||j                        }| j                  t        j                        }t        j                   |||      5 }t        j"                  | ||	|||j                  |      }t        j"                  | ||
|||j                  |      }|j%                  |j'                  |      |       ddd       t)        | ||j
                  |j+                               S # 1 sw Y   /xY w)z
    Array copy.
    r   r  r  rF   r   N)r   rw   r
   r   rd   r   r  r   r  
raw_memcpyr   r   r   r   r   r   r,  r  r  r=   r!   r   )r|   r<   rZ   r   r  r   r   rettyperU  r   r  r"  r  r   r   r  r/  s                    rB   _array_copyrD    s    hhqkG
*W
gwd1g
>C!!'3995FooG
'7F
;CxxHI>>T!!!~~'7Ix<<q	2 **7CKK@++GS[[A''

3w77//(0607IG 00'91718JH MM',,w/: 8 GWcoos}}OO 87s   A,G""G+c                     t        |t        j                        sJ |j                  dk(  rdnd}|j	                  |d      } ||      }|t
        fS )Nr  r   F)r  rO  )r   r   r   r  rI  rD  )rT  r  r  rU  rZ   s        rB   _array_copy_intrinsicrF  )  sM    a%%%HHOSF
&&&
/C
a&CrD   z
array.copyc                     t        | |||      S r:  )rD  r  s       rB   
array_copyrH  2  s    wd33rD   c                 @    t        | t        j                        rd }S )Nc                     t        |       S r:  )rF  rR  s    rB   
numpy_copyz#impl_numpy_copy.<locals>.numpy_copy:  s    (++rD   r;  )r  rK  s     rB   impl_numpy_copyrL  7  s    !U[[!	,rD   c           	      D   |j                   }|j                  d   }|j                  |k(  sJ d       |j                  dk(  r|j                  dk(  sJ  t	        |      | ||d         } t	        |      | |      }| j                  |t        j                  t        j                  d      d      }	| j                  |t        j                  t        j                  d      |j                  f      }
t        ||j                  |	|
|j                  |j                  |j                         t        | |||j!                               S |j                  |j                  k(  s|j                  dk(  r|j                  dv rt        | |||d         S |j                  dk(  r|dv sJ |dk(  rt"        nt$        }t'        || |||d         }|j)                  |      5 \  }}|5  t        | |||d         }|j*                  }d	d	d	       |5  t-        | |||      }|j*                  }d	d	d	       d	d	d	       |j/                  j0                        }|j3                  |       |j3                         |S t-        | |||      S # 1 sw Y   xY w# 1 sw Y   lxY w# 1 sw Y   pxY w)
zd
    Common logic for layout conversion function;
    e.g. ascontiguousarray and asfortranarray
    r   z return-type has incorrect layoutrF   r  r  r  rG  r   N)r   r   r  ro   rw   r  r   rp  r   r  r   r   r   r   r   r    r   r   r   r$  r  blockrD  phir8   add_incoming)r|   r<   rZ   r   output_layoutr#  r   r   rU  rd   r   
check_funcr  thenorelseout_thenthen_blk
out_orelse
orelse_blkret_phis                       rB   _as_layout_arrayrZ  ?  sZ   
 OOEHHQKE<<=(L*LL(zzQzzQjQ@j1,,U^^EJJ2D
 $$W%*^^EJJ%B&)ll_6 	sCHHeWcll{{CJJ	0 '5#--/JJ
,,%,,
&

aELLD$8 '5$q'BB <<3 !D(((*73*>JJ.z/6/6/4/3Aw	8I
 +~f0'515a :H&}}H 
 !,WgsD!IJ!(J  , kk(--0G  84  Z8N wd;;! T
 V ,+s<   JI>:
JJ
J>J	J
J	JJc                     t        t        j                        st        j                        |j                  j                  t        |j                  d            } ||      }|fdfS )NrF   )r  ro   c                 8    t        | |||j                        S )N)rQ  )rZ  r   )r  rg  r   r  rQ  s       rB   r  z,_as_layout_array_intrinsic.<locals>.<lambda>  s    #3	1a-"="=$?rD   )	r   r   r%   r	   RequireLiteralValuerI  r   r  ro   )rT  r  rQ  rU  rZ   s     `  rB   _as_layout_array_intrinsicr^    sd    mU%8%89((77
&&33#affa.&
IC
a
C ? ? ?rD   c                     t        |       st        j                  d      t        | t        j
                  t        j                  f      rd }|S t        | t        j                        rd }S )Nr2  c                 R    t        j                  t        j                  |             S r:  )rg  ascontiguousarrayr   rR  s    rB   r   z%array_ascontiguousarray.<locals>.impl  s    ''44rD   c                     t        | d      S Nr   r^  rR  s    rB   r   z%array_ascontiguousarray.<locals>.impl      -a55rD   r   r	   r   r   r   r  r  r   r  s     rB   array_ascontiguousarrayrg    sY    A  !FGG!ellEMM34	5
 K 
Au{{	#	6KrD   c                     t        |       st        j                  d      t        | t        j
                  t        j                  f      rd }|S t        | t        j                        rd }|S y )Nr2  c                 R    t        j                  t        j                  |             S r:  )rg  asfortranarrayr   rR  s    rB   r   z"array_asfortranarray.<locals>.impl  s    $$RXXa[11rD   c                     t        | d      S )Nr  rd  rR  s    rB   r   z"array_asfortranarray.<locals>.impl  re  rD   rf  r  s     rB   array_asfortranarrayrl    sZ    A  !FGG!ellEMM34	2	Au{{	#	6 
$rD   zarray.astypec           
      r   |j                   d   } t        |      | ||d         }t        j                  ||j                        }|j
                  }t        | |||      }|j                  }	|j                  }
t        j                  ||j                        }t        j                  ||j                        }| j                  t        j                        }t        j                  |||      5 }t        j                  | ||	|||j                  |      }t        j                  | ||
|||j                  |      }t        | |||      }| j!                  |||j"                  |j"                        }t%        | ||||       d d d        t'        | ||j
                  |j)                               S # 1 sw Y   /xY wrM  )r   rw   r
   r   rd   r   r  r   r   r   r   r   r,  r  r  r   r   rz   r   r!   r   )r|   r<   rZ   r   r  r   r   rC  rU  r   r  r"  r  r   r   r  r/  items                     rB   array_astypero    st    hhqkG
*W
gwd1g
>C!!'3995FooG
'7F
;CxxHI&&w<K''=L##EJJ/F			7FF	3w++GWh,2K,3NNGE ,,Wgy-3\-4^^WF '7G<||GT7=='--H7GWdH= 
4 GWcoos}}OO 
4	3s   /BF--F6c                 <    |j                   } ||||      }d }||fS )Nc           	         |j                   d   }|j                  } t        |      | ||d         }t        |      } || |      }|j                  }	t	        | |      }
t        |j                  j                  |
      }|j                  |j                  |j                        }|j                  ||      }t        j                  ||      }|j                  |d      5  d}| j                  j                  |t         |f       d d d        t        j"                  ||j%                  ||      g      }t        j"                  ||g      }|j'                  |j(                  | j+                  |	j-                  d                  }t/        ||||||j0                  |j2                         |j5                         }t7        | ||j                  |      S # 1 sw Y   xY w)Nr   r  FrS  z.buffer size must be a multiple of element sizer   r0  )r   r   rw   r   r~   r   r   r8   r   r   sremr
   is_not_nullr
  rU  rV  r   ri   sdivr'  r   r   r   r   r   r   r   r    )r|   r<   rZ   r   buftyr   r  
out_ary_tyout_aryout_datamodelr   ll_itemsizer  remis_incompatibler   rd   r   r   r   s                       rB   rS  znp_frombuffer.<locals>.codegen  s   jQ@&
Wg.**/s||00(;SZZ6 ll6;/!--gs;___U_;BC--gzC6J < ""7W\\&+-N,OP$$W{m<HHg,,]-C-CF-KL
 	w "& +"{{!jj	+ ! '3??CHH' <;s    %GGr  )rT  bufferrz   r#  r=  rZ   rS  s          rB   np_frombufferr}    s.    			B
VUE
"C#IH <rD   c                    t        d|       t        | t        j                        r| j                  dk7  rd|  }t        j                  |      |t        u s7t        |t        j                        r|j                  t        u st        |      rt        j                  }nt        |      }|%t        j                  |dd| j                         nd|  d| d}t        j                  |      t        ffd		}|S )
N
frombufferr   z+Argument "buffer" must be buffer-like. Got rF   )rz   ro   r  rO  z3Cannot parse input types to function np.frombuffer(r  r  c                     t        | |      S r:  )r}  )r|  rz   r#  s     rB   r   z impl_np_frombuffer.<locals>.impl  s    VUE22rD   )r  r   r   r   r  r	   r   r  r  r  r   r  r  r   r  )r|  rz   r   r  r   r#  s        @rB   impl_np_frombufferr    s    </fell+v}}/C;F8D  %%	E5>>	*u/?/?5/H<<!%((3)/%79  &xr%3  %%  3KrD   c                     t        |      rt        dd       dfd	}|S t        |t        j                        rt        d|      dfd	}|S y )Nr   c                      | |      S r:  rn  rj   rd   rz   intrinsic_cfarrays      rB   r   zimpl_carray.<locals>.impl      $S%00rD   c                      | |      S r:  rn  r  s      rB   r   zimpl_carray.<locals>.impl  r  rD   r:  r   get_cfarray_intrinsicr   r   r  rj   rd   rz   r   r  s       @rB   impl_carrayr    L    51#t<	1	E5??	+1#u=	1 
,rD   c                     t        |      rt        dd       dfd	}|S t        |t        j                        rt        d|      dfd	}|S y )Nr  c                      | |      S r:  rn  r  s      rB   r   zimpl_farray.<locals>.impl%  r  rD   c                      | |      S r:  rn  r  s      rB   r   zimpl_farray.<locals>.impl+  r  rD   r:  r  r  s       @rB   impl_farrayr     r  rD   c                 (     t          fd       }|S )Nc                 b   |t         j                  u rd }nBt        |t         j                        r|j                  }nd| d}t        j                  |      	|d}t        j                  |      |}nft        	t         j                        r1	j                  }|>||k7  r9d| d| d}t        j                  |      d	 d}t        j                  |      t        |      }|d| d}t        j                  |      t        j                  ||
      }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   rn  r   CPointerrz   r	   r  r  r  r   r$   
np_cfarray)rT  rj   rd   	ptr_dtyper   rz   ro   r#  rZ   dtype_r  s            rB   r  z0get_cfarray_intrinsic.<locals>.intrinsic_cfarray1  s1   %--IU^^,		I4SE;C'',,> B++C00E0LLE$));+E72Fse1M++C00(2C'',,e$<#E7!,C'',,E40sE*JrD   r)   )r  r  r  s   `` rB   r  r  0  s     > rD   c           
         |j                   dd \  }}|dd \  }}|j                  }|j                  dv sJ  t        |      | |      }	t	        | |      }
t        j                  |
      }t        |t        j                        rt        j                  ||      }n|f}|f}t        ||      D cg c]'  \  }}| j                  |||t        j                        ) }}}|}g }|j                  dk(  r+|D ]%  }|j                  |       |j                  ||      }' nCt!        |      D ]%  }|j                  |       |j                  ||      }' |j#                          |j%                  || j'                  |j(                        j+                               }t-        |	||||d       |	j/                         }t1        | ||j                  |      S c c}}w )zR
    numba.numpy_support.carray(...) and
    numba.numpy_support.farray(...).
    NrX  r  r  r  )r   r   r  rw   r~   r
   r   r   r   rF  r   r   r   r   rh   r   r  r>  r'  ry   rz   r  r   r   r!   )r|   r<   rZ   r   r  r  rj   rd   r   rw  r   ry  r   r  r  offr   r   r   r   s                       rB   r  r  T  s   
 XXbq\NE7bqJCOOE<<4j1GGU+H..*K'5??+%%gu5*#&w#79#7-&% ll7E65::>#7  9 CG||sANN3++c1%C  &!ANN3++c1%C " 	??3"00=HHJLD 7"' 


CGWcoosCC99s   0,Gc                 0   t        |t        j                        r)| j                  t        j                  t        |            S t        |t        j                        r8| j                  t
        t        t        j                  |            } |||f      S J r:  )	r   r   rF  r   r   r   r  rP   r$   )r|   r<   seqtyseqr  s        rB   _get_seq_sizer    sj    %)##EJJE
;;	E5>>	*''Yuzz5-JK#((qrD   c                      |j                    j                  t        j                  t	        |t
        j                               fd}|S )zK
    Return a getitem() implementation that doesn't incref its result.
    c                 l     | |      }j                   rj                  j                  | |       |S r:  )r   r   decref)r<   r   rU  r|   r  r#  s      rB   wrapz$_get_borrowing_getitem.<locals>.wrap  s3    7D)KKws3
rD   )rz   rP   r  r  r$   r   r   )r|   r  r  r  r#  s   `  @@rB   _get_borrowing_getitemr    sC     KKE''(8(8(1%

(KML KrD   c           	      
     j                  t        j                        }t        |d       fd}g }||}	}t	        |      D ]0  }
|
dkD  r |||	      \  }}	|j                  t         ||	             2 t        |      S )zF
    Compute the likely shape of a nested sequence (possibly 0d).
    r   c                     t        | t        j                        r&t        |       dk(  ry| d   j	                  |d      fS t        |       }| j                   ||f      fS )Nr   NN)r   r   rF  r   rM  r  rz   )r  r  r  r<   r|   r   s      rB   get_first_itemz.compute_sequence_shape.<locals>.get_first_item  sa    eU__-5zQ!Qx!6!6sA!>>>1'5AL;;WsDk BBBrD   )r   r   r   r   r7   rh   r  r   )r|   r<   ro   r  r  r   r  r   innertyinnerrl   r   s   ``         @rB   compute_sequence_shaper    s     ##EJJ/FFADC FCUG4[q5+GU;NGUmGWguEF 
 =rD   c                 <      fd fd |||       y)z?
    Check the nested sequence matches the given *shapes*.
    c                  H    j                   j                   t        d       y )N)zincompatible sequence shape)rU  rV  r   )r<   r|   s   rB   _failz#check_sequence_shape.<locals>._fail  s    ))':*J	LrD   c                    t        |      dk(  ry t        | |      }|d   }j                  d||      }j                  |d      5           d d d        t        |      dk(  ry t	        | t
        j                        rZt        |       }t        j                  |      5 }| j                  } |||j                  f      }	 ||	|dd         d d d        y t	        | t
        j                        r>t        t        |             D ]&  }
| |
   }j                  ||
      }	 ||	|dd         ( y J |        # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   rR  FrS  rF   )r   r  r  r
  r   r   r  r  r
   r  rz   r   rF  r7   rM  )r  r  r   r   expectedr?  r  r  r  r  rl   r  r<   check_seq_sizer|   s              rB   r  z,check_sequence_shape.<locals>.check_seq_size  s;   v;!Wguc:!9&&tT8<__Xe_4G 5 v;!eU^^,1'5AL""7D1T++$WsDJJ.?@wvabz: 21
 u/3u:&(--c15wvabz: ' eO1) 54 21s   
D<%/E<EENrn  )r|   r<   r  r  r   r  r  s   ``   @@rB   check_sequence_shaper    s    
L: 5#v&rD   c                 N    	  fd		 fd ||d       y)zl
    Assign a nested sequence contents to an array.  The shape must match
    the sequence's structure.
    c           
          t        j                  	j                  | d      }j                  ||j                        }t        ||       y r  )r
   r  r  r   rz   r   )
r   rI  r   rj   r  r<   r|   r   r   r   s
       rB   assign_itemz-assign_sequence_to_array.<locals>.assign_item  sQ    ''$(-g%Qll7C<7GUC5rD   c                    t        |      dk(  r7t        | t        j                  t        j                  f      rJ  || |       y |d   }t        | t        j                        rit        |       }t        j                  |      5 }| j                  } |||j                  f      } |||dd  ||j                  fz          d d d        y t        | t        j                        rct        t        |             D ]K  }	| |	   }j                  ||	      }j                  t        j                  |	      }
 |||dd  ||
fz          M y J |        # 1 sw Y   y xY wr  )r   r   r   r  rF  r  r
   r  rz   r   r7   rM  r   r   )r  r  r   r   r   r  r  r  r  rl   r   assignr  r<   r|   s              rB   r  z(assign_sequence_to_array.<locals>.assign  s8   v;!!%%..%//)JKKK,ayeU^^,1'5AL""7D1T++$WsDJJ.?@wvabz7djj]3JK 21
 u/3u:&(--c15,,UZZ;wvabz7eX3EF	 ' eO1 21s   >EErn  Nrn  )
r|   r<   r   r   r   r  r  r  r  r  s
   ``````  @@rB   assign_sequence_to_arrayr    s"    6 62 5#vr"rD   c                     t        | |      \  }}t        |      r|}nt        |      }|y t        j                  ||d      S rc  )r3   r   r  r   r   )rT  r  rz   ro   	seq_dtypes        rB   np_array_typerr    sD    ,Y?OD)5u%=;;udC((rD   c                 T    t        d|       t        | ||      } |||      }d }||fS )Nr   c           
      j   |j                   }|j                  }|j                  d   }|d   }t        | ||||      }t	        |      |k(  sJ t        | ||||       t        | |||      }	t        | ||	j                  ||	j                  |||       t        | ||j                   |	j                               S r   )r   ro   r   r  r   r  r  r  r   r   r!   r   )
r|   r<   rZ   r   r  ro   r  r  r   r   s
             rB   rS  znp_array.<locals>.codegen$  s    zz1g'$sK6{d"""Wguc6BWguf= '388V!$eUC	A  #// #1 	1rD   )r  r  )rT  objrz   rU  rZ   rS  s         rB   np_arrayr    s6    7E*
C
/C
c5/C1" <rD   c                     t        d|       t        |       st        j                  d      t	        |      s"t        |      d}t        j                  |      dd}|S )Nr   z(The argument "object" must be array-likez:The argument "dtype" must be a data-type if it is providedc                     t        | |      S r:  )r  )r  rz   s     rB   r   zimpl_np_array.<locals>.implB  s    &&rD   r:  )r  r   r	   r   r   r  )r  rz   r   r   s       rB   impl_np_arrayr  8  s^    7E*F#   "1 2 	2u."7"?J  %%'KrD   c                    |j                  d      }|j                  |      }|j                  d||      }|j                  ||j                  ||      |      }|j	                  |j                  d||      |j                  d||            }|j                  |d      5  d|z  }	| j                  j                  |t        |	f       d d d        |S # 1 sw Y   |S xY w)Nr   r  r  FrS  z%s(): axis out of bounds)	r8   r  r  r  r  r
  rU  rV  r  )
r|   r<   r   ro   r   r   ll_ndimis_neg_axisaxis_out_of_boundsr   s
             rB   _normalize_axisr  G  s    99Q<DiioG %%c46K>>+w{{4'A4HD !Ct,D$02 
+E	:(94))':vF 
; K	 
; Ks    (CCc           
      v   t        |      |dz
  k(  sJ t        j                  t        j                  |      }t        j
                  ||      }t        j                  d      }t        |dz
        D ]z  }t        j                  |      }	|j                  d|	|      }
||   }|j                  |
|j                  |	|      |	      }|j                  |t        j                  ||d|             | |j                  |t        j                  ||d|             t        j                  ||j                  |            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).
    rF   r  r   r   r   r  r
   r   rV   r7   r  r  r  r  rg   r   r=   )r|   r<   
orig_shapero   r   ll_shtyr   r#  rr  ll_dim
after_axisr,  r   s                rB   _insert_axis_in_shaper  Z  s    z?dQh&&&ll7>>40G  '2F
..
C TAX$((vt<
_nnZ$[[5#% 	b'..w3GH  MM#w++GVQEFf)=>>rD   c           
         t        |      |dz
  k(  sJ t        j                  t        j                  |      }t        j
                  ||      }t        j                  d      }t        j                  d      }t        |dz
        D ]x  }	t        j                  |	      }
|j                  d|
|      }|j                  ||j                  |
|      |
      }|j                  ||	   t        j                  ||d|             z |j                  |t        j                  ||d|             t        j                  ||j                  |            S )zD
    Same as _insert_axis_in_shape(), but with a strides array.
    rF   r   r  r  )r|   r<   orig_stridesro   r   r  r   r#  r   rr  r  r  r   s                rB   _insert_axis_in_stridesr  w  s    |q(((ll7>>40G!!'73G
..
C>>!D TAX$((vt<
nnZ$[[5#% 	l3'**7GQD	F  MM$,,Wgq$GHg)>??rD   c           	         |j                   }|j                  }|j                  d   } t        |      | ||d         } t        |      | |      }	t	        j
                  ||j                        }
t	        j
                  ||j                        }t        | ||
||      }t        | ||||      }t        |	|j                  |||j                  |j                  |j                         |	j                         S )z/
    np.expand_dims() with the given axis.
    r   r  r0  )r   ro   r   rw   r
   r   rd   r   r  r  r   r   r   r   r   r   )r|   r<   rZ   r   r   r#  ro   r  r   rU  r   r   
new_shapesnew_stridess                 rB   expand_dimsr    s     OOE::DHHQKE
*U
GWDG
<C
*U
GW
-C!!'3995F""7CKK8G&wtLJ)'7GT4PK3#&LL;;**& ==?rD   c                     |j                   dk  r|j                  nd}|j                  |j                   dz   |      } |||      }d }||fS )NrF   rG  rH  c                     | j                  ||d   |j                  d   t        j                        }t	        | |d|j
                  j                  |      }t        | ||||      }t        | ||j
                  |      S )NrF   znp.expand_dims)	r   r   r   r   r  r   ro   r  r    )r|   r<   rZ   r   r   rU  s         rB   rS  znp_expand_dims.<locals>.codegen  so    ||GT!Wchhqk5::Fw1A"33T; '7Ct< '3??CHHrD   )ro   r  rI  )rT  r  r   r  rU  rZ   rS  s          rB   np_expand_dimsr    sN    1QXX#F
&&affqj&
0C
a,CI <rD   c                     t        | t        j                        sd|  }t        j                  |      t        |t        j
                        sd| }t        j                  |      d }|S )Nz)First argument "a" must be an array. Got z(Argument "axis" must be an integer. Got c                     t        | |      S r:  )r  )r  r   s     rB   r   z!impl_np_expand_dims.<locals>.impl  s    a&&rD   )r   r   r   r	   r   r   )r  r   r   r   s       rB   impl_np_expand_dimsr    sb    a%9!=  %%dEMM*8?  %%'KrD   c                 0     t          fd       fdS )Nc           	      0   ||D cg c](  }|j                  t        |j                              * c}fd}t        t	              dkD  rt        j                        nd   t
        j                  j                  |            |fS c c}w )Nr   c                 F   t              }t        j                  ||d         }t        |      D cg c]  \  }}} || ||||       }	}}}t	        |	      dkD  r| j                  ||j                  |	      }
n|	d   }
t        | ||j                  |
      S c c}}}w r  )_atleast_nd_transformr
   r   r   r   r  r   r    )r|   r<   rZ   r   	transformarrsr   r  r#  retsrU  r  r  minimumr  s              rB   rS  z*_atleast_nd.<locals>.impl.<locals>.codegen  s    -gt<I''a9D .1vv-FH-F)UE gwUEB-F  H 4y1}((#//4H1g$WgsLLHs   BrF   r   )	rI  r  ro   r$   r   r   rq  StarArgTuple
from_types)typingcontextr   r  rS  r  r  r  r  s       @@rB   r   z_atleast_nd.<locals>.impl  s    CGH4C#((CHHg 6(74H	M FaV,VAY++66t<>?FG 	G Is   -Bc                       |  S r:  rn  )r   r   s    rB   r  z_atleast_nd.<locals>.<lambda>  s	    trD   r  )r  r  r   s   ``@rB   _atleast_ndr    s    G G( %$rD   c                 6      t              k(  sJ  fd}|S )z`
    Return a callback successively inserting 1-sized dimensions at the
    following axes.
    c           	         t        
      D ]t  }|dz   }|j                  |k  st        j                  	|         }|j	                  |j                  dz         }t        | |t        j                  ||      |f|      }|}v |S )NrF   r   )r7   ro   r
   r   rI  r  r   r$   )r|   r<   r   r  r#  rl   ro   r   newarrtyr  min_ndims            rB   r  z(_atleast_nd_transform.<locals>.transform  s    xAq5DzzD ~~d1g. ::5::>::!'7"("2"28U"CcV"&( ! ! 
rD   )r   )r  r  r  s   `` rB   r  r    s$    
 s4y    rD   c                  B    t        d | D              rt        ddg      S y )Nc              3   P   K   | ]  }t        |t        j                           y wr:  r;  r  s     rB   r>  z np_atleast_1d.<locals>.<genexpr>       
84C:c5;;'4r?  rF   r   rr  r  r  s    rB   np_atleast_1dr     s$    

84
881qc"" 9rD   c                  D    t        d | D              rt        dddg      S y )Nc              3   P   K   | ]  }t        |t        j                           y wr:  r;  r  s     rB   r>  z np_atleast_2d.<locals>.<genexpr>  r  r?  rX  r   r  r  s    rB   np_atleast_2dr    s&    

84
881q!f%% 9rD   c                  D    t        d | D              rt        dg d      S y )Nc              3   P   K   | ]  }t        |t        j                           y wr:  r;  r  s     rB   r>  z np_atleast_3d.<locals>.<genexpr>  r  r?  r  )r   r   rX  r  r  s    rB   np_atleast_3dr    s"    

84
881i(( 9rD   c	                 f   t        |      t        |      cxk(  rt        |      cxk(  rt        |      k(  sJ  J t        j                  d      }	t        | |||      }
t        j                  ||
j
                        }g }|D ]  }|	}t        t        ||            D ]_  \  }\  }}|j                  d|j                  |      |      }|j                  ||      }|j                  ||j                  ||      |      }a |j                  |        |
j                  }t        |||||      D ]  \  }}}}}|j                  }t        j                  ||t        j                  |j                         }|5 }t        j"                  | |||||j                   |      }t%        | |||      }| j'                  |||j(                  |j(                        }t        j"                  | |||||j                   |      }t+        | ||||       ddd       t        j,                  |||      } |
S # 1 sw Y   $xY w)z2
    Concatenate arrays along the given axis.
    r   r  )orderN)r   r
   r   r  r   r   r  r   r  r8   r   r  r  rh   r   r,  r  r  r   r   rz   r   r   )r|   r<   r   r  r  
arr_shapesarr_stridesr#  
ret_shapesr   rU  ret_stridescopy_offsetsarr_shr   rr  r   r  is_axisaddendret_datar  r   arr_starr_datar,  r   r  r   r/  s                                 rB   _do_concatenater    s    v;#d)Js:J#k:JJJJJJ>>!D '5*
=C&&w<K L#,S-E#FC$))$		#EG[[v.F^^G$+KK$?$*,F $G 	F#  xxH.1&$
2=|/M*sFFF88 %%gvw~~,1LL:	 '//(0605gGG GWeW=C,,wU[[%++FC00'81;[16wHH wX>  &&w&A+/M. J Ys   4BH''H0	c                 x   |j                   }t        ||      D cg c]  \  }} t        |      | ||       }}}t        | |d||      }|D 	cg c]"  }	t	        j
                  ||	j                        $ }
}	|D 	cg c]"  }	t	        j
                  ||	j                        $ }}	|
d   D cg c]  }t	        j                  ||       }}t        |      D ]C  }|j                  d|j                  |      |      }||   }|j                  |      }|
dd  D cg c]  }||   	 }}|j                  |      5 \  }}|5  t        j                  |j                   ||gz         }|j#                  ||       d d d        |5  t        j$                  }|D ]%  }|j'                  ||j                  d||            }' |j)                  |j+                  |      d      5  | j,                  j/                  |t0        d|z  f       d d d        d d d        d d d        F |D cg c]  }|j                  |       }}t3        | |||||
|||	      }t5        | |||j7                               S c c}}w c c}	w c c}	w c c}w c c}w # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY wc c}w )	Nr  np.concatenater   r  rF   FrS  z<np.concatenate(): input sizes over dimension %d do not match)ro   r   rw   r  r
   r   rd   r   r   r7   r  r8   r=   r  r2  r3  r  r  r4  r  r
  r  rU  rV  r   r  r!   r   )r|   r<   r  r  r#  r   ro   r  r  r   r  r  r,  r  rr  r  ret_shape_ptrret_shother_shapeson_axison_other_dimis_okrU  s                          rB   _np_concatenater  O  s   ::D fd+-+Q JsOGWA6+ 	 - 7G-=tTJD GKKds'&&w		:dJKIMN#7''=KN 'qM+)b ++GR8)  + T{%%dDIIcNDA"3m,*4QR.9.B3.9__W%)@'<%%KK F8+- b-0	  ((&B#LL)0)<)<T2v)NPE ' __W\\%%8_G%%5557:; => H  &% 0 .88Zr',,r"ZJ8
'7D $
K-C GWeS]]_EEY- LN
+ :  HG  &%$ 9sx   I+'I1='I6-I;J 9J*?7J6
J* AJ&J	JJ*"J7J
J*JJJ'#J**J4	c                 	   |j                   }t        j                  d      }t        j                  d      }t        j                  t        |            }	t	        ||      D 
cg c]  \  }
} t        |
      | ||       }}
}t        | |d||      }t        j                  ||d   j                        }|dd  D ]  }t        j                  }t	        t        j                  ||j                        |      D ]t  \  }}|j                  ||j                  d||            }|j                  |j                  |      d      5  | j                  j                  |t         d       d d d        v  |D cg c]"  }t        j                  ||j"                        $ }}t%        j&                  t        j                  |      }t        j(                  ||      }t        j(                  ||      }t+        |dz
        D ]  }t        j                  |      }|j                  d	||      }||   }|j-                  ||j/                  ||      |      }|j1                  |t        j2                  ||d|             |j1                  |t        j2                  ||d|              |j1                  |t        j2                  ||d|             |j1                  |	t        j2                  ||d|             t        j                  ||j5                  |            }|gt        |      z  }t        j                  ||j5                  |            }t+        t        |            D cg c]  }t        j(                  ||       }}t+        |dz
        D ]  }t        j                  |      }|j                  d	||      }|j-                  ||j/                  ||      |      }t+        t        |            D ]3  }|j1                  ||   |   t        j2                  |||   d|             5  t+        t        |            D ]-  }|j1                  |t        j2                  |||   d|             / |D cg c]'  }t        j                  ||j5                  |            ) }}t7        | ||||||||	      }t9        | |||j;                               S c c}}
w # 1 sw Y   xY wc c}w c c}w c c}w )
Nr   rF   r  np.stackr  FrS  )z5np.stack(): all input arrays must have the same shaper  )ro   r
   r   r   r   rw   r  r   rd   r4  r  r  r
  r  rU  rV  r   r   r   r  rV   r7   r  r  r  rg   r=   r  r!   r   )r|   r<   r  r  r#  r   ro   r   r#  
ll_narraysr  r  r  r   r  r,  orig_shr  r  input_shapesr  rr  r  r  r   rl   input_stridesr-  rU  s                                rB   	_np_stackr    s   ::D>>!D
..
CD	*J fd+-+Q JsOGWA6+ 	 - 7GZtDD %%gtAw}}=JABx  w33GSYYG)+KBLL(;(;D"g(NOEe!4UC!!11ZNP DC+  KOO$3G((#++>$LO
 ll7>>40G&&w8L$$Wg6J TAX$((vt<
_nnZ$[[5#% 	b'..waMNb'..w
AsKL  MM#w++G\1dKLMM*g2273=34379 :
 ''l1KLL >CI-L%%gw||J/GHJ $CI.0. ((':.  0 TAX$((vt<
nnZ$[[5#% s4y!AMM,q/#.!..wa8H!/245 "  3t9dG00-:JA157 	8 
  -., ))'7<<3CD,  . '7D $m-C GWeS]]_EE_- DC
 PB0*.s$   $S"S6'S !S%0,S*Sc                     |t        |t        j                        sy t        | d|      \  }}|dk(  rt	        d      t        |      }t        j                  |||      S )Nr  r   z.zero-dimensional arrays cannot be concatenated)r   r   r   r4   	TypeErrorr5   r   )rT  r  r   rz   ro   r  s         rB   np_concatenate_typerr    sb    
4 ? 	 &i&6@KE4qyHII)&1F;;udF++rD   c                 t    t        | ||      }t        |t        j                        sJ  |||      }d }||fS )Nc           
          | j                  ||d   |j                  d   t        j                        }t	        | |t        |j                  d         t        j                  ||d         |j                  |      S r  )	r   r   r   r   r  r   r
   r   r   r|   r<   rZ   r   r   s        rB   rS  znp_concatenate.<locals>.codegen  se    ||GT!Wchhqk5::Fw#CHHQK0&33GT!WE"#	% 	%rD   )r  r   r   r   )rT  r  r   rU  rZ   rS  s         rB   np_concatenater    sA    
y&$
7Cc5;;'''
fd
C% <rD   c                 D    t        | t        j                        rdd}|S y )Nc                     t        | |      S r:  )r  r  r   s     rB   r   z!impl_np_concatenate.<locals>.impl  s    !&$//rD   r  r   r   rF  r  r   r   s      rB   impl_np_concatenater!    s    &%//*	0 +rD   c                 d    |D ]+  }|j                   dk  s|j                   dkD  s"t        d       y)NrF   rX  z7np.column_stack() is only defined on 1-d and 2-d arrays)ro   r  )r|   r   r  r  s       rB   _column_stack_dimsr#    s8    66A:! 1 2 2  rD   c                     t        | d|t              \  }}t        |      }t        j                  |||      } ||      }d }||fS )Nznp.column_stack)dim_chooserc                 B   t        |j                  d         }t        j                  ||d         }g }g }| j	                  t
        j                  d      }t        ||      D ]  \  }	}
|	j                  dk(  r#|j                  |	       |j                  |
       8|	j                  dk(  sJ |	j                  d      }t        j                  ||	      }t        | |||
f|      }|j                  |       |j                  |        t        | ||||j                  |      S )Nr   rF   rX  r   )r   r   r
   r   r   r   r   r   ro   rh   rI  r   r$   r  r  r   )r|   r<   rZ   r   orig_arrtys	orig_arrsr  r  r   r  r   r  
expand_signewarrs                 rB   rS  z np_column_stack.<locals>.codegen  s   388A;'(($q':	##EJJ2k95JE3zzQe$C  zzQ&


*#--eU;
$WgzC64Pe$F# 6 w"6 	6rD   )r4   r#  r5   r   r   )rT  rC  rz   ro   r  rU  rZ   rS  s           rB   np_column_stackr+    sS    %i&72DFKE4 *#.F
++eT6
*C
c(C64 <rD   c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S r:  )r+  rC  s    rB   r   zimpl_column_stack.<locals>.impl6  s    "3''rD   r  rC  r   s     rB   impl_column_stackr0  3  s    #u'	( (rD   c           
          t        | |t        |j                  d         t        j                  ||d         |j
                  |      S )z/
    np.stack() with the given axis value.
    r   )r  r   r   r
   r   r   r  s        rB   _np_stack_commonr2  ;  sC     Wg#((1+&))'47;__	 rD   c                     t        | d|      \  }}t        d |D              rdnd}t        j                  ||dz   |      } |||      }d }||fS )Nr  c              3   :   K   | ]  }|j                   d k(    yw)r  N)r  r  s     rB   r>  z"np_stack_common.<locals>.<genexpr>K  s     8ACs   r  r   rF   c                     | j                  ||d   |j                  d   t        j                        }t	        | ||||      S r  )r   r   r   r   r2  r  s        rB   rS  z np_stack_common.<locals>.codegenO  s9    ||GT!Wchhqk5::F#tTBBrD   )r4   rr  r   r   )	rT  r  r   rz   ro   r  rU  rZ   rS  s	            rB   np_stack_commonr6  F  sa     &i&0&:KE4888ScF
++eTAXv
.C
fd
CC <rD   c                 D    t        | t        j                        rdd}|S y )Nc                     t        | |      S r:  )r6  r  s     rB   r   zimpl_np_stack.<locals>.implY  s    "6400rD   r  r  r   s      rB   impl_np_stackr9  V  s    &%//*	1 +rD   c                     t        | ||      \  }}t        ||      }t        |      }t        j                  |||      }|S r:  )r4   r  r5   r   r   )rT  r   r  ndim_minrz   ro   r  rU  s           rB   NdStack_typerr<  ^  sA    %iFCKE4tXD)&1F
++eT6
*CJrD   c                 <    t        | d|d      } ||      }d }||fS )Nz	np.hstackrF   c                     |j                   d   }|d   j                  }|dk(  r/| j                  t        j                  d      t        | |||      S |dk(  rdndfd}| j                  ||||      S )Nr   rF   c                 2    t        j                  |       S rC  rE  r  s    rB   np_hstack_implz3_np_hstack.<locals>.codegen.<locals>.np_hstack_implz  s    ~~f488rD   r   ro   r   r   r   r2  r  )r|   r<   rZ   r   rB  ro   r@  r   s          @rB   rS  z_np_hstack.<locals>.codegenl  sz    Qx}}19''

A6D#GWc4FF
 	1qD9 ++G^S$OOrD   r<  rT  rC  rU  rZ   rS  s        rB   
_np_hstackrD  g  s-    
	;Q
7C
c(CP& <rD   c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S r:  )rD  r.  s    rB   r   zimpl_np_hstack.<locals>.impl      c?"rD   r  r/  s     rB   impl_np_hstackrH        #u'	# (rD   c                 <    t        | d|d      } ||      }d }||fS )Nz	np.vstackrX  c                     |j                   d   }|d   j                  }|dk(  rd }n7|dk(  r/| j                  t        j                  d      }t        | ||||      S d }| j                  ||||      S )Nr   c                 T    t        j                  t        j                  |       d      S r  )rg  r  hstackr  s    rB   np_vstack_implz3_np_vstack.<locals>.codegen.<locals>.np_vstack_impl  s    ~~bii&7;;rD   rF   c                 0    t        j                  | d      S )Nr   rD  rE  rN  s    rB   rO  z3_np_vstack.<locals>.codegen.<locals>.np_vstack_impl      ~~f155rD   rA  )r|   r<   rZ   r   rB  ro   rO  r   s           rB   rS  z_np_vstack.<locals>.codegen  sx    Qx}}19< QY''

A6D#GWc4FF6 ''dKKrD   rB  rC  s        rB   
_np_vstackrR    s-    
	;Q
7C
c(CL& <rD   c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S r:  )rR  r.  s    rB   r   zimpl_np_vstack.<locals>.impl  rG  rD   r  r/  s     rB   impl_np_vstackrU    rI  rD   c                 <    t        | d|d      } ||      }d }||fS )Nz	np.dstackr  c                    |j                   d   }|j                  }|d   j                  }|dk(  rd }| j                  ||||      S |dk(  r| j	                  t
        j                  d      }|j                  |j                  dz
        }	t        j                  |	g|j                    }
t        | ||
||      }| j	                  t
        j                  d      }t        j                  ||	      }t        | |||f|      S |dk(  r/| j	                  t
        j                  d      }t        | ||||      S d }| j                  ||||      S )Nr   c                 N    t        j                  |       j                  ddd      S )NrF   r  )rg  rM  r.  rN  s    rB   rO  z3_np_dstack.<locals>.codegen.<locals>.np_vstack_impl  s     yy(00Ar::rD   rF   r   rX  c                 0    t        j                  | d      S )NrX  rD  rE  rN  s    rB   rO  z3_np_dstack.<locals>.codegen.<locals>.np_vstack_impl  rQ  rD   )r   r   ro   r  r   r   r   rI  r   r$   r2  r  )r|   r<   rZ   r   rB  r#  ro   rO  r   stack_retty	stack_sig	stack_retr)  s                rB   rS  z_np_dstack.<locals>.codegen  s:   Qx}}19; ++G^S$OOQY''

A6D**%**q.*9K((@sxx@I('9d)-/I ''

A6D))%=Jwi\4PPQY''

A6D#GWc4FF6 ++G^S$OOrD   rB  rC  s        rB   
_np_dstackr]    s.    
	;Q
7C
c(C PD <rD   c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S r:  )r]  r.  s    rB   r   zimpl_np_dstack.<locals>.impl  rG  rD   r  r/  s     rB   impl_np_dstackr`    rI  rD   fillc                     d }|S )Nc                     || d d  y r:  rn  )r   r   s     rB   	fill_implzarr_fill.<locals>.fill_impl  s    ArD   rn  )r   r   rd  s      rB   arr_fillre    s     rD   dotc                     d }|S )Nc                 .    t        j                  | |      S r:  )rg  rf  )r   others     rB   dot_implzarray_dot.<locals>.dot_impl  s    vvc5!!rD   rn  )r   ri  rj  s      rB   	array_dotrk    s    " OrD   c                 R    t        |       st        j                  d| z        d }|S )NzCannot np.fliplr on %s typec                 z    t        j                  |       }|j                  dk  rt        d      |d d d d ddf   S )NrX  r  r  .rg  rh  ro   r   rz  rG  s     rB   r   znp_flip_lr.<locals>.impl  s=    JJqM 66A:455TrT3rD   r  rz  r   s     rB   
np_flip_lrrq    s/     A  !>!BCC  KrD   c                 R    t        |       st        j                  d| z        d }|S )NzCannot np.flipud on %s typec                 t    t        j                  |       }|j                  dk  rt        d      |d d ddf   S )NrF   zInput must be >= 1-d.r  .rn  ro  s     rB   r   znp_flip_ud.<locals>.impl  s:    JJqM 66A:4552s|rD   r  rp  s     rB   
np_flip_udrt    s/     A  !>!BCC KrD   c                     t        |t        j                        st        j                  |      t        |j                        t        j                  t        j                         |      }fd}||fS )zY Creates a tuple of slices for np.flip indexing like
    `(slice(None, None, -1),) * sz` r  c                     d }t         j                  g}t        j                  g| }| j	                  t         j                        }| j                        } |      |g}	| j                  ||||	      }
|
S )Nc           
      Z    |}t        |       D ]  }t        ||t        d d d            } |S )Nr  )r7   r.   r+  )lengthempty_tupler   rl   s       rB   r   z6_build_flip_slice_tuple.<locals>.codegen.<locals>.impl"  s1    C6]#CE$b,AB #JrD   )r   r   r   r$   r   get_constant_undefr  )r|   r<   r$   r   r   inner_argtypes	inner_sigll_idx_typery  
inner_argsr   r   
tuple_types              rB   rS  z(_build_flip_slice_tuple.<locals>.codegen!  s{    	  **j1$$ZA.A	,,UZZ800<!$'5
&&wiL
rD   )	r   r   rs  r	   r]  r   r   rp  slice3_type)r  szrZ   rS  r   r  s       @@rB   _build_flip_slice_tupler    sf     b%../((,,r De&7&7tDJ
R.C" <rD   c                 p    t        | t        j                        st        j                  d| z        d }|S )NzCannot np.flip on %s typec                 6    t        | j                        }| |   S r:  )r  ro   )rz  sls     rB   r   znp_flip.<locals>.impl<  s    $QVV,urD   )r   r   r   r	   r   rp  s     rB   np_flipr  5  s5     a%  !<q!@AA KrD   c                    t        | t        j                  t        j                  t        j                  f      rdd}|S t        |t        j
                        rdd}|S t        |t        j                        r4t        |j                  j                  t        j
                        rdd}|S t        |t        j                        r#t        d |j                  D              rdd}|S y y )Nc                 X    t        j                  t        j                  |       ||      S rC  )rg  array_splitrh  r   indices_or_sectionsr   s      rB   r   znp_array_split.<locals>.implF  s$    >>

3# rD   c                     t        | j                  |   |      \  }}t        j                  t        j                  |dz   g|z  |g||z
  dz
  z  z               }t        j
                  | ||      S )NrF   rD  )divmodrd   rg  cumsumr   r  )r   r  r   r  rz  r   s         rB   r   znp_array_split.<locals>.implP  sp    CIIdO-@AFAsiiQ#*S01456! G >>#wT::rD   c                 "   t        | j                        }t        dd| j                  |      }g }d}|D ]/  }t        ||t	        ||            }|j                  | |          |}1 |j                  | t        ||t	        d                       |S Nznp.splitr   r   )r/   ro   r   r.   r+  rh   r   r  r   	slice_tupr   prevr  r   s           rB   r   znp_array_split.<locals>.impla  s    .sxx8I!*fchhEDCD*#ItU45EF

3s8$ + JJs=D%T:JKLMJrD   c              3   P   K   | ]  }t        |t        j                           y wr:  r   r   r   )r<  r	  s     rB   r>  z!np_array_split.<locals>.<genexpr>q  s     P6O
1emm,6Or?  c                 4   t        | j                        }t        dd| j                  |      }g }d}t        |      D ]/  }t	        ||t        ||            }|j                  | |          |}1 |j                  | t	        ||t        d                       |S r  )r/   ro   r   r   r.   r+  rh   r  s           rB   r   znp_array_split.<locals>.impls  s    .sxx8I!*fchhEDCD%&9:#ItU45EF

3s8$ ; JJs=D%T:JKLMJrD   r  )r   r   rp  ListTyper  r   IterableTypeiterator_typer  rq  rr  r   r  r   r   s       rB   np_array_splitr  C  s    #

CD	 %u}}5	;  	&(:(:;--88MM


	  	&4P6I6O6OPP
	  Q 	5rD   c                     t        | t        j                  t        j                  t        j                  f      rdd}|S t        |t        j
                        rdd}|S t        | ||      S )Nc                 X    t        j                  t        j                  |       ||      S rC  )rg  splitrh  r  s      rB   r   znp_split.<locals>.impl  s    88BJJsO-@tLLrD   c                     t        | j                  |   |      \  }}|dk7  rt        d      t        j                  | ||      S )Nr   z0array split does not result in an equal divisionrD  )r  rd   r   rg  r  )r   r  r   r  rz  s        rB   r   znp_split.<locals>.impl  sM    CIIdO-@AFAsax F  >>(t rD   rD  r  )r   r   rp  r  r  r   r  r  s       rB   np_splitr    s[     #

CD	M %u}}5	  c#6TBBrD   c                 ,   t        | t        j                        sd}t        j                  |      t        |t        j
                  t        j                  t        j                  t        j                  f      sd}t        j                  |      d }|S )N#The argument "ary" must be an array:The argument "indices_or_sections" must be int or 1d-arrayc                 f    | j                   dk  rt        d      t        j                  | |d      S )NrX  z3vsplit only works on arrays of 2 or more dimensionsr   rD  ro   r   rg  r  r   r  s     rB   r   znumpy_vsplit.<locals>.impl  s5    88a< ? A Axx0q99rD   r   r   r   r	   r   r   r  rp  r   r  r   r   s       rB   numpy_vsplitr    s    c5;;'3  %%)EMM5;;,1JJ,H IK  %%: KrD   c                 ,   t        | t        j                        sd}t        j                  |      t        |t        j
                  t        j                  t        j                  t        j                  f      sd}t        j                  |      d }|S )Nr  r  c                     | j                   dk(  rt        d      | j                   dkD  rt        j                  | |d      S t        j                  | |d      S )Nr   z3hsplit only works on arrays of 1 or more dimensionsrF   rD  r  r  s     rB   r   znumpy_hsplit.<locals>.impl  sT    88q= ? A A88a<88C!41==xx0q99rD   r  r  s       rB   numpy_hsplitr    ss    c5;;'3  %%)EMM5;;,1JJ,H IK  %%: KrD   c                 ,   t        | t        j                        sd}t        j                  |      t        |t        j
                  t        j                  t        j                  t        j                  f      sd}t        j                  |      d }|S )Nr  r  c                 f    | j                   dk  rt        d      t        j                  | |d      S )Nr  z3dsplit only works on arrays of 3 or more dimensionsrX  rD  r  r  s     rB   r   znumpy_dsplit.<locals>.impl  s3    88a< * + +xx0q99rD   r  r  s       rB   numpy_dsplitr    r  rD   c                     | |k  S )z7
    Trivial comparison function between two keys.
    rn  r  s     rB   
default_ltr    s     q5LrD   c                    | |j                   |f}	 t        |   S # t        $ r` | dk(  r%t        j                  ||d      }|j
                  }n(| dk(  r#t        j                  ||      }|j                  }t        |<   |cY S w xY w)z6
    Get a sort implementation of the given kind.
    r+   T)lt
is_argsortis_np_arrayr,   )r  r  )	rp   _sortsKeyErrorr+   make_jit_quicksortrun_quicksortr,   make_jit_mergesortrun_mergesort)rN  lt_implr  keyr  funcs         rB   get_sort_funcr    s       *
,Cc{ ;//% "D %%D[ //%'D %%Dss    A&BBc                     t        | t        j                        rt        S t        | t        j                        rt
        S t        S r:  )r   r   r  r   r  r   r  r  s    rB   lt_implementationr     s0    %%	E5==	)rD   z
array.sortc                     |j                   d   }t        dt        |j                              fd}| j	                  ||||      S )Nr   r+   )rN  r  c                      |        y r:  rn  r   	sort_funcs    rB   array_sort_implz#array_sort.<locals>.array_sort_impl  s
    #rD   )r   r  r  rz   r  )r|   r<   rZ   r   r  r  r  s         @rB   
array_sortr  	  sG    hhqkG;&7&FHI ##G_c4HHrD   c                 L    t        |       st        j                  d      d }|S )NzArgument "a" must be array-likec                 F    | j                         }|j                          |S r:  )rI  r  )r  r   s     rB   np_sort_implz"impl_np_sort.<locals>.np_sort_impl  s    ffh

rD   r  )r  r  s     rB   impl_np_sortr    s/    A   "1 2 	2 rD   zarray.argsortc                    	 |j                   \  }}t        |j                  t        |j                        d      		fd}|j                  |j                   d d       }|d d }| j                  ||||      S )NT)rN  r  r  c                      |       S r:  rn  r  s    rB   array_argsort_implz)array_argsort.<locals>.array_argsort_impl-  s    ~rD   rF   r  )r   r  r   r  rz   replacer  )
r|   r<   rZ   r   r  rN  r  innersig	innerargsr  s
            @rB   array_argsortr  $  s|     HHMGT4#5#5&7&F)-/I {{!{-HRaI##G-?$,i9 9rD   c                 Z    |j                   |j                   k7  s|j                  dk(  sJ |S )NrG  )r  r  )r|   r<   r  r  r   s        rB   array_to_arrayr  9  s*     >>T\\)T[[C-???JrD   c                 z    d }t        ||      }| j                  ||||g      }t        | ||j                  |      S )Nc                 $    | j                  d      S r   )r  rR  s    rB   r   zarray0d_to_scalar.<locals>.implH  s    vvayrD   )r$   r  r"   r   r|   r<   r  r  r   r   rZ   r   s           rB   array0d_to_scalarr  @  sB     D&
!C

"
"7D#u
=CgwEErD   c                 z    d }t        ||      }| j                  ||||g      }t        | ||j                  |      S )Nc                     t        | d         S r  )r`  rR  s    rB   r   z array_to_unichrseq.<locals>.implS  s    1R5zrD   )r$   r  r    r   r  s           rB   array_to_unichrseqr  Q  sB     D&
!C

"
"7D#u
=CWgsDDrD   c                     t         )zR
    An intrinsic returning a derived array with the given shape and strides.
    r   )r  rd   r   s      rB   reshape_uncheckedr  ^  s
     rD   c                     d fd}|S )Nc                 ^    t        | t        j                        xr t        d | D              S )Nc              3   P   K   | ]  }t        |t        j                           y wr:  r  r  s     rB   r>  z>type_reshape_unchecked.<locals>.check_shape.<locals>.<genexpr>i  s     @%QJq%--0%r?  )r   r   rF  rr  rd   s    rB   r  z+type_reshape_unchecked.<locals>.check_shapeg  s*    5%//2 A@%@@	BrD   c                     t        | t        j                        sy  |      r |      sy t        |      t        |      k7  ry | j	                  t        |      d      S )NrG  rH  )r   r   r   r   rI  )r  rd   r   r  s      rB   typerz%type_reshape_unchecked.<locals>.typerk  sP    !U[[)5!W)=u:W%vv3u:cv22rD   rn  )r|   r  r  s     @rB   type_reshape_uncheckedr  e  s    B3 LrD   c                    |j                   d   }|j                  } t        |      | ||d         } t        |      | |      }t        j                  ||d         }t        j                  ||d         }	t        ||j                  ||	|j                  |j                         |j                         }
t        | |||
      S )Nr   rF   rX  r  )r   r   rw   r
   r   r   r   r   r   r   r    )r|   r<   rZ   r   r   r#  r   r   rd   r   r   s              rB   impl_shape_uncheckedr  w  s    HHQKEOOE
*U
GWd1g
6C
*U
GW
-C  $q'2E""7DG4G3"LL;; --/CWguc::rD   c                     |d t         j                  fv rt        d        nt        d        |d t         j                  fv rt        d      t        d        dfd	}|S )Nc                     | j                   S r:  r  rA  rd   s     rB   rf  zas_strided.<locals>.get_shape  s    77NrD   c                     |S r:  rn  r  s     rB   rf  zas_strided.<locals>.get_shape  s    LrD   z*as_strided() strides argument is mandatoryc                     |S r:  rn  )rA  r   s     rB   get_strideszas_strided.<locals>.get_strides  s    NrD   c                 >    t        |  | |       | |            } | S r:  )r  )rA  rd   r   rf  r  s      rB   as_strided_implz#as_strided.<locals>.as_strided_impl  s$    a1e!4k!W6MNrD   r  )r   r  r&   rQ   )rA  rd   r   r  rf  r  s       @@rB   
as_stridedr    sz    uzz""		 
	 
	 
	 4$$
 ""NOO		 
	 rD   c                    t        |t        j                        rOt        t	        | j
                  dz               t        t	        | j
                  dz               t        d        nt        |t        j                        rt        |j                  t        j                        rat        t	        | j
                  t        |      z               t        t	        | j
                  t        |      z               t        d        nt        j                  d      t        |      rt        d        nt        |t        j                        rt        d        n`t        |t        j                        r1t        |j                  t        j                        rt        d        nt        j                  d      d
fd		}|S )NrF   c                     | fS r:  rn  window_shapes    rB   get_window_shapez-sliding_window_view.<locals>.get_window_shape  s
     ?"rD   c                     | S r:  rn  r  s    rB   r  z-sliding_window_view.<locals>.get_window_shape  s    rD   z4window_shape must be an integer or tuple of integersc                 *    t        t        |            S r:  )r   r7   r  r   ro   s      rB   get_axisz%sliding_window_view.<locals>.get_axis  s    d$$rD   c                      t        dd||      gS Nsliding_window_viewr   r   r  s      rB   r  z%sliding_window_view.<locals>.get_axis  s     4fdDI rD   c           	      D    |D cg c]  }t        dd||       c}S c c}w r  r  )r  r   ro   r  s       rB   r  z%sliding_window_view.<locals>.get_axis  s5     "#! ##8&$J!# # #s   z2axis must be None, an integer or tuple of integersc                 P    |      } 
||| j                         }t        |      t        |      k7  rt        d      }}t        | j                         D ]6  }t	        ||| j
                  |         }t	        ||| j                  |         }8 | j                   }t        ||      D ]l  \  }}|dk  rt        d      ||   |k  rt        d      ||   |z
  dz   }t	        |||      }t	        |||      }t	        ||| j                  |         }|dz  }n t        | ||      }	|	S )Nz2Must provide matching length window_shape and axisr   z-`window_shape` cannot contain negative valuesz4window_shape cannot be larger than input array shaperF   )	ro   r   r   r7   r.   rd   r   r   r  )rA  r  r   	out_shapeout_stridesrl   r(  rr  trimmedr  r  r  shape_bufferstride_buffers             rB   sliding_window_view_implz5sliding_window_view.<locals>.sliding_window_view_impl  sD   '5dAFF3|D	)D 
 !	#qvvA%iAGGAJ?I'Q		!EK  FF4.GBQw C  }s" J   mc)A-G%iW=I%iC8I'Q		"FKFA /$ !I{;rD   r:  )r   r   r   r   r7   ro   r&   rp  rz   r   r	   r   r   )rA  r  r   r  r  r  r  r  s       @@@@rB   r  r    sx    ,.U166A:./eAFFQJ/0		# 
	# \5>>
2|))5==9U166C,=#=>?eAFFS->$>?@		  
	    B
 	

 4		% 
	% 
D%--	(		 
	
 T5>>
*tzz5==1		# 
	#
   @
 	
% %N $#rD   c                 B    t        | t        j                        rd }|S y )Nc                     | j                   dk(  ry| j                   dk(  rt        | j                  d            S d}t        |      )Nr   FrF   z[The truth value of an array with more than one element is ambiguous. Use a.any() or a.all())r   rG  r  r   )r   r   s     rB   r   zol_bool.<locals>.impl  s?    xx1}QCHHQK((> o%rD   r;  rH  s     rB   ol_boolr  	  s!    #u{{#	&  $rD   c                    t        |t        t        j                  f      st	        j
                  d      t        |t        t        j                  f      st	        j
                  d      t        | t        j                        st	        j
                  d      | j                  t        t                    fd}|S )Nz.The second argument "axis1" must be an integerz-The third argument "axis2" must be an integerz'The first argument "a" must be an arrayc                     t        dd|      }t        dd|      }|dk  r|z  }|dk  r|z  }t        ||      }t        |||      }t        j                  | |      S )Nznp.swapaxesaxis1axis2r   )r   r.   rg  r  )r  r  r  
axes_tuple	axes_listro   s       rB   r   znumpy_swapaxes.<locals>.impl'  sr    }gtUC}gtUC 19TME19TME"9eU;
":ue<
||Az**rD   )
r   r   r   r   r	   r   r   ro   r   r7   )r  r  r  r   r  ro   s       @@rB   numpy_swapaxesr    s    ec5==12   "+ , 	,ec5==12   "+ , 	,a%  !JKK 66DeDk"I+ KrD   c                 (   t        dd| j                  |      }t        | j                        }d||<   t	        t        ||j                              D ]7  \  }\  }}	|dk(  r|	}
n|	dk(  r|}
n||	k7  rt        d      |}
t        |||
      }9 t        ||| j                  |         }t        j                  | |      } t        j                  ||      }|}t        |      dkD  r3t        t        |            D ]  }t        ||| j                  |         } |}t        |      dkD  r9t        t        |            D ]"  }t        ||| j                  |dz   |z            }$ |j                  |   }t        j                  ||fz   |z   | j                        }t        d d d       f}t        j                  |      D ]X  }t        j                  |      D ]>  }| ||z   |z      }|||z   |z      }|||z   |z      }t        |      D ]  }|||      ||<    @ Z |S )Nznp.take_along_axisr   rF   z*`arr` and `indices` dimensions don't matchr   )r   ro   r   rd   r  r   r   r.   rg  rm  r   r7   r  rz   r+  r[  )r   r   r   Ni_origNk_origindices_broadcast_shape	arr_shaperl   d1d2new_valarr_broadcast_shapeNiNkJr   np_s_iikka_1d
indices_1dout_1dr  s                          rB   _take_along_axis_implr"  8  s    .$GD SYYIIdO Y!>?8B7G1WGRx @  G"/#Q#
 @ (syy //#2
3Coog'>?G	B
7|as2wAr1ciil3B  	B
7|as2wAr1ciiq1&=>B   	dA
((29r>399
-C4t$&Ejjn**R.BrEzB'D eb1Jeb)F1X A/q	 	 !  JrD   c                    t        | t        j                        st        j                  d      t        |t        j                        st        j                  d      t        |j
                  t        j                        st        j                  d      t        |      rd}n| j                  }||j                  k7  rt        j                  d      t        t        |j                              t        |      rfd}|S t        |d       t        |t        j                        st        j                  d      |j                  }|d	k  r| j                  |z   }|d	k  s|| j                  k\  rt        j                  d
      t        t        |            t        t        |dz   | j                              fd}|S )Nz)The first argument "arr" must be an arrayz.The second argument "indices" must be an arrayz'The indices array must contain integersrF   z;`indices` and `arr` must have the same number of dimensionsc                 @    t        | j                         |ddd      S )Nr   rn  )r"  rL  )r   r   r   r  s      rB   take_along_axis_implz1arr_take_along_axis.<locals>.take_along_axis_impl  s%    (B)@B BrD   r   zaxis must be a literal valuer   zaxis is out of boundsc                 $    t        | ||      S r:  )r"  )r   r   r   r  r  r  s      rB   r%  z1arr_take_along_axis.<locals>.take_along_axis_impl  s    (gtR)@B BrD   )r   r   r   r	   r   rz   r   r   ro   r   r7   r   rs  r  r   )r   r   r   arr_ndimr%  r  r  r  s        @@@rB   arr_take_along_axisr(  t  su   c5;;'  !LMMgu{{+  <> 	>gmmU]]3  !JKK4887<<  I
 	
 $E',,$784	B(  ! 	v&$ 4 45(()GHH!!!888d?D!8tsxx'(()@AA5;5388,-	B  rD   c                    t        | t        j                        rut        | t        j                        rd	d}|S t        | t        j                        rd	d}|S t        | t        j
                        rd	d}|S t        j                  d      t        |       rt        | j                  t        j                        rd	d}|S t        | j                  t        j                        rd	d}|S t        | j                  t        j
                        rd	d}|S t        j                  d      t        j                  d      )
Nc                     | S r:  rn  rA  rI  nans      rB   r   znan_to_num_impl.<locals>.impl      rD   c                 (   t        j                  |       r|S t        j                  |       r(t        j                  t	        |             j
                  S t        j                  |       r(t        j                  t	        |             j                  S | S r:  )rg  isnanisneginffinfor8   r\  isposinfr  r+  s      rB   r   znan_to_num_impl.<locals>.impl  s_    88A;J[[^88DG,000[[^88DG,000rD   c                     t        j                  | j                  |      }t        j                  | j                  |      }t	        ||      S )N)r,  )rg  
nan_to_numr  r  complex)rA  rI  r,  ry  r  s        rB   r   znan_to_num_impl.<locals>.impl  s6    MM!&&c2MM!&&c2q!}$rD   z4Only Integer, Float, and Complex values are acceptedc                     | S r:  rn  r+  s      rB   r   znan_to_num_impl.<locals>.impl  r-  rD   c                    t        j                  | j                        j                  }t        j                  | j                        j                  }t        j
                  |       }|rt        j                  |      n|}|j                  }t        |j                        D ]\  }t        j                  ||         r|||<   !t        j                  ||         r|||<   ?t        j                  ||         sX|||<   ^ |S r:  )rg  r1  rz   r\  r  rh  rI  r  r7   r   r/  r0  r2  )	rA  rI  r,  min_infmax_infx_outputoutput_flatrl   s	            rB   r   znan_to_num_impl.<locals>.impl  s    ((177+//((177+//ZZ](,"$kkv{{+AxxA/),A[^4)0A[^4)0A , rD   c                     t        j                  |       }|rt        j                  |      n|}t        j                  |j                  d|       t        j                  |j
                  d|       |S )NF)rI  r,  )rg  rh  rI  r4  r  r  )rA  rI  r,  r:  r;  s        rB   r   znan_to_num_impl.<locals>.impl  sM    ZZ](,"fkk3?fkk3?rD   z4The first argument must be a scalar or an array-likeTg        )
r   r   r  r   r  r  r	   r   r   rz   )rA  rI  r,  r   s       rB   nan_to_num_implr?    s   !U\\"a'v Kq 5;;'n K_ 5==)%\ KS $$F  
!	aggu}}-D KA -> K / K $$F     ". / 	/rD   r:  r  r  r  r  )Fr  r>  (  rm  r2  r'  r  llvmliter   llvmlite.irr   numpyrg  numbar   r   
numba.corer   r   r	   r
   r   numba.np.numpy_supportr   r   r   r   r   r   r   r   r   r   r   r   r   numba.core.imputilsr   r   r   r   r   r   r   r    r!   r"   r#   numba.core.typingr$   numba.core.typesr%   numba.core.extendingr&   r'   r(   r)   r*   
numba.miscr+   r,   numba.cpythonr-   numba.cpython.unsafe.tupler.   r/   r0   numba.core.typing.npydeclr1   r  r2   r  r3   r4   r5   rC   rH   rw   r~   r   r   r   r   r   r   r   r   r   r   r   r  ArrayIteratorBORROWEDr  r.  r   r4  r  r   r  r7  rF  rD  r/  AnyrK  r   rP  r   rW  r[  r  r]  rp  r  r  r  r  r  rA  r  r  r  r
  r  r0  r9  rE  rM  rV  r[  re  rj  rm  rv  r|  broadcast_shapesr  rZ  r  rH  r  r  r  r  VarArgr  r  r  r  r  r  	geomspacer  rot90r	  r  r!  r)  r+  r.  r0  resizer=  rh   rF  rO  r4  rT  rW  re  rj  r  r  r  r  rd   r  r   r  uniquer  r  r  r  r  r  r  r  r  r  r  
MemoryViewr  r  r  r  r  r   r  r  r  r  r  r  r  r  rn  r  r$  r(  r&  r*  r,  r3  r7  r1  rI  rM  DTypeNumberClassrR  r^  ra  rT  rh  rm  rq  rs  ru  r}  r  r  r  Bytesr  is_r  r  r  r  r  r  r  r"  r  rI  rE  rK  rN  rP  rR  r  rV  rT  rX  r[  r\  r^  rZ  r`  r  rb  NumpyNdIterTyperd  eqrh  r  r  rp  r  r  r  r5  r  r  r  r  r  r  rY  r  r  r  r5  r  r  r  r  r  r  r  rw  r  r  r  r  r  r  r  eyer  diagr  r   r  diagflatr
  r  r  r$  r  r8  r  r@  rD  rF  rH  rI  rL  rZ  r^  ra  rg  rj  rl  ro  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  
atleast_1dr  
atleast_2dr  
atleast_3dr  r  r  r  r  r  r7  r!  r#  r+  column_stackr0  r2  r6  stackr9  r<  rD  rM  rH  rR  vstackrU  	row_stackr]  dstackr`  re  rk  r  rq  r  rt  r  flipr  r  r  r  r  vsplitr  hsplitr  dsplitr  r  r  r  r  r  r  r  argsortr  r  UnicodeCharSeqr  r  r  NPTimedelta
NPDatetimer  r  r  type_callabler  r  libstride_tricksr  r  rG  r  r  r  r"  take_along_axisr(  r4  r?  rn  rD   rB   <module>ru     s  
        * @ @; ; ; P O* * * * ( *A A + ! L 5E E#69x(-M	

  BJH& 
 
. , y%,,' (.;* z5../w - ! 0-6  $A4H ;* xu}}=xu?E @ >E xu?E @E0 xuyy%))D%6 E%6P sELL!F "F |U[[)8 *8 6?EKK;) <)(/"f /"d/-G /-dW >:-' :-zN-' N-bB-7 B-JL6 L^(GV xu{{;; <;&'TH
:$z"J!. 4  ,  " 5 5>- 
"//'& '&T 3 3  
"

% %P 
"

6 6rF%X&  %++.; /;
  %++u?3E @3El  %++|u||EII/FGF HF
 
",,  u{{C 9 !9& 
"++  
",,C CL 
"(( 4!H;< U__==E >=E@ \U\\%))-DE> F>
 
"**  
"))+ +\ 
")) 2 }ekk* +, rxx%G &G , - 
 
   
"''v vr f% &{| 
"((  
"''  
"))  
")))1 )1X  " 5;;1 2  	 

9-( .(V |U[[%//:$E ;$ET u{{G$: %:
 u{{G$u): * %: u{{I&u+: , ': u{{F#u(: ) $:
 u{{F#: $: u{{J'u,: - (: u{{H%u*: + &: u.: /:
 u0: 1:
 u0: 1:
 u,: -: u{{H%	9 &	9 u  &): *: Eu~~.Eu}}-; . /;4 u{{G$8 %8 u.u0	: 1 /	: u0
: 1
:  u{{F#Q $Q u{{F#Q $Q 4Mn f%k* + &%
 #ekk6 ": . "ekk6 ": . !2!2EII>( ?(. u{{#4; $4;n e.A.ABO CO u||$$= %$=N u||$D %D: u/B/BCA DA u/C/CDE EE u/B/BEIIN	% O	% u/C/CUYYO
% P
%" ; ; 3 3 9 9 x||U[[%++6
G 7
G  EKK, -9> IM6:#D '+OEP
>BTn u{{F#P $P z5../w E ! 0E x!4!4emmDE EE x!4!4emmyy%% sE''( ) r~~u{{+E ,E" z5556w C ! 7C xemm45rzz<5<<67
E 8 6
E x)rzz5??+E , *E* z5112w 7 ! 37 ryy%))$> %>& z5001w 7 ! 27 x{{EKK5F 6FL^ ekk;/ 0* 
 
-`K#&   
"((" & &*   
"-- 0   l+ , 
"(("   
"--  
",,
 
 
"''   
",,
 
 
"''  
"++ 	 %& ' BFF1E  2 
"''# #L 
"** 6 
"++ 4 
"''f%+ & +\4 
"))@ @F 
"++$ $N"PJ   |U[[)4 *4 
"'' ><B ? ? 
"


  
 
"

  ~u{{EOO<~u{{E,?,?@P A =P: ( (V 
"--%*  6 
&  
& !H1Dh"<&'R&#R)  2 
"(( &?:@:8    
".. %2. 
"--# #
 
"--& &
 
"--) )
:z/FdVFr,"    
"..  " "J 
"//    
"((   4 
"))   4 
"))  FHR\\>* & &R 
"))  5;;/ 0 5;;. / 
"))   
"))    : 
"''
 
 
"..; ;| 
"((C C4 
")) & 
")) * 
")) , 
0 |U[[)
I *
I 
"''	 	 U-@-@Arzz5;;(;(;<9 = B9& EKK% & EKK--.EKK%EKK'EKK'EKK'EKK**+EKK))*F + , ( ( ( & /F EKK--.E /E *+ ,"  %++uP; Q;* BFF((334 58 BFF((<<=[$ >[$| 
$  
"++ > 8 8v 
"

(  ( V 
"--? ?rD   