
    S3j7             
       1   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	Z
ddlmZmZ ddlmZmZmZmZmZ 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l0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z? ddl@mAZAmBZB ddl2mCZC ddlDmEZFmGZHmIZImJZJmKZK d ZLd ZMd ZNd ZOd ZPd ZQd ZRd ZSd ZT	 dYdZUd ZVd ZW e4eW      d        ZXd  ZY e4eY      d!        ZZ e#d"ej                        d#        Z\d$ Z] e#d%ej                         e)e-j                        d&               Z`	 dYd'Zad( Zbd) Zc e#ej                  ej                  ej                         e#ej                  ej                  ej                         e#ej                  ej                  ej                        d*                      Zh e#ej                  ej                  ej                        d+        Zj e#ej                  ej                  ej                  ej                        d,        Zm e#enej                        d-        Zo e#d.ej                        d/        Zqe!d0k  r$ e#d1ej                  ej                        d2        Zr G d3 d4es      Zt G d5 d6et      Zu G d7 d8et      Zv G d9 d:et      Zw G d; d<et      Zx G d= d>et      Zy G d? d@es      ZzdA Z{ e#ej                  ej                  ej                        dB        Z|dC Z}dD Z~dE ZdF ZdG ZdH ZdI ZdJ Ze6dK        Ze6dL        Ze3dM        ZdN Z e4e
j                        dO        Ze3dP        Z e4e
j                        dQ        Z e4e
j                        dR        ZdS Z e4edTU      dV        Z e4edWU      dX        ZdY ZdZ Z e#d[ej                        d\        Zd] Z e#d[ej                  ej                        d^        Z e#d[ej                   ej0                  ej                              d_        Z e4e
j4                        dYd`       Z e$ej                  da      db        Z e4e
j:                        dZdc       Z e4e
j>                        dZdd       Z e4e
jB                        d[de       Zdf Zdg Z e#dhej                  ej                        di        Z e#dhej                   ej0                  ej                              dj        Ze!dkk  r e4e
jN                        dl        Zn e4e
jN                        dm        Z e4e
jR                        dn        Z e4e
jV                        dYdo       Z e#dpej                        dq        Z e#e
j\                  ej                        dr        Z e#dsej                        dt        Ze3du        Ze3dv        Z e4e
jf                        dYdw       Z e5ej                  dx      d\dy       Zdz Z e4e
jn                        d{        Z e4e
jr                        d|        Z e4e
jv                        d}        Z e4e
jz                        d~        Ze3d        Z ejj                  ej                  d      d        Ze6d        Zd Z e4edTU      d        Z e#dej                  ej                        d        Z e$ej                  d      d        Z e$ej                  d       e$ej                  d      d               Z e$ej                  d       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       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        Z e$ej                  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 e5ej                  d       e5e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jb                        d        Z e%ej                        d        Z e&ej                        d        Z e#dej                  ejb                        d        Z e#dej                  ej                        d        Z e#dej                  ejb                  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 e7ej                  d      d        ZdÄ ZdĄ Z	 	 d\dńZ	 dYdƄ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#enej                        dτ        Z e#e
j                  ej                        dЄ        Z e#d%ej
                         e)e-j                        dф               Z e#e ej0                  ej                               e#e
j                   ej0                  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 eCej                  ddWU      dڄ        Zdۄ Ze6d܄        Zd݄ Zdބ Zd߄ Zd Ze6d        Z e4e
j6                        efd       Ze6d        Z e4e
j>                        dYd       Z e6d        Z! e5ej                  d      d        Z" e4e
jF                        efd       Z$ e4e
jJ                        dYd       Z& e4e
jN                        dYd       Z( e4e
jR                        dYd       Z* e4e
jV                        dYd       Z, e4e
jZ                        dYd       Z. e4e
j^                        dYd       Z0d Z1 ejh                  e1      d        Z2 ejh                  e
jf                        ddefd       Z4 e4e
jj                        d]d       Z6 e4e
jn                        d        Z8 e4e
jr                        d]d       Z:d Z; e4e
jx                         e5ej                  d      dYd              Z=d Z> e4e
j~                        d\d       Z@ e4e
j                        dZd       ZBd ZCe6d        ZD e#dej                        d        ZE e4e
j                        d        ZGd  ZHe6d        ZI e4e
j                        d        ZK e4e
j                        d        ZM e#dej                  ej                         e#dej                  ejb                        d               ZNe6d        ZO e5ej                  d      d        ZPe6d	        ZQ e4e
j                        ed
dfd       ZS e4e      dYd       ZT e4e      dYd       ZUd ZVd ZWd ZXd ZYd ZZd Z[d Z\d Z]e6d        Z^ e4e
j                        dYd       Z`d Zad Zbd Zcd Zde6d        Ze e4e
j                        d        Zfd Zgd Zh e4e
j                        d         Zj e4e
j                        d!        Zl e4e
j                        d"        Znd# Zod$ Zpd% Zqd& Zre6d'        Zs e4e
j                        d]d(       Zud) Zve6d*        Zw e4e
j                        d+        Zyd, Zze6d-        Z{ e4e
j                        d]d.       Z}d/ Z~e6d0        Z e4e
j                         d1        Ze6d2        Z e4e
j                        d3        Ze!d0k\  r  e4e
j
                        e       e6d4        Z e4e
j                        d5        Z ejj                  ej                  d6      d7        Z ejj                  ej                  d8      d9        Z e4e
j                        d:        Z e4e
j                        d;        Ze6d<        Z e4e
j                         d=        Z e4e
j$                        d]d>       Z e4e
j(                        d]d?       Z e4e
j,                        d@        Z e4e
j0                        dA        Z e4e
j4                        dB        Zi ZdC Zd^dDZdE Z e#dFej                        dG        Z e4e
jB                        dH        Z e#dIej                  ejb                         e#e
jF                  ej                  ejb                        dJ               Z e'ej                  ej                        dK        Z e'ej                  ejL                         e'ej                  ejN                         e'ej                  ej                         e'ej                  ejP                         e'ej                  ejR                         e'ej                  ejT                         e'ej                  ejV                        dL                                                  Z e'ej                  ejL                        dM        ZdN Z ej^                  e      dO        Z e#eej                  ej                  ej                        dP        Z ejh                  e
jd                  jf                  jh                        d_dQ       Z ejh                  e
jd                  jf                  jj                        dYdR       Z e4e      dS        Z e4e
jp                        dT        Z e4e
jt                        dU        Ze3dV        Z e4e
jz                        dW        Z e4e
j~                        d`dX       Zy(a  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)_make_constant_bytes
bytes_type)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         >/DATA/.local/lib/python3.12/site-packages/numba/np/arrayobj.pyset_range_metadatarE   .   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)r:   widthrE   )r>   r?   rA   s      rD   mark_positiverJ   9   s.     1,-2Kwa5rF   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          rD   rU   z*make_array.<locals>.ArrayStruct._make_refsO   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)
rY   __getattr___get_ptr_by_namer9   r
   gep_inboundsr?   appendrJ   
pack_array)	rZ   r>   ptrdimsidimptrr?   basendims	          rD   rf   z%make_array.<locals>.ArrayStruct.shapec   s    
 mmGqy''g66 ''0CD4[ --gsAqA||F+D!gt,	 ! %%gt44rF   )__name__
__module____qualname__rU   propertyrf   __classcell__)rb   ra   rc   rp   rq   rd   s   @rD   ra   rM   M   s    	"( 
	5 
	5rF   ra   )as_arrayr
   create_struct_proxyrq   )rc   ra   rp   rq   rd   s   `@@@@rD   
make_arrayry   A   sE     !))O&&7DD+5 +5d +5Z rF   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)contextrc   lltys      rD   get_itemsizer   }   s+       !1!12D!!$''rF   c                 `    |j                   rdnd}| j                  ||j                  ||      S )z3
    Load the item at the given array pointer.
    NrH   align)alignedunpack_valuer|   )r~   r>   arraytyrl   r   s        rD   	load_itemr      s6     OODE&+   - -rF   c                 b    |j                   rdnd}| j                  ||j                  |||      S )z4
    Store the item at the given array pointer.
    NrH   r   )r   
pack_valuer|   )r~   r>   r   valrl   r   s         rD   
store_itemr      s1     OODEgw}}c3eLLrF   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         rD   fix_integer_indexr      s]     ||ll7C

;d3 J ll7C<JrF   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   Arrayrq   r|   Integerry   r   data)r~   r>   r   r   idxaryidxvals         rD   normalize_indexr      sv     %%%**/%++u}}555"E"7GS97GUFKK@{{F""czrF   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         rD   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.
    rH   CzThe datamodel for type z is missing fields  .Nmeminfo)rf   stridesr   itemsizer   parentnswflagsnitemszmissing {0}) rQ   rY   
_datamodelr   r   float64rV   set_fields_fe_typer   
ValueErrorr   get_value_typeget_typer   r   tuplelistr
   rk   intdictget_constantunpack_tupler:   countmulkeysformatitemssetattr)arrayr   rf   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                           rD   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!  LrF   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.
    rH   r   r   N)rQ   rY   r   r   r   r
   r   rf   rq   r   r   r   r   )arytyr   r~   r>   r   r   r   s          rD   update_array_infor     s    
 nnGnnG !!%**a0F))'5;;

KNVU5':  EL))%***6w*FHENrF   c                     t               )z/Constrain axis values to valid positive values.rS   	func_namearg_namerq   axiss       rD   normalize_axisr         

rF   c                     t        | t              st        j                  d      t        |t              st        j                  d      | j                   d|j                   dfd}|S )N func_name must be a str literal.arg_name must be a str literal.: Argument * out of bounds for dimensions of the arrayc                 F    |dk  r||z  }|dk  s||k\  rt              |S Nr   r   )r   r   rq   r   r   s       rD   implz&normalize_axis_overloads.<locals>.impl%  s/    !8DLD!8tt|S/!rF   )r   r%   r	   TypingErrorliteral_value)r   r   rq   r   r   r   s        @rD   normalize_axis_overloadsr     sr    i/  !CDDh.  !BCC ""
#;x/E/E.F G4 	4 
 KrF   c                     t               )zFNormalizes an axis argument into a tuple of non-negative integer axes.r   r   s       rD   normalize_axis_tupler   0  r   rF   c                    t        | t              st        j                  d      t        |t              st        j                  d      | j                   d|j                   d| j                   d|j                   dt        |t
        j                        rfd}|S t        |      dz  fd	}|S )
Nr   r   r   r   z: repeated axis in z	 argumentc                 H    |dk  r||z  }|dk  s||k\  rt              |fS r   r   )r   r   rq   r   invalid_axis_msgs       rD   r   z,normalize_axis_tuple_overloads.<locals>.implH  s3    axax44< !1227NrF   r   c                     	}t        |      D ]1  \  }}|dk  r||z  }|dk  s||k\  rt              t        |||      }3 t        t	        |            k7  rt        
      |S r   )	enumerater   r0   r   r   )r   r   rq   r   	norm_axisrn   axaxis_lenr   norm_axis_initrepeated_axis_msgs          rD   r   z,normalize_axis_tuple_overloads.<locals>.implT  sv    &I"426$JB6R4Z$%566))Q;	 ) 3y>"h. !233rF   )r   r%   r	   r   r   r   r   r   )	r   r   rq   r   r   r   r   r   r   s	        @@@@rD   normalize_axis_tuple_overloadsr   5  s    i/  !CDDh.  !BCC ""
#;x/E/E.F G4 	4  ""
##6!!
")	- 
 $&	4 K# t9	 KrF   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>   r\   r   r   r   iterobjzeroindexptrresouts              rD   getiter_arrayr  e  s    IWGU!!'3??;G

A.D(($7HGMGM 7GU3



C 7GS__c
BCJrF   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   rH   N)r
   r   rf   rq   r   r   pointer_addr   r   r   Buffer	make_viewr  r   )r~   r>   r   r   aryr   shapesr   offsetdataptrview_shapesview_stridesretarys                rD   _getitem_array_single_intr  }  s     !!'399EJJGF""7CKKuzzJG[[S)F!!'388V<G*K12;L+u||,7GUC"K?!! '5'::rF   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valuerH   r  <)r   rc   r   ry   r   r
   r   rf   r?   r  icmp_signed	set_validif_thenr  
yield_typeyield_increment_indexstore)r~   r>   r\   r   resultitertyiterr   r  r  r   r  is_validr  nindexs                  rD   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   rH   r  unexpected index type: F
wraparoundboundscheck)r   r   r   r
   r   rf   rq   r   r   r   r   ellipsisr9   rj   r   	SliceTyper   r-   guard_invalid_slice	fix_slicestartget_slice_length
fix_strider   r   do_boundscheckrS   get_item_pointer)r~   r>   r   r  r   r   r/  r  oner  r   output_indicesoutput_shapesoutput_stridesr   num_newaxesr   indexvalr   	n_missingrn   sliceshstr   r  s                             rD   basic_indexingrC    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   rf   r   r   r   r   )ry   r   r   r   r   )	r~   r>   r   r  r   r   r  r   r  s	            rD   r  r    sF    
 %Z$Wg6F6"LL;;**& MrF   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/  )rC  enable_boundscheckr   r   r  r  r  r   )r~   r>   r   r   r  r   r   r  r  r  r  s              rD   _getitem_array_genericrI    s     	w['#*#=#=	? 'G[, +u||,7GUC"K?!! '5'::rF   c           	         |j                   \  }}|\  }}t        |t        j                        s|j                  dk\  sJ  t        |      | ||      }t        | ||j                  |||f|f      }t        | ||j                  |      S )z9
    Basic indexing with an integer, slice, or None.
    rH   )	r   r   r   NoneTyperq   ry   rI  r   r    	r~   r>   r\   r   r   r   r  r   r	  s	            rD   getitem_arraynd_intprM    s     88LE5HC eU^^,zzQ
*U
GWc
2C
 '3??!&eXv?CWgsDDrF   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     rD   	<genexpr>z&getitem_array_tuple.<locals>.<genexpr>:  s     
=2:b%++&   $&)r   ry   r   r
   r   r   r   anyfancy_getitemrI  r   r    )r~   r>   r\   r   r   tuptyr  tupr   r   r	  s              rD   getitem_array_tuplerZ  +  s    
 88LE5HC
*U
GWc
2C++K""7Cs5zBG,Wg-8'CK 
=
==WgsD"Cg? 	? !'3??!&['CCWgsDDrF   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  rG  TN)r   r   r   	BaseTupler
   r   r   ry   r   rC  rH  boolrS   fancy_setslicer   r|   r   )r~   r>   r\   r   r   r   valtyr  r   r   r   r   r  r  r   use_fancy_indexings                   rD   setitem_arrayra  D  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   ry   rf   extract_valuer"   r   )	r~   r>   r\   r   r   r  arysttyshapearyr	  s	            rD   	array_lenrf  m  s\    xxHUFSG
'7C
(CyyH


!
,CgwEErF   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!=rH   Flikelyz>item(): can only convert an array of size 1 to a Python scalar)r   ry   r   r   r  r:   	call_convreturn_user_excr   r   r   )r~   r>   r\   r   r   r  r   r   s           rD   
array_itemrm  x  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)Nrh  rH   Fri  z/itemset(): can only write to an array of size 1)r   r|   ry   r   r   r  r:   rk  rl  r   r   r   get_dummy_value)
r~   r>   r\   r   r   r_  r  r   r   r   s
             rD   array_itemsetrr    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   rZ   s    rD   preparezIndexer.prepare  
    
 "!rF   c                     t         )z=
        Return this dimension's size as an integer.
        r   rv  s    rD   get_sizezIndexer.get_size  
     "!rF   c                     t         )z;
        Return this dimension's shape as a tuple.
        r   rv  s    rD   	get_shapezIndexer.get_shape  r{  rF   c                     t         )z}
        Return a half-open [lower, upper) range of indices this dimension
        is guaranteed not to step out of.
        r   rv  s    rD   get_index_boundszIndexer.get_index_bounds  rx  rF   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   rv  s    rD   	loop_headzIndexer.loop_head  s
     "!rF   c                     t         )z)
        Finish indexation loop.
        r   rv  s    rD   	loop_tailzIndexer.loop_tail  r{  rF   N)
rr   rs   rt   __doc__rw  rz  r}  r  r  r   rF   rD   rt  rt    s%    
""""	""rF   rt  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 rP  )	r~   r>   r   r  dimr   r   r   ll_intp)rZ   r~   r>   r   r  r  s         rD   __init__zEntireIndexer.__init__  s?    
||225::>rF   c                 $   | j                   }|j                  | j                  j                  | j                        | _        t        j                  || j                        | _	        |j                         | _        |j                         | _        y rP  )r>   rc  r  rf   r  r   r
   rX   r  r  append_basic_blockbb_startbb_endrZ   r>   s     rD   rw  zEntireIndexer.prepare  sc    ,,))$((..$((C	(($,,?
224002rF   c                     | j                   S rP  r   rv  s    rD   rz  zEntireIndexer.get_size  s    yyrF   c                     | j                   fS rP  r  rv  s    rD   r}  zEntireIndexer.get_shape  s    		|rF   c                 <    | j                  d      | j                  fS r   r  r   rv  s    rD   r  zEntireIndexer.get_index_bounds      Q++rF   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   >=Fri  )r>   r$  r   r  r  branchr  position_at_endr?   r   r  r   r  )rZ   r>   	cur_indexs      rD   r  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 rP  )
r>   r
   r#  r?   r  r$  r  r  r  r  rZ   r>   
next_indexs      rD   r  zEntireIndexer.loop_tail  s^    ,,,,Wgll4::6NO
j$**-t}}%,rF   Nrr   rs   rt   r  r  rw  rz  r}  r  r  r  r  rF   rD   r  r    s*    ?3,
$-rF   r  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 rP  )r~   r>   r   r   r   r   r  )rZ   r~   r>   r   s       rD   r  zIntegerIndexer.__init__  s1    ||225::>rF   c                      y rP  r  rv  s    rD   rw  zIntegerIndexer.prepare      rF   c                 .    t        | j                  d      S NrH   )r   r  rv  s    rD   rz  zIntegerIndexer.get_size  s    a((rF   c                      yNr  r  rv  s    rD   r}  zIntegerIndexer.get_shape  s    rF   c                     | j                   | j                  j                  | j                   | j                               fS rP  )r   r>   addrz  rv  s    rD   r  zIntegerIndexer.get_index_bounds  s,    $,,**488T]]_EFFrF   c                     | j                   d fS rP  )r   rv  s    rD   r  zIntegerIndexer.loop_head  s    xx~rF   c                      y rP  r  rv  s    rD   r  zIntegerIndexer.loop_tail  r  rF   Nr  r  rF   rD   r  r    s+    ?)GrF   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   rq   r   r   r   r  )rZ   r~   r>   r   r   r   s         rD   r  zIntegerArrayIndexer.__init__%  sO    
	zzQ||225::>rF   c                    | j                   }t        j                  || j                  j                        d   | _        t        j                  || j                        | _        |j                         | _
        |j                         | _        y r   )r>   r
   r   r   rf   idx_sizerX   r  	idx_indexr  r  r  r  s     rD   rw  zIntegerArrayIndexer.prepare.  sf    ,,,,Wdkk6G6GHK ,,WdllC224002rF   c                     | j                   S rP  r  rv  s    rD   rz  zIntegerArrayIndexer.get_size5  s    }}rF   c                     | j                   fS rP  r  rv  s    rD   r}  zIntegerArrayIndexer.get_shape8  s    rF   c                 <    | j                  d      | j                  fS r   r  rv  s    rD   r  z$IntegerArrayIndexer.get_index_bounds;  r  rF   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   r  r  r  r  r  r?   r   r  r  r  r  r~   r   r|   r   r   r   )rZ   r>   r  r  s       rD   r  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 rP  )
r>   r
   r#  r?   r  r$  r  r  r  r  r  s      rD   r  zIntegerArrayIndexer.loop_tailT  sb    ,,,,W-4\\$..-IK
j$..1t}}%,rF   Nr  r  rF   rD   r  r     s*    ?3 , *-rF   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 NrH   r   )r~   r>   r   r   rq   r   r   r   r  r   r  )rZ   r~   r>   r   r   s        rD   r  zBooleanArrayIndexer.__init__b  sZ    
zzQ||225::>T\\1-	rF   c                    | j                   }t        j                  || j                  j                        d   | _        t        j                  || j                        | _        t        j                  || j                        | _	        |j                         | _        |j                         | _        |j                         | _        y r   )r>   r
   r   r   rf   r   rX   r  r  r   r  r  bb_tailr  r  s     rD   rw  zBooleanArrayIndexer.preparek  s    ,,(($++2C2CDQG	 ,,WdllC(($,,?
224113002rF   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rP  )r>   r
   r   r  	for_ranger   r?   r  r~   r   r|   r   r  r  zextr:   r$  )rZ   r>   r   loopcpreds         rD   rz  zBooleanArrayIndexer.get_sizet  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 rP  rz  rv  s    rD   r}  zBooleanArrayIndexer.get_shape      !!rF   c                 <    | j                  d      | j                  fS r   r  rv  s    rD   r  z$BooleanArrayIndexer.get_index_bounds  s     Q++rF   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  Fri  )r>   r$  r  r  r   r  r  r  r?   r   r  r   r  r  r~   r   r|   r   not_r  r
   r#  )rZ   r>   r  	cur_countr  
next_counts         rD   r  zBooleanArrayIndexer.loop_head  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 rP  )r>   r  r  r  r
   r#  r?   r  r$  r  r  r  s      rD   r  zBooleanArrayIndexer.loop_tail  s    ,,t||$-,,W-4\\$..-IK
j$..1t}}%,rF   Nr  r  rF   rD   r  r  ]  s*    .3#",
$0-rF   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  r  r   r@  r   r   r   r  r   r  )rZ   r~   r>   r   r  r  r   r@  s           rD   r  zSliceIndexer.__init__  s_    


||225::>T\\1-	rF   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 rP  )r>   rc  r  rf   r  dim_sizer-   r2  r~   r   r@  r3  r
   
is_neg_intstepis_step_negativerX   r  r  r   r  r  r  r  s     rD   rw  zSliceIndexer.prepare  s    ,,--dhhnndhhG##DLL'4::$(JJ	0'4::t}}= ' 2 27DJJOO L(($,,?
(($,,?
224002rF   c                 V    t        j                  | j                  | j                        S rP  )r-   r5  r>   r@  rv  s    rD   rz  zSliceIndexer.get_size  s    ''djjAArF   c                 $    | j                         fS rP  r  rv  s    rD   r}  zSliceIndexer.get_shape  r  rF   c                 d    t        j                  | j                  | j                        \  }}||fS rP  )r-   get_slice_boundsr>   r@  )rZ   loweruppers      rD   r  zSliceIndexer.get_index_bounds  s*    //djjIue|rF   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  Fri  )r>   r$  r@  r4  r  r  r   r  r  r  r?   selectr  r  stopr   r  )rZ   r>   r  r  is_finisheds        rD   r  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  r  r  r  )rZ   r>   r  r  s       rD   r  zSliceIndexer.loop_tail  s    ,,[[djj!94::??(-w ! 0
j$**-,,Wgll4::6NO
j$**-t}}%,rF   Nr  r  rF   rD   r  r    s+    	.3B"$$-rF   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   rH   r,  )$r~   r>   r   r
   r   rf   rq   r  r   r   r   r   r  newaxesr   r   r   r0  r9   r  rj   r   r1  r   r  r   r   r  r   ry   r|   r  Booleanr  AssertionErrorindexers)rZ   r~   r>   r   r  r   r   r  r   r=  r   new_axr>  r   r?  rn   indexerr@  r   r   s                       rD   r  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 )NrH   r  )r  rw  r~   r   r   r   r}  r  insertsumindexers_shape)rZ   rn   r9  	res_shapes       rD   rw  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  rv  s    rD   r}  zFancyIndexer.get_shapeM  s     """rF   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   rH   ==r  )r   r   rq   r>   r
   	false_bitr  r   r  r  or_icmp_unsignedr  r   subr  r  r  )rZ   r   r   r>   is_emptyr  r9  r  r  r  rf   stridelower_indexupper_indexlower_offsetupper_offsetis_downwardss                    rD   get_offset_boundszFancyIndexer.get_offset_boundsS  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|rF   c                 B    t        d | j                  D         \  }}||fS )Nc              3   <   K   | ]  }|j                           y wrP  )r  )rR  rn   s     rD   rT  z+FancyIndexer.begin_loops.<locals>.<genexpr>z  s     E}!}s   )r   r  )rZ   r   countss      rD   begin_loopszFancyIndexer.begin_loopsy  s$    Et}}EFrF   c                 X    t        | j                        D ]  }|j                           y rP  )reversedr  r  )rZ   rn   s     rD   	end_loopszFancyIndexer.end_loops}  s    $--(AKKM )rF   N)
rr   rs   rt   r  r  rw  r}  r  r  r  r  rF   rD   r  r    s(    @!D1&#$LrF   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   rf   r   r   r  rw  r   r}  _empty_nd_implr   r   r   r   r  get_item_pointer2layoutrH  r   r?   gepr   r#  r$  r  r!   r  )r~   r>   r\   r   r   r  r   r   r  r   r   r  out_ty
out_shapesr
  out_dataout_idx_rl   r   curnext_idxs                         rD   rW  rW    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FrF   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   ry   rq   r   rI  r   r    rW  rL  s	            rD   fancy_getitem_arrayr    s    
 88LE5HC
*U
GWc
2CzzQ$WgucB
s$Wgs%*C%C6C '3??CHH WgsD"C%C6; 	;rF   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   rH   CFr  r  )r   r:   r	  r   r   r9   rq   r  r  r  r  )r~   r>   arrtyarrr  r   r   r  r9  r  r  rn   max_axis_offset
is_upwardsr  s                  rD   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%<rF   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.
    )ptrtointr:   r  )r~   r>   r  r  r   data_ptr_as_intr4  ends           rD   compute_memory_extentsr    sD    
 &&tUZZ8OKK/E
++ou
-C#:rF   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	            rD   get_array_memory_extentsr!    s2     .gws.4g?LE5!'7E5$GGrF   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          rD   extents_may_overlapr)    s>     ,,c7E2c7E2K rF   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   Fri  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)NFri  r.  )r
   rX   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       rD   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)NFri  )r   r?   bitcastr  free)r   r>   r~   r2  r;  	voidptrtys    rD   src_cleanupz&maybe_copy_source.<locals>.src_cleanupA  sQ    __Xe_4<<	*D??43DKKWd+ 544s   A AA')r:   r
   r   r   r   r   r   r  allocater>  r$  r   r   r   	loop_nestr  r	  r?   )r~   r>   r;  r:  srcr8  r9  r7  	allocsizer   r   r   r/  dest_ptrr<  rA  r2  r3  r4  r5  r6  r@  s   ```` ```        @@@@@@rD   maybe_copy_sourcerG    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   rH   Nr  Fri  z,cannot broadcast source array for assignment)r   r   r   r   r  	functoolsreducer#  r
   true_bitr   r  rk  rl  r   )r~   r>   r  r   target_shaper  r9  nd_diffrA  
dim_is_oneacceptedr   s               rD   _bc_adjust_dimensionrP  K  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   rH   rh  r  )r   r   r   r   r  r#  r  )r~   r>   r  r   rL  	bc_shapes
bc_stridesr  r9  taroldmismatch
src_is_onexypredsps                    rD   _bc_adjust_shape_stridesr\  p  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rq   r	  rE  )r
   r   rf   r   rP  r\  copyr   ry   r   r   rk   r   r   r   )	r~   r>   arrtyper  rL  r  r   new_arrtypenew_arrs	            rD   _broadcast_to_shaperd    s     !!'3995F""7CKK8G*7GVW+79OFG.w/6FOFG,,C$5c,BK%j%gw7G7 ++GV<"--gw?LL;;**& rF   c                 ^    |j                  |j                  dd      } |||      }d }||fS )Nr^  T)rq   r	  readonlyc                 n   |\  }}|j                   d   } t        |      | ||      }t        j                  ||      }t	        | ||||      \  }}t        |dt        | j                  |j                  j                  d            d              |j                         }	t        | ||j                  |	      S )Nr   r   )r   ry   r
   r   rd  r   r   r   r   r   r  r    r   )
r~   r>   r\   r   rD  shape_r:  r  destr	  s
             rD   codegenz$_numpy_broadcast_to.<locals>.codegen  s    Vj#6%%gv6%gwsFL4 	h&&t'?'?'IJ! 	 nn '3??CHHrF   )r`  r   )	typingctxr   rf   retr\   rj  s         rD   _numpy_broadcast_torm    s8    
**%++cD*
AC
eU
CI <rF   c                 D    |j                  d      } ||      }d }||fS )NTrf  c                     |\  }|j                   d   } t        |      | ||      }t        j                  |j                  j
                        |_        |j                         }t        | ||j                  |      S r   )	r   ry   r
   get_null_valuer   r:   r  r    r   )r~   r>   r\   r   rD  r:  ri  r	  s           rD   rj  z#get_readonly_array.<locals>.codegen  sh     z% '37,,T[[-=-=>nn '3??CHHrF   )r`  )rk  r  rl  r\   rj  s        rD   get_readonly_arrayrr    s/     ((D(
!C
c(CI <rF   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-negativerH   z=operands could not be broadcast together with remapped shapes)rf   r   r   )
r   
dest_shape	src_shapesrc_ndim	dest_ndimr   	src_index
dest_indexsrc_dimdest_dims
             rD   _can_broadcastr|    s    I9~HJI) 1 2 	2!8 , - -  IX%J
h
I&j) h'Q,NI!OJ 4 5 5 h
rF   c                 \    t        j                  |       } t        | |       t        | |      S rP  )npasarrayr|  rm  r   rf   s     rD   _default_broadcast_to_implr    s'    JJuE5% ue,,rF   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 rP  )r~  broadcast_tor  s     rD   r   z numpy_broadcast_to.<locals>.impl  s    ??55(33rF   z7The second argument "shape" must be a tuple of integersr   "z," object cannot be interpreted as an integerc                 B    t        j                  |       } t        |       S rP  )r~  r  rr  r  s     rD   r   z numpy_broadcast_to.<locals>.impl  s     

5))%00rF   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   UniTupler|   r  Tupler   allIntegerLiteralr   rq   r   )r   rf   r   r   typis_scalar_arrays         rD   numpy_broadcast_tor    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 allowedrH   z=shape mismatch: objects cannot be broadcast to a single shape)r9   r   r   )rmrf   rn   r   tmps         rD   numpy_broadcast_shapes_listr    s~    3u:E
NQAh7BCC!8Q419AaDqTS[ 2 3 3 rF   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 rH   c                       yr  r  r   s    rD   <lambda>z+ol_numpy_broadcast_shapes.<locals>.<lambda>B  s    RrF   rH   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   r   r0   )r   r  rY  argr   elemr  tup_inits         rD   r   z'ol_numpy_broadcast_shapes.<locals>.implF  s    aAC%d+c5)c#hl/1c:S)/1sf=	 ,
 'q\	T#Cd3 *JrF   )r   r   r   r   r  r|   r  r   r	   r   maxr\  )
r   r   r  is_intis_int_tupleis_empty_tupler   r   r  r  s
           @@rD   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	 rF   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   rH   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  r~  r  rf   r9   r0   rj   r  )r   rf   r   rY  rn   outsr  r  s         rD   r   z$numpy_broadcast_arrays.<locals>.implx  s    
 a#D)E'q"**U2C2I2IJ * qAQa1C  #D)EKK

5(93?@ *rF   )r   r   r	   r   r   r   r   r\  r|   ArrayCompatibler  rq   Numberr  )r   r   r  unified_dtypedtr   r  r  s         @@rD   numpy_broadcast_arraysr  U  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( KrF   c                     t         )zTargets should implement this if they wish to specialize the error
    handling/messages. The overload implementation takes two tuples as arguments
    and should raise a ValueError.r   r8  index_shapes     rD   raise_with_shape_contextr    
     rF   generic)targetc                     t        | t        j                        r_t        |t        j                        rD| j                  |j                  k(  r*t        | j                  t        j                        rd }|S y y y y )Nc                     t        d      )Nz0cannot assign slice from input of different sizer   r  s     rD   r   z1ol_raise_with_shape_context_generic.<locals>.impl  s    OPPrF   r   r   r  r|   r   r8  r  r   s      rD   #ol_raise_with_shape_context_genericr    sg     	:u~~.;/K---z''7	Q	 8 	. 	0 	/rF   CPUc                     t        | t        j                        r_t        |t        j                        rD| j                  |j                  k(  r*t        | j                  t        j                        rd }|S y y y y )Nc           	      L   t        |       dk(  r
d| d    d}n,ddj                  | D cg c]  }t        |       c}       d}t        |      dk(  r
d|d    d}n,ddj                  |D cg c]  }t        |       c}       d}d| d| }t        |      c c}w c c}w )	NrH   (r   z,), )zcannot assign slice of shape z from input of shape )r   joinstrr   )r8  r  	shape_strrX  	index_strr   s         rD   r   z-ol_raise_with_shape_context_cpu.<locals>.impl  s    :!#
1b1			:*F:a3q6:*F GHJ	;1$A/r2			;*G;a3q6;*G HIK	29+ >%;(CS/! +G +Hs   B
-B!
r  r  s      rD   ol_raise_with_shape_context_cpur    sf    :u~~.;/K---z''7	"  8 	. 	0 	/rF   c                 ^   ()* |j                   \  }}*|\  }}( t        |       |      }t        j                  |j                        }	t        j                  |j
                        }
|j                  }t         ||||      }|j                          d }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dd       t+         *(|||      \  }}|j-                  |
|j.                        \  }}t1         |||      \  }}t3         ||||      }t5         |*(|||      \  }}nt        *t        j6                        r*j                  )|j                         }t!        |      dk(  sJ  j9                  t         t;        t        j<                  *            } |(f      }j'                  d|d   |      }j)                  |d      5   | |f|d   f       ddd        ()*fd}d	 }n
*)(fd
}d } j?                  t        j@                  d      } |jC                         \  }!}"tE        |"      }"|jF                  D ]  }#|"jI                  |#|         |"D $cg c]  }$|$|$	 }%}$ ||%      }& jK                  |&)|j                        }&t        jL                   ||	|
|jN                  |!d jP                  	      }'tS         ||&|'       |jU                           |         jW                         S # 1 sw Y   Mx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.
    c           	         | j                   j                  t              }t        j                  t        j
                  t        |            t        j                  t        j
                  t        |            f}|j                  | j                   |i       }| j                  ||      } ||| j                  ||j                  d   |      | j                  ||j                  d   |      f       y Nr   rH   )typing_contextresolve_value_typer  r   r  int64r   get_call_typerR   
make_tupler   )r~   r>   r8  r  fntyargtys	raise_sigfuncs           rD   raise_shape_mismatch_errorz2fancy_setslice.<locals>.raise_shape_mismatch_error  s     %%88$&..c*o>..c+.>?A&&w'='=vrJ	##D)4Ww))'9>>!3D*46))'9>>!3D*578 	9rF   rh  Fri  NrH   r   c                     | \  }j                  t        j                  t        t        j
                              } ||f      S rP  )rR   operatorgetitemr$   r   r   )r.  r   getitem_implr>   r~   rD  	src_dtyper:  s      rD   r<  z#fancy_setslice.<locals>.src_getitem  sF    !DC"//  )UEJJ7L  #s44rF   c                       y rP  r  r  rF   rD   rA  z#fancy_setslice.<locals>.src_cleanup      rF   c                     S rP  r  )r.  rD  s    rD   r<  z#fancy_setslice.<locals>.src_getitem$  s    JrF   c                       y rP  r  r  rF   rD   rA  z#fancy_setslice.<locals>.src_cleanup'  r  rF   r-  ),r   ry   r
   r   rf   r   r   r  rw  r   r   r  r|   r}  rd  r  r   r   r  r  r   r!  r  r   r  r)  rG  SequencerR   r$   r   r   r   r  r   r  r  r   r  r	  rH  r   r  rq  )+r~   r>   r\   r   r   r   r   r  r  dest_shapesdest_strides	dest_datar  r  r  r8  r9  r7  shape_errorur   	src_startsrc_end
dest_lower
dest_upper
dest_startdest_endr;  r<  rA  len_implseq_lenr  dest_indicesr  rn   r  r.  r   rF  rD  r  r:  s+   ``                                      @@@rD   r^  r^    s    hhOE1eKCC
*U
GWc
2C&&w		:K''=LI7GUC&1GOO9 %&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&w'24 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&w'(3A'8: 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$   9PP4P*<P*PP'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   rH   r|   r   )r   r   r   r   r   r
   rk   r:   r  r   r   r$   r   )r~   r>   r\   r   r   dimtysr  rm   rS  r   rf   shapetynew_signew_argss                 rD   vararg_to_tupler  U  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>   r\   r   s       rD   array_transposer  h  s    7GSXXa[$q'::rF   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   rf   r   r  rX  s        rD   permute_arraysr  m  st    
4yCD	N"566
e*C8s1v| / 0 0 
 T{E!HGAJrF   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   rH   r   r|   rq   r	  r   rf   r   r   r   ro  rE  )"r   ry   r   r|   r   r   r   r   	ArrayTyperf   r   r
   rX   r   r$  r   r   r}   r   r>  
as_pointercompile_internalr  r   r$   voidr  r   r   r?   r   r   r   r    )r~   r>   r\   r   r   r  axistyr   num_axisr|   r  ll_ary_sizearysr  ll_arysrD  dst	np_ary_tynp_itemsizenp_arysnp_aryll_aryarl  r	  s                            rD   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 rP  )r  r  r~   r>   r\   r   r  r  s         rD   array_transpose_varargr
    s(    '#tDGX '7HEErF   c                 |    t        | t        j                        rt        j                  d      |dd}|S dd}|S )Nz#np.transpose does not accept tuplesc                 "    | j                         S rP  	transposer  axess     rD   np_transpose_implz*numpy_transpose.<locals>.np_transpose_impl  s    ;;= rF   c                 $    | j                  |      S rP  r  r  s     rD   r  z*numpy_transpose.<locals>.np_transpose_impl  s    ;;t$$rF   rP  )r   r   r\  r	   r   )r  r  r  s      rD   numpy_transposer    sA    !U__%  !FGG|	! 	% rF   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 )NrH   rE  )rq   ry   r
   r   rf   r   r   r   rk   r   r   r   r  r    )	r~   r>   r  r  r	  r  rl  r  r   s	            rD   r  r    s    
xx1}jogw6jogw/%%gsyy#((C&&wSXXFsHH$//"F&11'74R4=I #"{{!jj	* mmoWgsC88rF   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      $@)r~  linspacepower)r4  r  numrY  s       rD   r   znumpy_logspace.<locals>.impl  s%    KKtS)xxa  rF   2   )r   r   r  r	   r   r   r   )r4  r  r  r   s       rD   numpy_logspacer    ss    eU\\*  !NOOdELL)  !NOOcC/0  !NOO! KrF   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rP  r   r   ComplexrR  r  s     rD   rT  z"numpy_geomspace.<locals>.<genexpr>       
C]c:c5==)]rU  c                 F   | dk(  s|dk(  rt        d       	|       }  	|      }t        dk  rz| j                  dk(  |j                  dk(  z  }t        j                  |       dk(  t        j                  |      dk(  z  }d}|r| j
                  } |j
                  }d}|r)|  } | }| }nt        j                  |       }| |z  } ||z  }t        j                  |       }t        j                  |      }t        j                  |||      }|dkD  r| |d<   |dkD  r||d<   ||z  S )Nr   &Geometric sequence cannot include zerorn  r  rH   y              ?)r   r   realr~  signimaglog10logspace)
r4  r  r  both_imaginaryboth_negativeout_signlogstartlogstopr%  result_dtypes
            rD   r   znumpy_geomspace.<locals>.impl  s'   zTQY !IJJ 'E%Dv%"'**/dii1n!E!#2!5"''$-2:M N!!JJE99D!H "FE 5D (yH775>! xxHhhtnG[[7C8F Qw!q	7!%F2Jf$$rF   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  rH   )r   r~  r)  r+  r,  )r4  r  r  r.  r/  r0  r1  r%  s           rD   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$$rF   r  )r   r   r  r	   r   r   r   rV  r   r~  result_typer   )r4  r  r  r   r   r2  s        @rD   numpy_geomspacer5    s    eU\\*5  %%dELL)4  %%cC/05  %%

CeT]
CC!"..%19$#G H 	%p K+	%* KrF   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 arrayro  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   rH   ro     )r~  swapaxesfliplrflipudr  )r  r   s     rD   r   znumpy_rot90.<locals>.implD  s    E6Q4K!V;;ryy|Q22!V99RYYq\**!V99R[[Aq122  rF   r  )	r   r   r   r   r	   r   r   rq   NumbaValueError)r  r   r   s      rD   numpy_rot90r?  9  sr     a#u}}-.  !MNNa%  !JKKvvz$$%<==! KrF   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_reshaperf   r   r   )r   r   r   r  intcr   FunctionTyper
   get_or_insert_functionr;   rq   ri   rh   callr   )r~   r>   r   r  newndnewshape
newstridesr  ll_intp_starll_intcr  fnndrf   r   
is_f_orderr	  s                    rD   _attempt_nocopy_reshaperN  T  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 JrF   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   rH   z)total size of new array must be unchangedzmultiple negative shape values)r   r   )	origsizerf   num_neg_value
known_sizer   r   neg_axinferredoks	            rD   normalize_reshape_valuerV  x  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::rF   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   rH   r   r  r  r  zincompatible shape for arrayrE  )(r   r   r   r   r   r   r  r   ry   r
   rX   r$  r   r|   r   r}   r   r>  r  r   r  rV  r   r$   r  r   r  rN  r  r:   r   rk  rl  rS   r   r?   r   r   r   r    )r~   r>   r\   r   r   rettyr  rf   r  ll_shaper  rG  shape_ary_ty	shape_aryshape_itemsizer   rF  rH  rU  failr   rl  r	  s                          rD   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 rP  )r  r^  r	  s         rD   array_reshape_varargr`    s(    '#tDGX'7H==rF   )ro  rH   c                     d }|S )Nc                 $    | j                  |      S rP  reshape)r  rG  s     rD   np_reshape_implz#np_reshape.<locals>.np_reshape_impl  s    99X&&rF   r  )r  rG  re  s      rD   
np_reshaperf    s    	'rF   c                     d }|S )Nc                 $    | j                  |      S rP  rc  )r  rf   s     rD   re  z#np_reshape.<locals>.np_reshape_impl  s    99U##rF   r  )r  rf   re  s      rD   rf  rf    s    	$rF   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 )NrH   r   z0All elements of `new_shape` must be non-negative)r~  r  ravelr   r   r   r   zerosastyper|   r9   concatenaterd  )	r  	new_shapenew_size
dim_lengthr   msg2repeatsr	  rn   s	            rD   r   znumpy_resize.<locals>.impl  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))rF   )r   r	   r   r   r   r  r|   r   )r  rp  r   r   s       rD   numpy_resizeru    st     A3  %%	5>>2	7y%--0%  %%*8 KrF   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 rP  )r~  rl  r  ro  r  valuesr   s      rD   r   znp_append.<locals>.impl%	  sB    ((2::c?+CXXbjj01F>>3-00rF   z,The third argument "axis" must be an integerc                 4    t        j                  | |f|      S Nr   r~  ro  rx  s      rD   r   znp_append.<locals>.impl/	  s    >>3-d;;rF   rP  )r   r	   r   r   r   r   r   )r  ry  r   r   s       rD   	np_appendr~  	  s     C   !NOOF#   ". / 	/ 4	1 K $.$$ &/ 0 0	<KrF   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)rd  r   r  s    rD   
imp_nocopyzarray_ravel.<locals>.imp_nocopy7	  s    {{388$$rF   c                 "    | j                         S )zCopy version)flattenr  s    rD   imp_copyzarray_ravel.<locals>.imp_copy;	  s    {{}rF   r   r   )r   r	  r  r!   r   )r~   r>   r\   r   r  r  impr	  s           rD   array_ravelr  4	  s_    %
 xx{S  

"
"7Cd
;C
7GS__c
BCJrF   c                 0    d }| j                  ||||      S )Nc                 "    | j                         S rP  )rl  r  s    rD   np_ravel_implznp_ravel.<locals>.np_ravel_implM	  s    wwyrF   )r  )r~   r>   r\   r   r  s        rD   np_ravelr  K	  s      ##G]CFFrF   zarray.flattenc                 d    d }| j                  ||||      }t        | ||j                  |      }|S )Nc                 T    | j                         j                  | j                        S rP  )r`  rd  r   r  s    rD   r  zarray_flatten.<locals>.impV	  s    xxz!!#((++rF   )r  r!   r   )r~   r>   r\   r   r  r	  s         rD   array_flattenr  S	  s8    , 
"
"7Cd
;C
7GS__c
BCJrF   c                    |t        j                  |       n|}t        j                  | ||      \  }}}t        j                  |j                        D ]*  }||   }	||   }
||   }t        t        |	|
      |      ||<   , |S rP  )r~  
empty_likebroadcast_arraysndindexrf   minr  )r  a_mina_maxr
  rl  a_ba_min_ba_max_br  val_a	val_a_min	val_a_maxs               rD   _np_clip_implr  ^	  s     "k"--
sC//5%@C'CII&E
EN	EN	UI.	:E
	 ' JrF   c                     t        j                  | j                        D ]-  }| |   }||   }|rt        ||      ||<   t	        ||      ||<   / |S rP  )r~  r  rf   r  r  )r  buse_minr
  r  r  val_bs          rD   _np_clip_impl_noner  l	  sU    AGG$%%UE*CJUE*CJ % JrF   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 )Nrj  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       rD   
np_clip_nnznp_clip.<locals>.np_clip_nn	  s    EFFrF   c                     |t        j                  |       n|}t        j                  | j                        D ]   }| |   }t	        t        ||      |      ||<   " |S rP  )r~  r  r  rf   r  r  r  r  r  r
  rl  r  r  s          rD   
np_clip_ssznp_clip.<locals>.np_clip_ss	  sV     '*k"--"sCAGG,% UE!2E:E
 - JrF   c                     |t        j                  |       n|}t        j                  | j                        D ]  }| |   }t	        ||      ||<    |S rP  )r~  r  r  rf   r  r  s          rD   
np_clip_snznp_clip.<locals>.np_clip_sn	  O     +.+bmmA&3ZZ0EeHE!$UE!2CJ 1 
rF   c                 J    t        j                  | |      }t        | |||      S rP  r~  	full_liker  )r  r  r  r
  
a_min_fulls        rD   
np_clip_saznp_clip.<locals>.np_clip_sa	  s%    
  \\!U3
$Q
E3??rF   c                     |t        j                  |       n|}t        j                  | j                        D ]  }| |   }t	        ||      ||<    |S rP  )r~  r  r  rf   r  r  s          rD   
np_clip_nsznp_clip.<locals>.np_clip_ns	  r  rF   c                 J    t        j                  | |      }t        | |||      S rP  r  )r  r  r  r
  
a_max_fulls        rD   
np_clip_asznp_clip.<locals>.np_clip_as	  s%    
  \\!U3
$Qz3??rF   c                     |t        j                  |       n|}t        j                  | |      \  }}t        ||d|      S )NTr~  r  r  r  )r  r  r  r
  rl  r  r  s          rD   
np_clip_naznp_clip.<locals>.np_clip_na	  s=    *-+bmmA&3!221e<W)#wcBBrF   c                     |t        j                  |       n|}t        j                  | |      \  }}t        ||d|      S )NFr  )r  r  r  r
  rl  r  r  s          rD   
np_clip_anznp_clip.<locals>.np_clip_an	  s=    *-+bmmA&3!221e<W)#wsCCrF   c                     t        | |||      S rP  )r  r  s       rD   
np_clip_aaznp_clip.<locals>.np_clip_aa	  s     %Quc::rF   rP  )	r   r	   r   r   r   rK  r   r   r  )r  r  r  r
  r   a_min_is_nonea_max_is_noner  a_min_is_scalara_max_is_scalarr  r  r  r  r  r  r  r  s                     rD   np_clipr  x	  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 ; rF   clipc                     dd}|S )Nc                 2    t        j                  | |||      S rP  )r~  r  r  s       rD   r   zarray_clip.<locals>.impl	  s    wwq%,,rF   NNNr  )r  r  r  r
  r   s        rD   
array_clipr  	  s    -KrF   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.
    r^  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   FrH   Tr  )rL  rm   r   old_itemsizenew_itemsizer	  rn   newdim
bytelength
any_layoutc_layoutf_layoutint8s            rD   r  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  rF   rf   r   r   rH   r  Nr  )rq   r	  ordr   r  r   r   r   r
   ri   rh   r   ry   rk   r}   r{   r   r  r$   booleanr  r   r    r   )r~   r>   oldtynewtyr  
new_layoutr  r  r  rL  
shape_datastrides_datashape_strides_array_typearyclsshape_constantsizeof_intpstrides_constantr[  strides_aryrf   r   r   r\   r	  r  r  r  r  s                           @@@@rD   _change_dtyper  	  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JrF   c                 L    t        |       st        j                  d      d }|S )Nz+The argument to np.shape must be array-likec                 @    t        j                  |       j                  S rP  )r~  r  rf   r  s    rD   r   znp_shape.<locals>.impl|
  s    zz!}"""rF   r   r	   r   r  r   s     rD   np_shaper  w
  s&    A  !NOO#KrF   c                 L    t        |       st        j                  d      d }|S )Nz*The argument to np.size must be array-likec                 @    t        j                  |       j                  S rP  )r~  r  r   r  s    rD   r   znp_size.<locals>.impl
  s    zz!}!!!rF   r  r  s     rD   np_sizer  
  s&    A  !MNN"KrF   c                     d }|S )Nc                    d }t        j                  | j                               }t        |d d       }t	        |dd        D cg c]"  \  }}||   |k7  r |||         r ||      s|$ }}}t        j
                  ||z         S c c}}w )Nc                     | | k(   S rP  r  )rX  s    rD   isnanz0np_unique.<locals>.np_unique_impl.<locals>.isnan
  s    Q<rF   rH   )r~  sortrl  r   r   r   )arr  r  headrn   rX  tails          rD   np_unique_implz!np_unique.<locals>.np_unique_impl
  s    	  GGBHHJAbqE{#AabE*
*$!Qtqy%!+%( * 	 
 xxt$$	
s   'Br  )r  r  s     rD   	np_uniquer  
  s    
% rF   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r|   r   rH   r  z(operands could not be broadcast together)r~  r  r  rf   np_repeat_impl_repeats_scalerrV  r   rl  emptyr  r|   r9   )	r  rt  repeats_arrayasaaraveln	to_returnposrn   s	            rD   !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  rF   zIThe repeats argument must be an integer or an array-like of integer dtype)r   r   r   Listr\  r  r  r   r  r|   r	   r   )r  rt  r  s      rD   	np_repeatr   
  s    
, !ekkjjoollmm	  gu}}-00%++uzz!:;'--788  01 	1rF   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   r  r  rH   )	r   r~  r  rl  rf   r  r|   r`  r9   )r  rt  r  r  r  r  rn   s          rD   r  r  
  s    {>??
**Q-CYY[FQA!|xx++	AwwvHHQ[		:	qA9?Ia'kQUg$56 rF   repeatc                     d }|S )Nc                 .    t        j                  | |      S rP  )r~  r  )r  rt  s     rD   array_repeat_implz'array_repeat.<locals>.array_repeat_impl
  s    yyG$$rF   r  )r  rt  r  s      rD   array_repeatr  
  s    % rF   c                 :    t        j                  |      }d }||fS )z"Computes the itemsize of the dtypec                     | j                  |j                  d   j                        }| j                  |j                        } || j	                  |            S r   )r{   r   r|   r   r}   )cgctxr>   r\   llargsr   llintps         rD   rj  z%_intrin_get_itemsize.<locals>.codegen
  sJ    ""388A;#4#45$$S__5e**4011rF   )r   r   )tyctxr|   r\   rj  s       rD   _intrin_get_itemsizer  
  s#     **U
C2 <rF   c                      y rP  r  )r  r|   s     rD   _compatible_viewr  
      rF   c                     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 unchangedrH   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   rq   r   rf   r   r   )r  r|   
dtype_sizemsg1r   p1p2p3rs  msg3r  msg4s               rD   r   z ol_compatible_view.<locals>.impl
  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 $rF   r  r  r|   r   s      rD   ol_compatible_viewr  
  s    "+F KrF   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   )rH      r  z"new type not compatible with array)r   r   ry   r   r   r   sortedgetattrr   r:   r>  r   r   r  r  r  r  rR   r  r  r   r   rk  rl  r   r  r    )r~   r>   r\   r   r   rX  r  rl  fieldsr   r   r6  r  r  _compatible_view_sigr   rU  r]  r   r	  s                       rD   
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	r|   c                 >    | j                         }t        | |||      S rP  )rq  r"   r~   r>   r  r  r	  s        rD   array_dtyper%  K  s!    

!
!
#CgwS99rF   rf   c                 `    t        |      } || ||      }|j                  }t        | |||      S rP  )ry   rf   r"   r~   r>   r  r  r   r   r	  s          rD   array_shaper(  Q  s5     oGGWe,E
++CgwS99rF   r   c                 `    t        |      } || ||      }|j                  }t        | |||      S rP  )ry   r   r"   r'  s          rD   array_stridesr*  Z  s5     oGGWe,E
--CgwS99rF   rq   c                 r    | j                  t        j                  |j                        }t	        | |||      S rP  )r   r   r   rq   r"   r$  s        rD   
array_ndimr,  c  s/     

uzz388
4CgwS99rF   r   c                 `    t        |      } || ||      }|j                  }t        | |||      S rP  )ry   r   r"   r'  s          rD   
array_sizer.  j  s3    oGGWe,E
,,CgwS99rF   r   c                 `    t        |      } || ||      }|j                  }t        | |||      S rP  )ry   r   r"   r'  s          rD   array_itemsizer0  r  s5     oGGWe,E
..CgwS99rF   nbytesc                     t        |      } || ||      }|j                  |j                  |j                        }t	        | |||      S )z"
    nbytes = size * itemsize
    )ry   r   r   r   r"   r'  s          rD   array_nbytesr3  {  sD     oGGWe,E
++ellENN
3CgwS99rF   
contiguousc                 r    | j                  t        j                  |j                        }t	        | |||      S rP  )r   r   r  	is_contigr"   r$  s        rD   array_contiguousr7    s-    


u}}cmm
<CgwS99rF   c_contiguousc                 r    | j                  t        j                  |j                        }t	        | |||      S rP  )r   r   r  is_c_contigr"   r$  s        rD   array_c_contiguousr;    -    


u}}coo
>CgwS99rF   f_contiguousc                 r    | j                  t        j                  |j                        }t	        | |||      S rP  )r   r   r  is_f_contigr"   r$  s        rD   array_f_contiguousr@    r<  rF   rf  c                 t    | j                  t        j                  |j                         }t	        | |||      S rP  )r   r   r  mutabler"   r$  s        rD   array_readonlyrC    s/    


u}}#++o
>CgwS99rF   ctypesc                     t        |      } || ||      }t        j                  |      }| j                  ||      }|j                  |_        |j
                  |_        |j                         }t        | |||      S rP  )ry   r   ArrayCTypesr   r   r   r  r    )	r~   r>   r  r  r   r   actctinfor	  s	            rD   array_ctypesrI    sp    oGGWe,E


C
 C  #.F**FK]]FN



CWgsC88rF   r   c                     | j                  |||      }|j                  }|j                  || j                  t        j
                              }t        | |||      S Nr  )r   r   r  r   r   r   r"   )r~   r>   r  r  rH  r	  s         rD   array_ctypes_datarL    sT      #U ;F
++C


3 6 6uzz B
CCgwS99rF   c                     | j                  |||      }|j                  }|j                  || j                  |            }t	        | |||      S rK  )r   r   r>  r   r"   )r~   r>   fromtytotyr   rH  r	  s          rD   array_ctypes_to_pointerrP    sP       & <F
++C
//#w55d;
<Cgwc::rF   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  )ry   r   r  r   rq   r}   r   r|   r$   bool_rf   r   r   r  )
checkerr~   r>   r   r  tup_intpr   	check_sig
check_argsr6  s
             rD   _call_contiguous_checkrW    s     *U
GWC
8C~~ejj%**5H%%g&<&<U[[&IJH%++x5::FI))S[[&&uzz8<>J(('9)35IrF   r   c                     | j                  |t        j                  |            }||_        |j	                         }| j
                  j                  |||       t        | |||      S rP  )r   r   
ArrayFlagsr   r  r  r  r!   )r~   r>   r  r  flagsobjr	  s         rD   array_flagsr[    s[    ""7E,<,<S,ABHHO



CKKwU+GWc377rF   c                 :   |j                   j                  dk7  r<| j                  |||      }t        t        | ||j                   |j
                        }n9|j                   j                  dk(  }| j                  t        j                  |      }t        | |||      S )Nr   r  )
rc   r	  r   rW  r   r   r   r   r  r"   )r~   r>   r  r  rZ  r	  r   s          rD   array_flags_c_contiguousr]    s     ~~#&&w5&A$]GW%(^^X__F nn##s*""5==#6gwS99rF   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  rH   r  )rc   r	  r   rW  r   r   rq   r   r   r  r"   )r~   r>   r  r  rZ  r	  r	  r   s           rD   array_flags_f_contiguousr_    s    
~~#&&w5&A$Z'%(^^X__F &&"~~22Q6fmFdN""5==#6gwS99rF   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 {})	r|   r   complex_domainarray_complex_attrnumber_domainr    rS   r   r:   )r~   r>   r  r  s       rD   array_real_partrf    se    
yyE(((!'7CVLL	e))	) '3>>!"<"C"CDJJ"OPPrF   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*  ra  Tro  r   zunsupported .imag for {})r|   r   rc  rd  re  r$   r`  _parse_empty_like_argsr  r
   memsetr   r   r   r   r!   r   r  rS   r   r:   )r~   r>   r  r  r\   ra  r  r  s           rD   array_imag_partrj    s    
yyE(((!'7CVLL	e))	)$/50'3PWgw?w'++cll69jj+BCD	F#// #1 	1 ""<"C"CDJJ"OPPrF   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*      rH   r^  r|   r	  )r   r   )r|   r   rc  rS   r   ry   underlying_floatr}   r{   r   r:   r   r  r>  r   r
  r   IntTyper`  r   r
   copy_structr    r  )r~   r>   r  r  rb  r   r   fltysizeof_fltyr   
llfltptrtyr  resulttyr%  repls                  rD   rd  rd    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LrF   conj	conjugatec                     d }|S )Nc                 ,    t        j                  |       S rP  )r~  rv  r  s    rD   r   zarray_conj.<locals>.implX  s    wws|rF   r  r  r   s     rD   
array_conjr|  U  s    KrF   c                 "    | j                         S rP  )rq  )r~   r>   dtypetydtypevals       rD   
dtype_typer  `  s    ""$$rF   r:   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>   r\   r   rX  r	  r   s          rD   static_getitem_number_clazzr  m  s^     OOE%% ,g$$U+D1!'7E3??L""3''rF   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 definedr^  r  rm  )r   rE  )ry   r|   r   r   RecordrS   typeofr  NestedArrayr`  rq   r   r   r
   r  r   r:   r   rf   r   r}   r{   r   r   r   r  r    )r~   r>   r  r  rb  r   r   rectyper|   r  restyrarytyraryconstoffset
newdataptrrf   rn   r   datasizer	  s                       rD   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   r  rS   r  r   )r~   r>   r\   r   r  s        rD   array_record_getitemr    s:    GEeS!!!#((1+tAwNNrF   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.
    NrE  rH   )sentry_record_alignmentr  r  r   r   r  ry   r|   rf   r   r   r   r
   get_record_memberr{   r   rk   r   r  r    r   r   )r~   r>   r  r  rb  r  elemtyr   r  r|   r   rG  rH  newdatar	  dptrr   s                    rD   record_getattrr    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.
    rH   r  Nr   )r   r  r  r  r   r   r  r
   rx   r   r  r:   pointeememcpyr   r   r   r{   r   r   r   )r~   r>   r\   r   rb  r  r_  r  r   r  r  
val_structrD  ri  r  r   s                   rD   record_setattrr    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CrF   c                     | j                  |j                  d   |d         } || ||j                  d   |d   |d         S )3
    Record.__getitem__ redirects to getattr()
    r   rH   )get_getattrr   )r~   r>   r\   r   r   s        rD   record_static_getitem_strr    sE    
 sxx{DG4D#((1+tAwQ@@rF   c                 2   |j                   d   j                  }t        |j                   d   j                        }| j	                  |j
                  ||         }| j                  |j                   d   |      } || ||j                   d   |d   ||         S )r  rH   r   )r   r   r   r   insert_const_stringr;   r  )r~   r>   r\   r   r   r   ll_fieldr   s           rD   record_static_getitem_intr    s    
 ((1+
#
#C#((1+$$%F**7>>6#;GHsxx{H5D#((1+tAwsDDrF   static_setitemc                     |j                   \  }}}|\  }}}	t        |j                  ||      }
| j                  ||
      }|J  ||||	f      S )3
    Record.__setitem__ redirects to setattr()
    )r   r$   r   get_setattr)r~   r>   r\   r   rectyr  r_  recr   r   getattr_sigr   s               rD   record_static_setitem_strr  !  s_    
 hhOE1eMCcCOOUE:KsK0D#s$$rF   c                     |j                   \  }}}|\  }}}	t        |j                  ||      }
t        |j                   d   j                        }| j                  ||   |
      }|J  ||||	f      S )r  r   )r   r$   r   r   r   r  )r~   r>   r\   r   r  r  r_  r  r   r   r  r   r   s                rD   record_static_setitem_intr  .  s{    
 hhOE1eMCcCOOUE:K#((1+$$%Fvc{K8D#s$$rF   c                 (    | j                  |||      S )zB
    Create a constant array (mechanism is target-dependent).
    )make_constant_array)r~   r>   rS  pyvals       rD   constant_arrayr  @  s    
 &&wE::rF   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  ro  r1  	bytearraytobytesr
   r   )r~   r>   rS  r  ltyr   s         rD   constant_recordr  H  sH    
 ,,rzz!}ell
3C
i(
)C$$Wc22rF   c                     t        j                  t        |      t         j                        }| j	                  |||      S )zM
    Create a constant array from bytes (mechanism is target-dependent).
    r  )r~  r   r  uint8r  )r~   r>   rS  r  bufs        rD   constant_bytesr  R  s2    
 ((9U#288
4C&&wC88rF   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 rP  )rf   r   rD  r   r  r  s     rD   array_is_implzarray_is.<locals>.array_is_impld  sI    177" /		QYY&/.	0rF   )r   r
   r  r  )r~   r>   r\   r   atybtyr  s          rD   array_isr  ^  s@    xxHC
cz   0
 ##G]CFFrF   __hash__c                     d S )Nc                      y rP  r  rz  s    rD   r  zol_array_hash.<locals>.<lambda>q  s    trF   r  rz  s    rD   ol_array_hashr  o  s    rF   c                     t        | d      S )zq
    Return the Structure representation of the given *flatiterty* (an
    instance of types.NumpyFlatType).
    flat_make_flattening_iter_cls)
flatitertys    rD   make_array_flat_clsr  w  s    
 %Z88rF   c                     t        | d      S )zv
    Return the Structure representation of the given *nditerty* (an
    instance of types.NumpyNdEnumerateType).
    ndenumerater  nditertys    rD   make_array_ndenumerate_clsr    s    
 %X}==rF   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   r  r$  r
   
false_byter  r9   ri   r#  r?   r  	if_likelyr  	true_byter  )r~   r>   rq   rf   r   end_flagloop_continue
loop_breakr  bbendr  idxptrr   r   	in_boundss                  rD   _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 rP  )r
   r   rf   rq   r  )r~   r>   r  r  r   r  rf   s          rD   _increment_indices_arrayr    s4      #))UZZ@EwUGXNrF   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).
    rH   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 rP  )nditermember_name	start_dimend_dimrq   )rZ   r  r  r  r  s        rD   r  z-make_nditer_cls.<locals>.BaseSubIter.__init__  s+     DK*D&DN"DL)+DIrF   c                 F    t        | j                  | j                  |       y rP  )r   r  r  )rZ   rl   s     rD   set_member_ptrz3make_nditer_cls.<locals>.BaseSubIter.set_member_ptr  s    DKK!1!137rF   c                 B    t        | j                  | j                        S rP  )r  r  r  rv  s    rD   
member_ptrz/make_nditer_cls.<locals>.BaseSubIter.member_ptr  s    4;;(8(899rF   c                      y rP  r  )rZ   r~   r>   s      rD   init_specificz2make_nditer_cls.<locals>.BaseSubIter.init_specific  r  rF   c                      y rP  r  rZ   r~   r>   logical_dims       rD   r  z2make_nditer_cls.<locals>.BaseSubIter.loop_continue  r  rF   c                      y rP  r  r  s       rD   r  z/make_nditer_cls.<locals>.BaseSubIter.loop_break  r  rF   N)rr   rs   rt   r  r  r  rI  cached_propertyr  r  r  r  r  rF   rD   BaseSubIterr    s:    		,	8 
	"	"	: 
#	:			rF   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   )rZ   r~   r>   r  s       rD   r  z2make_nditer_cls.<locals>.FlatSubIter.init_specific  s3    ''

A6D 9 9'4 HIrF   c                 r    |j                  | j                        }|j                  |j                  |g      S rP  )r?   r  r
  r   )rZ   r~   r>   r   r  r  r  s          rD   compute_pointerz4make_nditer_cls.<locals>.FlatSubIter.compute_pointer  s+    LL1E;;sxx%11rF   c                     || j                   dz
  k(  rN|j                  | j                        }t        j                  ||      }|j                  || j                         y y r  )rq   r?   r  r
   r#  r$  )rZ   r~   r>   r  r  s        rD   r  z2make_nditer_cls.<locals>.FlatSubIter.loop_continue  sM    dii!m+T__5//?eT__5	 ,rF   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 r  )	r   r   r   r$  r  rq   r?   r
   r#  )rZ   r~   r>   r  r  r  s         rD   r  z/make_nditer_cls.<locals>.FlatSubIter.loop_break  s}    a++EJJ:dDOO4		A-T__5//?eT__5	 .rF   N)rr   rs   rt   r  r  r  r  r  r  rF   rD   FlatSubIterr    s    	
	J	2	6		6rF   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 rP  )need_shaped_indexing)rZ   r~   r>   r  s      rD   r  z9make_nditer_cls.<locals>.TrivialFlatSubIter.init_specific  s    44444rF   c                 v    t        |      dk  sJ t        |             |j                  |j                  |      S r  )r   r
  r   rZ   r~   r>   r   r  r  s         rD   r  z;make_nditer_cls.<locals>.TrivialFlatSubIter.compute_pointer  s2    w<1$2c'l2$;;sxx11rF   N)rr   rs   rt   r  r  r  r  s   rD   TrivialFlatSubIterr    s    	
	5	2rF   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   rq   r
   r8  r  s         rD   r  z7make_nditer_cls.<locals>.IndexedSubIter.compute_pointer  s:    w<499,,,++GWeS,3G GrF   Nrr   rs   rt   r  r  r  rF   rD   IndexedSubIterr    s    		GrF   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 rP  )r   r  s         rD   r  z7make_nditer_cls.<locals>.ZeroDimSubIter.compute_pointer  s    88OrF   Nr  r  rF   rD   ZeroDimSubIterr    s    		rF   r  c                       e Zd ZdZd Zy)&make_nditer_cls.<locals>.ScalarSubIterz8
        Sub-iterator "walking" a scalar value.
        c                     |S rP  r  r  s         rD   r  z6make_nditer_cls.<locals>.ScalarSubIter.compute_pointer  s    JrF   Nr  r  rF   rD   ScalarSubIterr    s    		rF   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  rj   )rZ   l	factoriesrn   r  r  r  r  r  r  factoryr  r  r  r  r  r  s              rD   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
 HrF   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%dNr  rH   c                     t        |       }t        |      D ]'  }| |   |t        |      |z
  |z      k7  st        d       y )Nz2nditer(): operands could not be broadcast together)r   r9   r   )rf   
main_shaper  rn   s       rD   check_shapezBmake_nditer_cls.<locals>.NdIter.init_specific.<locals>.check_shapeV  sJ    JqAQx:c*o.AA.E#FF( *> ? ? "rF   r  r  r  r  )&r   r   r   r  r  arraysr   r   r   r
   r   r   _arrays_or_scalarsr  rq   rf   r   r   r$   noner  r   r  r  r  r  r  r   rX   r:   r9   ri   r$  r   rk   	exhaustedr  r  )rZ   r~   r>   arrtysr$  r  rn   rS  r  slotmain_shape_tyr"  main_nitemsr  r#  r  r\   r  shape_is_emptyr'  r   r  r  subiterr	  rq   r  nshapess                           rD   r  z-make_nditer_cls.<locals>.NdIter.init_specific3  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 )rF   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  FNTrH   r   )r  r
   as_bool_bitr?   r'  if_unlikelyr  r  r$  r   r%  r   _make_viewsr  r   r"  r  r!  rf   r  rI  partial_loop_continue_loop_breakr  )rZ   r~   r>   r%  r  r'  r(  r$  r   viewsr   rf   r  s               rD   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 rP  )r  r  r  r  rZ   r~   r>   r  r  s        rD   r4  z.make_nditer_cls.<locals>.NdIter._loop_continue  s@    }}==C5#++5%%gwcmm8KL %rF   c                     | j                   D ]E  }|j                  |cxk  r|j                  k  s#n &|j                  ||||j                  z
         G y rP  )r  r  r  r  r9  s        rD   r5  z+make_nditer_cls.<locals>.NdIter._loop_break  s>    }}==C5#++5NN7GS3==5HI %rF   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rP  r  rR  r   s     rD   rT  z>make_nditer_cls.<locals>.NdIter._make_views.<locals>.<genexpr>  s     (%Qq%s   )r  r  r!  r   r   r\  r   r9   r?   r
   ri   r   r  r  
_make_viewr  )rZ   r~   r>   r   r(  r$  r6  r  r  rettysrn   r  r-  r  array_indicessub_indicesr	  narraysr  r.  s                   rD   r2  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   r  N)r   )r   r   r   rq   r  ry   r   r  r  r   r   )rZ   r~   r>   r   rX  r  r  r-  rl   viewr   rf   r   s                rD   r>  z*make_nditer_cls.<locals>.NdIter._make_view  s    
 eU[[1ejjAoEE))'7GUCPC,7%%e,Wg>D#GU3H&&wuzz10M')+E((%..Q2O)+-G 4eWhMKrF   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   rj   ry   r  )	rZ   r~   r>   r(  r$  r  rn   r  r  s	            rD   r%  z2make_nditer_cls.<locals>.NdIter._arrays_or_scalars  s     A#,S-@#A<E3eU[[1HH6W//6w7>=@B C HHWT:>:; $B HrF   N)rr   rs   rt   r  rI  r  r  r  r7  r4  r5  r2  r>  r%  )
r  r  r  r  r  r	  rB  rq   r  r.  s
   rD   NdIterr    sO    	 
	"	"	 	 
#	M	8^(	+T	M
	J
	8	(	rF   rF  )rq   r	  r   r$  r  objectr
   rx   )r  r  rF  r  r  r  r  r  r	  rB  rq   r.  s   `  @@@@@@@@@rD   make_nditer_clsrH    s    
 ==D__F(//"G33dGf 86k 6@2[ 2G G  V V,,X6 Vp MrF   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
   rX   r:   r   r  r9   ri   r$  r  r1  r  r   r'  rk   rf   )rZ   r~   r>   r  r  r   r'  r  r  r  dim_is_emptyrq   s              rD   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   r  r
   r0  r?   r'  r1  r  r  r9   ri   r   rJ   r"  rk   r:   r   rf   r  r  )rZ   r~   r>   r%  r  r  r'  r  r   r?   rf   rq   s              rD   r7  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)rr   rs   rt   r  r  r7  rq   s   rD   NdIndexIterrK    s    		H,	+rF   rQ  )rq   r
   rx   )r  rQ  rq   s     @rD   make_ndindex_clsrR    s.    
 ==D5+g11(; 5+n rF   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  rX   r:   rq   r9   ri   r$  r   )
rZ   r~   r>   r  r  r  r   r  r  r  s
            rD   r  zD_make_flattening_iter_cls.<locals>.CContiguousFlatIter.init_specificB  s    ++EJJ:$66wE
 "ll=(%11$11%**ejjIKG  %UZZ0!(!5!5gw!LdF3  1 $+DL )rF   c                 b   |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$                              }|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  rS  )rq   r   r?   r  r  r  r
   r  r
  r   r   r"  r   r9   ri   rk   r{   r   r   make_anonymous_structr  r#  r$  )rZ   r~   r>   r  r  r%  rq   r   r  r(  rl   r  r   r  idxvalsidxtupler  s                   rD   r7  zH_make_flattening_iter_cls.<locals>.CContiguousFlatIter.iternext_specific[  s   zzTZZ0"..sE6B  *&&w9!++chh8C%gwsCEv~e, #',, /4Dk#; /:s $+<<0D0DWELEH1J $K /:   #; $+#5#5gw9@9N9N:?**:F$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 rP  )r
  r   r   rZ   r~   r>   r  r  r  rl   s          rD   r  z>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.getitem{  s)    kk#((UG4 '5#>>rF   c                 \    |j                  |j                  |g      }t        |||||       y rP  )r
  r   r   rZ   r~   r>   r  r  r  r  rl   s           rD   setitemz>_make_flattening_iter_cls.<locals>.CContiguousFlatIter.setitem  s(    kk#((UG47GUE3?rF   N)rr   rs   rt   r  r  r7  r  r`  r  s   rD   CContiguousFlatIterrU  =  s    +25@?@rF   rb  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rM  )r   r   r   r   rq   r
   r   rf   rX   r:   r   r  r9   ri   r$  r  r1  r  r   pointersr'  )rZ   r~   r>   r  r  r  r   rq   r  r   rf  r'  r  r  ptrptrr  rN  s                    rD   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  FTrH   r  r  )rq   r
   r   rf   r   r   rf  r   r   r   r  r0  r?   r'  r1  r  r  ri   r   r"  r9   rk   rY  r  r#  r  r  r$  r  r  r  )rZ   r~   r>   r  r  r%  rq   r  r   r   rf  r  r  is_exhaustedlast_ptrrl   r  r  rZ  r[  r  r   r   r  r  rg  	inner_dimr  s                              rD   r7  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  )rq   r
   r   rf   r   r  r9   rj   uremudivreverser  r   r	  )rZ   r~   r>   r  r  r  rq   r  r   r   r  rl   s               rD   _ptr_for_indexz:_make_flattening_iter_cls.<locals>.FlatIter._ptr_for_index  s    zz --gsyyM!..w4P #E$K0CNN7<<vc{#CD#LLs<E 1 !//#((06079 
rF   c                 H    | j                  |||||      }t        ||||      S rP  )rp  r   r]  s          rD   r  z3_make_flattening_iter_cls.<locals>.FlatIter.getitem  s+    ))'7E3N '5#>>rF   c                 L    | j                  |||||      }t        |||||       y rP  )rp  r   r_  s           rD   r`  z3_make_flattening_iter_cls.<locals>.FlatIter.setitem	  s*    ))'7E3N7GUE3?rF   N)	rr   rs   rt   r  r  r7  rp  r  r`  ra  s   rD   FlatIterrd    s%    +BC/J"?@rF   rs  )rc   r	  r
   rx   )r  r  rc   rb  rs  s    `   rD   r  r  7  sr    ****&&JCD	@'"="=j"I D	@L #"E	@w22:> E	@N rF   r  c                 >   t        t        j                  |            } || |      }||_        | j	                  |      } || ||j                  d            }|j                  | |||       |j                         }t        | |t        j                  |      |      S Nr   )r[   )	r  r   NumpyFlatTyper   ry   rh   r  r  r    )r~   r>   r  r  flatiterclsflatiterarrclsr	  s           rD   make_array_flatiterrz    s    %e&9&9%&@AK7G,HHN&F
'x'@'@'I
JC7GUC8



CWgu/B/B5/I3OOrF   c                     |j                   \  }|\  }t        |      } || ||      }|j                  }| j                  |      }	 |	| ||j                        }
|j                  | |||
|       y rK  )r   r  rc   ry   r   r7  )r~   r>   r\   r   r%  r  rx  rw  r  ry  r  s              rD   iternext_numpy_flatiterr|     sq     88LZJX%j1K7G8<H!!E&F
'
8CwVDrF   c                    |j                   d   }|\  }}t        |      } || ||      }|j                  }| j                  |      }	 |	| ||j                        }
|j                  | |||
|      }t        | ||j                  |      S Nr   r  )r   r  rc   ry   r   r  r    r   )r~   r>   r\   r   r  rx  r  rw  r  ry  r  r	  s               rD   iternext_numpy_getitemr  0  s    !JOHe%j1K7G8<H!!E&F
'
8C


7GUC
?CWgsDDrF   c                    |j                   d   }|\  }}}t        |      } || ||      }|j                  }	| j                  |	      }
 |
| ||j                        }|j                  | ||	|||       | j                         S r~  )r   r  rc   ry   r   r`  rq  )r~   r>   r\   r   r  rx  r  r  rw  r  ry  r  s               rD   iternext_numpy_getitem_anyr  @  s     !J!HeU%j1K7G8<H!!E&F
'
8CWguc5%@""$$rF   c                     |j                   d   }t        |      } || ||d         }| j                  |j                        } || ||j                        }|j
                  S r~  )r   r  ry   rc   r   r   )	r~   r>   r\   r   r  rw  rx  ry  r  s	            rD   iternext_numpy_getitem_flatr  Q  s]    !J%j1K7G47;H
 5 56F
'
8C::rF   c                 P   |j                   \  }|\  }t        t        j                  |            } || |      }||_        | j                  |      } || ||j                  d            }|j                  | |||       |j                         }	t        | ||j                  |	      S ru  )r   r  r   NumpyNdEnumerateTyper   ry   rh   r  r  r    r   )
r~   r>   r\   r   r  r  	nditerclsr  ry  r	  s
             rD   make_array_ndenumerater  \  s    XXFEDC*5+E+Ee+LMIw(FFL&F
'v'>'>w'G
HC
'5#6



CWgsDDrF   c                     |j                   \  }|\  }t        |      } || ||      }|j                  }| j                  |      }	 |	| ||j                        }
|j                  | |||
|       y rK  )r   r  rc   ry   r   r7  )r~   r>   r\   r   r%  r  r  r  r  ry  r  s              rD   iternext_numpy_nditerr  n  sq     JXHV*84Iwv6FE&F
'
6C
Wguc6BrF   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   rR  NumpyNdIndexTyper   r  r  r    r   )
r~   r>   r\   r   argtyr  rf   r  r  r	  s
             rD   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   rq   r   r|   r
   r   r   r   r   rR  r  r   r  r  r    )r~   r>   r\   r   rq   r   rY  rf   r   r  r  r	  s               rD   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 rK  )r   rR  r7  )r~   r>   r\   r   r%  r  r  r  s           rD   iternext_numpy_ndindexr    s@     JXHV *Iwv6F
Wgv6rF   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   r\  r
   r   rH  r  r  r    )	r~   r>   r\   r   r  r(  r$  r  r	  s	            rD   make_array_nditerr    s    
 H__F#((1+u/%%gtAw7q'&_X&w8F
'66:



CWgx==rF   c                 v    |j                   \  }|\  } t        |      | ||      }|j                  | ||       y rK  )r   rH  r7  )r~   r>   r\   r   r%  r  r  s          rD   iternext_numpy_nditer2r    s=     JXHV&_X&wvFF
Wgv6rF   c                     |j                   \  }}t        j                  t        j                  d      t	        ||k(              }t        | ||j                  |      S r  )r   r   r   ro  r   r"   r   )r~   r>   r\   r   arg1arg2r	  s          rD   dtype_eq_implr    sE    JD$
++bjjmS%6
7CgwEErF   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.
    rH   r   r  r   Nr  r  z3Don't know how to allocate array with layout '{0}'.Fri  )z[array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.rX  r  )+ry   r{   r|   r   r   r   r   r   r   ro  smul_with_overflowrc  r  rq   r	  r  rj   r   r   rS   r   r   rk  rl  r   get_preferred_array_alignmentuint32rq  MemInfoPointervoidptrTypeRefr:   r$   r  _call_allocatorr  meminfo_datar   r
   rk   r   r>  r  )r~   r>   ra  r  r  r  datatyper   arrlenoverflowr   arrlen_multr   dimension_sizeallocsize_multrE  r|   	align_valr   r   miparytypeclassargtypesr   r   r   shape_arraystrides_arrays                               rD   r  r    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 rP  )intrin_alloc)clsrE  r   s      rD   r   z _ol_array_allocate.<locals>.impl,  s    Iu--rF   r  )r  rE  r   r   s       rD   _ol_array_allocater  '  s    
.KrF   c                 &    | j                  ||      S )z9Trampoline to call the intrinsic used for allocation
    )r  )ra  r   r   s      rD   r  r  1  s     T5))rF   c                 p    d }t        j                  t         j                        }t        |||      }||fS )z3Intrinsic to call into the allocator for Array
    c                 J    |\  }}| j                   j                  |||      }|S rP  )r  meminfo_alloc_aligned)r~   r>   r$   r   rE  r   r   s          rD   rj  zintrin_alloc.<locals>.codegen;  s)    !E++33GYNrF   )r   r  r  r$   )rk  rE  r   rj  r  r\   s         rD   r  r  7  s5    
 

u}}
-C
CE
*C<rF   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 maintainedrH   >Fri  )z#Cannot safely convert value to intpN)r   r   r   rI   r   ro  r   sextr  r   rk  rl  r   trunc)
r~   r>   src_trD  r   
intp_widthintp_irmaxvalr	  	is_largers
             rD   safecast_intpz#_parse_shape.<locals>.safecast_intpI  s    ''

3\\
**Z('Q*q.%8A$=?;;#,,sG,C 
 [[J&++Cf=I59!!11Z< :
 {{Z'mmC1 
 
 :9s   ."C??DrH   r  r   r  )znegative dimensions not allowedN)r   r   r   r   r   r\  r   r
   r   rj   r:   get_constant_genericr9   r  r1  rk  rl  r   )r~   r>   rS  r   r  rq   passed_shapesr  r   r  r  is_negs               rD   _parse_shaper  E  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>   r\   r   arrshapetypearrshapera  s          rD   _parse_empty_argsr  u  s9     88A;LAwHooGL'<JJJrF   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  r  )
r   r   r   r   ry   r
   r   rf   rq   r   )r~   r>   r\   r   arytyper  r  s          rD   rh  rh    sr    
 hhqkG'5;;'!j!'7$q'B%%gsyyM&&""rF   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   )fnamer|   r   s      rD   _check_const_str_dtyper    s7    %**+ugMN  %% ,rF   c                 <    |j                   } ||||      }d }||fS )Nc                 `    t        | |||      \  }}t        | |||      }|j                         S rP  )r  r  r  r	  r>   r\   r
  ra  r  r  s          rD   rj  znumpy_empty_nd.<locals>.codegen  s2    +E7CHUGWf=}}rF   instance_type)r  ty_shapety_dtypety_retty_refty_rettyr\   rj  s          rD   numpy_empty_ndr    s,    ))H
8X|
4C <rF   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 rP  )r  )rf   r|   rX  s     rD   r   zol_np_empty.<locals>.impl  s    !%66rF   z.Cannot parse input types to function np.empty(r  r  )r  floatr   r   Function
typing_keyr   doublety_parse_dtypety_parse_shaper   r	   r   )rf   r|   nb_dtyperq   r   r   rX  s         @rD   ol_np_emptyr    s    7E*	E5>>	*u/?/?5/H<<!%(% D 0(cB# 	7>ugRwaP  %%rF   c                 <    |j                   } ||||      }d }||fS )Nc                 `    t        | |||      \  }}t        | |||      }|j                         S rP  )rh  r  r  r  s          rD   rj  z$numpy_empty_like_nd.<locals>.codegen  s2    0fMUGWf=}}rF   r  )r  ty_prototyper  r  r  r\   rj  s          rD   numpy_empty_like_ndr    s,    ))H
<<
8C <rF   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 )Nr  r^  r   F)r|   r	  rf  r   z3Cannot parse input types to function np.empty_like(r  r  c                     t        | |      S rP  )r  )r  r|   rX  s     rD   r   zol_np_empty_like.<locals>.impl  s    "3u55rF   rP  )r  r   r  r   r   r   r|   r	  r`  r	   r   )r  r|   r  r	  r   r   rX  s         @rD   ol_np_empty_liker    s    </u!%(	C	%99c5;;'#&::#4SZZ#FHH8FUHKEKK!S1E  #uBugQ0  %%6KrF   c                 :    t        j                  |      }d }||fS )Nc                      t        |j                  d         | ||d         }t        j                  ||j                  |j                  |j                  |j                        d       y r   )ry   r   r
   ri  r   r   r   r   )r	  r>   r\   r
  r  s        rD   rj  z(_zero_fill_array_method.<locals>.codegen  sO    %j!%eWfQi@w'++cllCJJ*O	rF   )r   r&  )r  rZ   r\   rj  s       rD   _zero_fill_array_methodr    s!    
**T
C <rF   
_zero_fillc                     d }|S )z?Adds a `._zero_fill` method to zero fill an array using memset.c                     t        |        y rP  )r  rv  s    rD   r   z ol_array_zero_fill.<locals>.impl  s
    %rF   r  )rZ   r   s     rD   ol_array_zero_fillr    s    &KrF   c                 0    t        d|       t        fd}|S )Nrm  c                 T    t        j                  | |      }|j                          |S Nr  )r~  r  r  )rf   r|   r  s      rD   r   zol_np_zeros.<locals>.impl  s!    hhuE*
rF   )r  r  rf   r|   r   s      rD   ol_np_zerosr    s    7E*  KrF   c                 &    t        d|       dd}|S )N
zeros_likec                 T    t        j                  | |      }|j                          |S r  )r~  r  r  )r  r|   r  s      rD   r   zol_np_zeros_like.<locals>.impl  s!    mmAU+
rF   rP  r  r  s      rD   ol_np_zeros_liker    s    </ KrF   c                 &    t        d|       dd}|S )N	ones_likec                     t        j                  | |      }|j                  }t        t	        |            D ]  }d||<   	 |S Nr  rH   r~  r  r  r9   r   )r  r|   r  arr_flatr   s        rD   r   zol_np_ones_like.<locals>.impl	  s<    mmAU+88X'CHSM (
rF   rP  r  r  s      rD   ol_np_ones_liker    s    ;. KrF   c                 ^    t        d|       t        |      st        |      n|dfd	}|S )Nfullc                     t        j                  |       }|j                  }t        t	        |            D ]  }|||<   	 |S rP  r~  r  r  r9   r   )rf   
fill_valuer|   r  r  r   r  s         rD   r  zimpl_np_full.<locals>.full  s=    hhuh'88X'C&HSM (
rF   rP  )r  r   r  )rf   r	  r|   r  r  s       @rD   impl_np_fullr
    s0    65)u!%( KrF   c                 &    t        d|       dd}|S )Nr  c                     t        j                  | |      }|j                  }t        t	        |            D ]  }|||<   	 |S rP  r  )r  r	  r|   r  r  r   s         rD   r  z$impl_np_full_like.<locals>.full_like'  s<    mmAu%88X'C&HSM (
rF   rP  r  )r  r	  r|   r  s       rD   impl_np_full_liker  #  s    ;. rF   c                 &    t        d|       dd}|S )Nonesc                     t        j                  | |      }|j                  }t        t	        |            D ]  }d||<   	 |S r  r  )rf   r|   r  r  r   s        rD   r   zol_np_ones.<locals>.impl7  s<    hhuE*88X'CHSM (
rF   rP  r  r  s      rD   
ol_np_onesr  1  s     65) KrF   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  )r~  rm  r9   )r  r|   r  rn   r  s       rD   r  z"impl_np_identity.<locals>.identityH  s7    hh1vx(qAC1I 
rF   rP  )r  r   r  r   r  )r  r|   r  r  s      @rD   impl_np_identityr  @  s4    :u-u!%(<<
 OrF   c                      y rP  r  NMs     rD   _eye_none_handlerr  P  r  rF   c                 J    t        |t        j                        rd }|S d }|S )Nc                     | S rP  r  r  s     rD   r   z$_eye_none_handler_impl.<locals>.implW      HrF   c                     |S rP  r  r  s     rD   r   z$_eye_none_handler_impl.<locals>.implZ  r  rF   )r   r   rK  )r  r  r   s      rD   _eye_none_handler_implr  T  s&    !U^^$	
 K	KrF   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 )Nr|   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  r~  rm  r  r9   )	r  r  r   r|   _Mr  drn   r  s	           rD   r   znumpy_eye.<locals>.implj  s    q!$hh2w#6ArAvA1X !Aq1uH  
 AE2A1X !AE1H 
rF   )
r   r   rK  r~  r|   r  	DTypeSpecr  r   r  )r  r  r   r|   r   r  s        @rD   	numpy_eyer%  _  sn     }
5%..9XXe_	EEOOU\\:	;geWe45XXe_!5  KrF   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)rH   ro  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  )
rq   rf   r  r~  rm  r|   r9   r  r  r  )r   r   r   r  rl  rn   rowscolss           rD   	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 &
rF   r   )r   r	   r   r   r   r   rq   NumbaTypeError)r   r   r+  s      rD   impl_np_diagr-  y  sZ    A  !FGG!U[[!66''(BCC	6 ? "rF   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   rH   )r~  r  r  arangerd  r0   )
dimensionsr	  rn   r  r   r  rf   s        rD   r   znumpy_indices.<locals>.impl  ss    hhtj(9C))Crxx088eQ,C CFFA  
rF   )r   r   r  r	   r   r|   r   r   )r1  r   r   r  rf   s      @@rD   numpy_indicesr2    so    j%..1E  %%j&&6E  %%JA1HE
 KrF   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   )	r~  r  rl  r   r  rm  r|   maximumr9   )	r   r   r   abs_kr  r	  rn   jts	            rD   r   znumpy_diagflat.<locals>.impl  s    JJqMGGIFAIhh1vqww'JJq1"JJq!qA !!CAq1u  
rF   r   )r   r	   r   r   r   r   r   )r   r   r   r   s       rD   numpy_diagflatr9    sU    A3  %%a#u}}-.3  %% KrF   c                 n   |dv sJ |dk(  r4d}t        d|       D ]"  }d|z  }|d| ddj                  |       d	z  }$ n3d
}t        d|       D ]"  }d|z  }|d| ddj                  |       dz  }$ t        j                  |      }t	        |t                      t               d|    }t        |      S )N)r  r`  r  zv
            def _getitem(a, idx, axis):
                if axis == 0:
                    return a[idx, ...]
        rH   ):z
                elif axis == z:
                    return a[r  z, idx, ...]
            z|
            def _setitem(a, idx, axis, vals):
                if axis == 0:
                    a[idx, ...] = vals
        z:
                    a[z, idx, ...] = vals
            r  )r9   r  textwrapdedentexecglobalsr&   )rq   r  rK  rn   lsts        rD   "generate_getitem_setitem_with_axisrA    s    ))))y
 q$A1*C S !"iin- . B   q$A1*C S !yy~& ' B   
	BWY	Qtf:	BBrF   takec                   	 t        j                  |      rt        | t        j                        r t        |t        j
                        rdd}|S t        | t        j                        r1t        |t        j                        r|j                  dk(  dfd	}|S t        | t        j                        r1t        |t        j                  t        j                  f      rdd}|S y y t        | t        j                        rBt        |t        j
                        r(d| j                  dz
  z  	t        	fd       dfd	}|S t        | t        j                        rgt        |t        j                  t        j                  t        j                  f      r-| j                  }t        |d	      t        |d
      dfd	}|S y y )Nc                     || j                   dz
  kD  s|| j                    k  rt        d      | j                         |   S )NrH   Index out of bounds)r   
IndexErrorrl  )r  r   r   s      rD   	take_implznumpy_take.<locals>.take_impl   s<    affqj)Ww->$%:;;wwy))rF   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   rH   rE  )
r~  r  r   r|   r`  r  rl  rF  rd  rf   )
r  r   r   rl  walkeritrn   r  rX  F_orders
            rD   rG  znumpy_take.<locals>.take_impl	  s    hhw||177;$\\^F$FYYv&wwyAAFFQJ'1w;()>??!!WCFAA	 
 {{7==11rF   c                 X    t        j                  |      }t        j                  | |      S rP  )r~  r   rB  )r  r   r   converts       rD   rG  znumpy_take.<locals>.take_impl  s!    ((7+wwq'**rF   r   rH   c                 J   t              }d}|t        | j                        k  r| j                  |   dk(  sJ | j                         t        t        | j                              D ])  }| j                  |   }||k7  st	        |||      }|dz  }+ | j                  |      S r  )r   r   rf   r9   r0   rd  )r  r   rY  r7  r   r   r8  s         rD   _squeezeznumpy_take.<locals>._squeeze'  s    Ahc!''l*qwwt}/AJ177JA QWW.CAd{+CA6Q	 /
 yy~%rF   c                     t        j                  | |f|      }| j                  dk(  r|d   S |dk  r|| j                  z  } ||      S )Nr|  rH   r   )r~  rB  rq   )r  r   r   r  rO  s       rD   rG  znumpy_take.<locals>.take_impl3  sN    GGAz566Q; Q4K!8AFFND4((rF   r  r`  c                 z   |}|dk  r|| j                   z  }|dk  s|| j                   k\  rd| d| j                    }t        |      t        | j                  |t	        |            }t        j                  || j                        }t        t	        |            D ]  } 	| ||   |      } 
||||        |S )Nr   zaxis z) is out of bounds for array of dimension r  )	rq   r   r0   rf   r   r~  r  r|   r9   )r  r   r   r   r   rf   r
  rn   rY  _getitem_setitems            rD   rG  znumpy_take.<locals>.take_implJ  s    !8AFFND!8tqvv~"2$ '++,66(4C$S/)%aggtS\BhhuAGG4s7|,A GAJ5AS!T1- - 
rF   rP  )r
   r   r   r   r   r   r	  r  r\  rq   r&   rA  )
r  r   r   rG  rq   rK  rR  rS  rO  r8  s
        @@@@@rD   
numpy_takerT    sb    4 a%*Wemm*L* a%*Wekk*Jnn+G2 a%7UZZ$AB+ 	 C & a%*Wemm*L
#A
 	& 	&) a%7U[[%**eoo$NO66D9$	JH9$	JH  / P &rF   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rP  r"  rR  r  s     rD   rT  z _arange_dtype.<locals>.<genexpr>`  s     
8A:a'rU  c              3   P   K   | ]  }t        |t        j                           y wrP  )r   r   FloatrW  s     rD   rT  z _arange_dtype.<locals>.<genexpr>b  s     8AZ5;;'rU  zint%sr  )r   r   rK  rV  
complex128r   r  r~  r|   r   r   	unliteralr  )r   r  boundsr|   NPY_TYrX  unliteral_boundss          rD   _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 )NrH   r   zMaximum allowed size exceededT)r   r   mathceilr(  r*  r  r  r~  r  r9   )r4  r  r  r|   	lit_startlit_stoplit_step_step_start_stopnitems_cnitems_rnitems_ir   r  r   rn   start_value
step_value
stop_value
true_dtypeuse_complexs                    rD   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 
rF   r  )r   r   Optionalr:   r&  r  rK  r$  r_  r|   rV  r#  r  )r4  r  r  r|   rX  r   rm  rn  ro  rp  rq  s         @@@@@rD   	np_arangers  w  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rP  )r   r   r  r$  s     rD   rT  z!numpy_linspace.<locals>.<genexpr>  s     Fz#u||,rU  r   c              3   P   K   | ]  }t        |t        j                           y wrP  r"  r$  s     rD   rT  z!numpy_linspace.<locals>.<genexpr>  r%  rU  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   rH   r  )r~  r  divider9   )	r4  r  r  r  divdeltar  rn   r|   s	           rD   r  z numpy_linspace.<locals>.linspace  s    hhsE" cz!8JAg75LE99UC(D1c]!d(+A # CF7CG
rF   r  )
r  r   r   r   r   r	   r   rV  rZ  r   )r4  r  r  r   r  r|   s        @rD   numpy_linspacer{    ss    FFFcC/05  %%

CeT]
CC  , OrF   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  rH   r   N)r   ry   r
   r   rf   r   r  r   r	  
raw_memcpyr   r   r   r   r   r   rC  r  r$  r?   r!   r  )r~   r>   r\   r   r  r  r  rettyperl  r7  r  r9  r  r   r   r/  rF  s                    rD   _array_copyr    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	  rf  )r   r   r   r	  r`  r  )rk  r  r	  rl  r\   s        rD   _array_copy_intrinsicr    sM    a%%%HHOSF
&&&
/C
a&CrF   z
array.copyc                     t        | |||      S rP  )r  r  s       rD   
array_copyr    s    wd33rF   c                     t        |       st        j                  d      t        | t        j
                        rd }|S d }|S )Nrj  c                     t        |       S rP  )r  r  s    rD   
numpy_copyz#impl_numpy_copy.<locals>.numpy_copy  s    (++rF   c                 ,    t        j                  |       S rP  )r~  r  r  s    rD   r  z#impl_numpy_copy.<locals>.numpy_copy   s    ::a= rF   )r   r	   r   r   r   r   )r  r  s     rD   impl_numpy_copyr    sL    A   "1 2 	2 !U[[!	, 	! rF   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 layoutrH   r  r  r  r^  r   N)r   r   r	  rq   ry   r  r   r  r   r  r   r   r   r   r   r    r  r   r   rW  r-  blockr  phir:   add_incoming)r~   r>   r\   r   output_layoutrX  r   r  rl  rf   r   
check_funcr6  thenorelseout_thenthen_blk
out_orelse
orelse_blkret_phis                       rD   _as_layout_arrayr  &  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      d      } ||      }|fdfS )NrH   F)r	  rq   rf  c                 8    t        | |||j                        S )N)r  )r  r   )r  r  r   r  r  s       rD   r  z,_as_layout_array_intrinsic.<locals>.<lambda>s  s    #3	1a-"="=$?rF   )	r   r   r%   r	   RequireLiteralValuer`  r   r  rq   )rk  r  r  rl  r\   s     `  rD   _as_layout_array_intrinsicr  g  sr    mU%8%89((77 &&**^  C a
C ? ? ?rF   c                     t        |       st        j                  d      t        | t        j
                  t        j                  f      rd }|S t        | t        j                        rd }S )Nrj  c                 R    t        j                  t        j                  |             S rP  )r~  ascontiguousarrayr   r  s    rD   r   z%array_ascontiguousarray.<locals>.impl}  s    ''44rF   c                     t        | d      S Nr   r  r  s    rD   r   z%array_ascontiguousarray.<locals>.impl      -a55rF   r   r	   r   r   r   r  r  r   r  s     rD   array_ascontiguousarrayr  w  sY    A  !FGG!ellEMM34	5
 K 
Au{{	#	6KrF   c                     t        |       st        j                  d      t        | t        j
                  t        j                  f      rd }|S t        | t        j                        rd }|S y )Nrj  c                 R    t        j                  t        j                  |             S rP  )r~  asfortranarrayr   r  s    rD   r   z"array_asfortranarray.<locals>.impl  s    $$RXXa[11rF   c                     t        | d      S )Nr  r  r  s    rD   r   z"array_asfortranarray.<locals>.impl  r  rF   r  r  s     rD   array_asfortranarrayr    sZ    A  !FGG!ellEMM34	2	Au{{	#	6 
$rF   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r~  )r   ry   r
   r   rf   r   r  r   r   r   r   r   rC  r  r	  r   r   r|   r   r!   r  )r~   r>   r\   r   r  r  r  r~  rl  r7  r  r9  r  r   r   r/  rF  items                     rD   array_astyper    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                 ^    t        |t        j                        sJ t        |      }d }||fS )Nc           
         |j                   \  }t        |      } || ||d         }|j                  }|j                  ||j                        }t        | ||      }	|j                  rV|j                  dk(  rGt        j                  ||	j                  |j                  |j                  |       |	j7                         S t        j                  ||j                        }
t        j                  ||j                        }|j                  }| j                  t        j                         }t        j"                  ||dd      }t        j$                  ||
|      5 }t        j&                  | ||j                  |
|||      }|j)                  ||	j                  j*                        }|j-                  |      }|j/                  |	j                  |g      }t        j0                  ||||       |j3                  |j5                  ||      |       d d d        |	j7                         S # 1 sw Y   |	j7                         S xY w)Nr   r   byteptrT)namerP   )r   ry   r   r   r   r.   r:  r	  r
   r}  r   r   rf   r   r   r   r   rX   rC  r  r>  r:   r?   r
  r  r$  r  r  )r~   r>   r\   r   rS  r  r  r   r1  bstrrf   r   r	  r   byteidxr   rl   srcptrr   destptrs                       rD   rj  z)_array_tobytes_intrinsic.<locals>.codegen  s   xx2GWd1g.<<Xszz2#GWf=NNryyC/w		388SZZ'). ~~) ((#))<E**7CKK@GYYF++EJJ7F))itG ""7E6:g//Wchhw !diinn=ll7+!++dii#7wBgkk#x8'B ; ~~ ; ~~s   B4H%%H=)r   r   r   r/   )rk  r  r\   rj  s       rD   _array_tobytes_intrinsicr    s1    a%%%
Q-C" F <rF   r  c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S rP  )r  rz  s    rD   r   z impl_array_tobytes.<locals>.impl  s    +C00rF   rQ  r{  s     rD   impl_array_tobytesr    s    #u{{#	1 $rF   c                 @    |j                   } ||||||      }d }||fS )Nc           	         |j                   d   }|d   }|d   }|j                  } t        |      | ||d         }t        |      }	 |	| |      }
|
j                  }t	        | |      }t        |j                  j                  |      }|j                  |j                  |j                        }|j                  ||      }|j                  ||      }|j                  d|t        j
                  |j                  d            }d}|j                  |d      5  | j                  j                  |t         |f       d d d        |j                  d|t        j
                  |j                  d            }|j#                  ||      }t%        j&                  ||      }|j                  |d      5  d	}| j                  j                  |t         |f       d d d        |j)                  |      5 \  }}|5  |j*                  }|j-                  ||      }d d d        |5  |j*                  }d d d        d d d        |j/                  |j                        }|j1                         |j1                  |       |j                  ||      }|j3                  d
||      }|j                  |d      5  d}| j                  j                  |t         |f       d d d        t%        j4                  ||g      }t%        j4                  ||g      }|j7                  |j8                  |g      }|j;                  || j=                  |j?                  d                  }tA        |
|||||jB                  |jD                         |
jG                         } tI        | ||j                  |       S # 1 sw Y   mxY 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# 1 sw Y   xY w)Nr   ro  r:  r  r  z=offset must be non-negative and no greater than buffer lengthFri  z.buffer size must be a multiple of element sizer  z%buffer is smaller than requested sizer   rE  )%r   r   ry   r   r   r   r   r:   r   r   r  r  r   r   rk  rl  r   sremr
   is_not_nullr-  basic_blocksdivr  r  r  rk   r
  r   r>  r   r   r   r   r   r  r    )!r~   r>   r\   r   bufty	arg_count
arg_offsetr   r  
out_ary_tyout_aryout_datamodelr   ll_itemsizer1  ll_offset_sizenbytes_is_negativer   ll_count_is_negativeremis_incompatible
then_block
else_blockbb_if	num_wholebb_elsell_itemcountll_required_sizeis_too_largerf   r   r   r	  s!                                    rD   rj  znp_frombuffer.<locals>.codegen  sn   G	!W
jQ@&
Wg.**/s||00(;SZZ6 Z=V^4$00KK	*
 N__/_>--gzC6J ?  '22KK	* 
 ll6;/!--gs;___U_;BC--gzC6J <
 __126Nz:++#LL=	  !-- 	 3 {{9>>2!!)U3!!)W5 #;;|[A,,S2BFK__\%_89C--gzC6J 9
 ""7\N;$$W{m<{{388j\2'(()?)?)GH
 	w "& +"{{!jj	* ! '3??CHHm ?> <;  	 32 98s`   #N'0%N4.O4O
OO*O1%O('N14N>O	OO	OO%(O2r  )	rk  bufferr|   r   r  rX  rS  r\   rj  s	            rD   np_frombufferr    s3    			B
VUE65
1CNI` <rF   r  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        d	d
ffd	}|S )N
frombufferr   z+Argument "buffer" must be buffer-like. Got rH   )r|   rq   r	  rf  z3Cannot parse input types to function np.frombuffer(r  r  r  r   c                 "    t        | |||      S rP  )r  )r  r|   r   r  rX  s       rD   r   z impl_np_frombuffer.<locals>.implU  s    VUE65AArF   )r  r   r   r  r	  r	   r   r  r  r  r   r  r  r   rB  )r  r|   r   r  r   r  r   rX  s          @rD   impl_np_frombufferr  >  s    </fell+v}}/C;F8D  %%u~~.53C3Cu3L<<!%((3)/%79  &xr%3  %% 1 B KrF   c                     t        |      rt        dd       dfd	}|S t        |t        j                        rt        d|      dfd	}|S y )Nr   c                      | |      S rP  r  rl   rf   r|   intrinsic_cfarrays      rD   r   zimpl_carray.<locals>.impl`      $S%00rF   c                      | |      S rP  r  r  s      rD   r   zimpl_carray.<locals>.implf  r  rF   rP  r   get_cfarray_intrinsicr   r   r$  rl   rf   r|   r   r  s       @rD   impl_carrayr  [  L    51#t<	1	E5??	+1#u=	1 
,rF   c                     t        |      rt        dd       dfd	}|S t        |t        j                        rt        d|      dfd	}|S y )Nr  c                      | |      S rP  r  r  s      rD   r   zimpl_farray.<locals>.implp  r  rF   c                      | |      S rP  r  r  s      rD   r   zimpl_farray.<locals>.implv  r  rF   rP  r  r  s       @rD   impl_farrayr  k  r  rF   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   r  r   CPointerr|   r	   r,  r$  r  r   r$   
np_cfarray)rk  rl   rf   	ptr_dtyper   r|   rq   rX  r\   dtype_r	  s            rD   r  z0get_cfarray_intrinsic.<locals>.intrinsic_cfarray|  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rF   r)   )r	  r  r  s   `` rD   r  r  {  s     > rF   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(...).
    Nro  r  r  r  )r   r   r	  ry   r   r
   r   r   r   r\  r   r   r   r   rj   r   r  ro  r>  r{   r|   r  r   r  r!   )r~   r>   r\   r   r6  r  rl   rf   r   r  r   r  r  rN  r  offr   r   r   r	  s                       rD   r  r    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 rP  )	r   r   r\  r   r   r   r  rR   r$   )r~   r>   seqtyseqr  s        rD   _get_seq_sizer    sj    %)##EJJE
;;	E5>>	*''Yuzz5-JK#((qrF   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 rP  )r  r  decref)r>   r   rl  r~   r  rX  s      rD   wrapz$_get_borrowing_getitem.<locals>.wrap  s3    7D)KKws3
rF   )r|   rR   r  r  r$   r   r   )r~   r  r  r  rX  s   `  @@rD   _get_borrowing_getitemr    sC     KKE''(8(8(1%

(KML KrF   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   r\  r   rc  r  r|   )r  r  r  r>   r~   r  s      rD   get_first_itemz.compute_sequence_shape.<locals>.get_first_item  sa    eU__-5zQ!Qx!6!6sA!>>>1'5AL;;WsDk BBBrF   )r   r   r   r   r9   rj   r  r   )r~   r>   rq   r  r  r   r  r  innertyinnerrn   r  s   ``         @rD   compute_sequence_shaper     s     ##EJJ/FFADC FCUG4[q5+GU;NGUmGWguEF 
 =rF   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)rk  rl  r   )r>   r~   s   rD   _failz#check_sequence_shape.<locals>._fail  s    ))':*J	LrF   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   rh  Fri  rH   )r   r  r  r   r   r   r  r  r
   r  r|   r  r\  r9   rc  )r  r  r  r   expectedrV  r  r  r  r  rn   r  r>   check_seq_sizer~   s              rD   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Nr  )r~   r>   r  r  r  r  r  s   ``   @@rD   check_sequence_shaper    s    
L: 5#v&rF   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   r|   r   )
r   r_  r   rl   r  r>   r~   r   r  r   s
       rD   assign_itemz-assign_sequence_to_array.<locals>.assign_item<  sQ    ''$(-g%Qll7C<7GUC5rF   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  r\  r  r
   r  r|   r  r9   rc  r   r   )r  r  r  r   r   r  r  r  r  rn   r  assignr
  r>   r~   s              rD   r  z(assign_sequence_to_array.<locals>.assignB  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r  Nr  )
r~   r>   r   r  r   r  r  r  r  r
  s
   ``````  @@rD   assign_sequence_to_arrayr  5  s"    6 62 5#vr"rF   c                     t        | |      \  }}t        |      r|}nt        |      }|y t        j                  ||d      S r  )r5   r   r  r   r   )rk  rG  r|   rq   	seq_dtypes        rD   np_array_typerr  ^  sD    ,Y?OD)5u%=;;udC((rF   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   rq   r   r   r   r  r  r  r   r   r!   r  )
r~   r>   r\   r   r  rq   r  r  r  r  s
             rD   rj  znp_array.<locals>.codegeno  s    zz1g'$sK6{d"""Wguc6BWguf= '388V!$eUC	A  #// #1 	1rF   )r  r  )rk  objr|   rl  r\   rj  s         rD   np_arrayr  i  s6    7E*
C
/C
c5/C1" <rF   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 rP  )r  )rG  r|   s     rD   r   zimpl_np_array.<locals>.impl  s    &&rF   rP  )r  r   r	   r   r   r  )rG  r|   r   r   s       rD   impl_np_arrayr    s^    7E*F#   "1 2 	2u."7"?J  %%'KrF   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  Fri  z%s(): axis out of bounds)	r:   r  r  r  r  r   rk  rl  rF  )
r~   r>   r   rq   r   r  ll_ndimis_neg_axisaxis_out_of_boundsr   s
             rD   _normalize_axisr    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).
    rH   r  r   r   r   r  r
   r   rX   r9   r  r  r  r$  ri   r   r?   )r~   r>   
orig_shaperq   r   ll_shtyr  r9  r  ll_dim
after_axisrA  r   s                rD   _insert_axis_in_shaper#    s    z?dQh&&&ll7>>40G  '2F
..
C TAX$((vt<
_nnZ$[[5#% 	b'..w3GH  MM#w++GVQEFf)=>>rF   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.
    rH   r   r  r  )r~   r>   orig_stridesrq   r   r   r   r9  r  r  r!  r"  r   s                rD   _insert_axis_in_stridesr&    s    |q(((ll7>>40G!!'73G
..
C>>!D TAX$((vt<
nnZ$[[5#% 	l3'**7GQD	F  MM$,,Wgq$GHg)>??rF   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  rE  )r   rq   r   ry   r
   r   rf   r   r#  r&  r   r   r   r   r   r  )r~   r>   r\   r   r   rX  rq   r  r  rl  r  r   
new_shapesnew_stridess                 rD   expand_dimsr*    s     OOE::DHHQKE
*U
GWDG
<C
*U
GW
-C!!'3995F""7CKK8G&wtLJ)'7GT4PK3#&LL;;**& ==?rF   c                     |j                   dk  r|j                  nd}|j                  |j                   dz   |      } |||      }d }||fS )NrH   r^  r_  c                     | j                  ||d   |j                  d   t        j                        }t	        | |d|j
                  j                  |      }t        | ||||      }t        | ||j
                  |      S )NrH   znp.expand_dims)	r   r   r   r   r  r   rq   r*  r    )r~   r>   r\   r   r   rl  s         rD   rj  znp_expand_dims.<locals>.codegen  so    ||GT!Wchhqk5::Fw1A"33T; '7Ct< '3??CHHrF   )rq   r	  r`  )rk  r  r   r	  rl  r\   rj  s          rD   np_expand_dimsr-    sN    1QXX#F
&&affqj&
0C
a,CI <rF   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 rP  )r-  )r  r   s     rD   r   z!impl_np_expand_dims.<locals>.impl  s    a&&rF   )r   r   r   r	   r   r   )r  r   r   r   s       rD   impl_np_expand_dimsr0    sb    a%9!=  %%dEMM*8?  %%'KrF   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 )NrP  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>   r\   r   	transformarrsr  r  rX  retsrl  r(  r  minimumr?  s              rD   rj  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rH   r   )	r`  r  rq   r$   r   r   r  StarArgTuple
from_types)typingcontextr   r  rj  r(  r?  r  r8  s       @@rD   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 rP  r  )r   r   s    rD   r  z_atleast_nd.<locals>.<lambda>1  s	    trF   r  )r8  r  r   s   ``@rD   _atleast_ndr=    s    G G( %$rF   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 )NrH   rP  )r9   rq   r
   r   r`  r*  r   r$   )r~   r>   r  r  rX  rn   rq   r   newarrtyr  min_ndims            rD   r5  z(_atleast_nd_transform.<locals>.transform;  s    xAq5DzzD ~~d1g. ::5::>::!'7"("2"28U"CcV"&( ! ! 
rF   )r   )rA  r  r5  s   `` rD   r4  r4  4  s$    
 s4y    rF   c                  B    t        d | D              rt        ddg      S y )Nc              3   P   K   | ]  }t        |t        j                           y wrP  rQ  r$  s     rD   rT  z np_atleast_1d.<locals>.<genexpr>M       
84C:c5;;'4rU  rH   r   r  r=  r  s    rD   np_atleast_1drF  K  s$    

84
881qc"" 9rF   c                  D    t        d | D              rt        dddg      S y )Nc              3   P   K   | ]  }t        |t        j                           y wrP  rQ  r$  s     rD   rT  z np_atleast_2d.<locals>.<genexpr>S  rD  rU  ro  r   rE  r  s    rD   np_atleast_2drI  Q  s&    

84
881q!f%% 9rF   c                  D    t        d | D              rt        dg d      S y )Nc              3   P   K   | ]  }t        |t        j                           y wrP  rQ  r$  s     rD   rT  z np_atleast_3d.<locals>.<genexpr>Y  rD  rU  r:  )r   r   ro  rE  r  s    rD   np_atleast_3drL  W  s"    

84
881i(( 9rF   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  r:   r   r  r  rj   r   rC  r	  r  r   r   r|   r   r  )r~   r>   r   r(  r6  
arr_shapesarr_stridesrX  
ret_shapesr  rl  ret_stridescopy_offsetsarr_shr  r  r   r  is_axisaddendret_datar  r  arr_starr_datarC  r   r/  r   rF  s                                 rD   _do_concatenaterZ  ]  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  rH   Fri  z<np.concatenate(): input sizes over dimension %d do not match)rq   r   ry   r  r
   r   rf   r   r   r9   r  r:   r?   r-  rI  rJ  r  r$  rK  r#  r   r  rk  rl  r   rZ  r!   r  )r~   r>   r(  r6  rX  r   rq   r  r  r  rO  rP  rA  rQ  r  rU  ret_shape_ptrret_shother_shapeson_axison_other_dimis_okrl  s                          rD   _np_concatenaterc    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   rH   r  np.stackr  Fri  )z5np.stack(): all input arrays must have the same shaper  )rq   r
   r   r   r   ry   r  r   rf   rK  r#  r  r   r  rk  rl  r   r   r   r  rX   r9   r  r  r$  ri   r?   rZ  r!   r  )r~   r>   r(  r6  rX  r   rq   r  r9  
ll_narraysr  r  r  r  rb  rA  orig_shr%  r   input_shapesrQ  r  r!  r"  r   rn   input_stridesrB  rl  s                                rD   	_np_stackrj    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d}t	        j
                  |      t        |      }t        j                  |||      S )Nr\  r   z.zero-dimensional arrays cannot be concatenated)r   r   r   r6   r	   r,  r7   r   )rk  r$  r   r|   rq   r   r	  s          rD   np_concatenate_typerrl  %  sl    
4 ? 	 &i&6@KE4qy>##C(()&1F;;udF++rF   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   rc  r   r
   r   r   r~   r>   r\   r   r   s        rD   rj  znp_concatenate.<locals>.codegen=  se    ||GT!Wchhqk5::Fw#CHHQK0&33GT!WE"#	% 	%rF   )rl  r   r   r   )rk  r$  r   rl  r\   rj  s         rD   np_concatenaterp  7  sA    
y&$
7Cc5;;'''
fd
C% <rF   c                 D    t        | t        j                        rdd}|S y )Nc                     t        | |      S rP  )rp  r$  r   s     rD   r   z!impl_np_concatenate.<locals>.implK  s    !&$//rF   r   r   r   r\  r$  r   r   s      rD   impl_np_concatenaterv  H  s    &%//*	0 +rF   c                 |    |D ]7  }|j                   dk  s|j                   dkD  s"d}t        j                  |       y)NrH   ro  z7np.column_stack() is only defined on 1-d and 2-d arrays)rq   r	   r,  )r~   r   r$  r  r   s        rD   _column_stack_dimsrx  P  s<    66A:!KC'',,  rF   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   rH   ro  rP  )r   r   r
   r   r   r   r   r   rq   rj   r`  r   r$   r*  rc  r   )r~   r>   r\   r   orig_arrtys	orig_arrsr(  r6  r   r  r  r  
expand_signewarrs                 rD   rj  z np_column_stack.<locals>.codegenb  s   388A;'(($q':	##EJJ2k95JE3zzQe$C  zzQ&


*#--eU;
$WgzC64Pe$F# 6 w"6 	6rF   )r6   rx  r7   r   r   )rk  rY  r|   rq   r	  rl  r\   rj  s           rD   np_column_stackr  Y  sS    %i&72DFKE4 *#.F
++eT6
*C
c(C64 <rF   c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S rP  )r  rY  s    rD   r   zimpl_column_stack.<locals>.impl  s    "3''rF   rt  rY  r   s     rD   impl_column_stackr    s    #u'	( (rF   c           
          t        | |t        |j                  d         t        j                  ||d         |j
                  |      S )z/
    np.stack() with the given axis value.
    r   )rj  r   r   r
   r   r   ro  s        rD   _np_stack_commonr    sC     Wg#((1+&))'47;__	 rF   c                     t        | d|      \  }}t        d |D              rdnd}t        j                  ||dz   |      } |||      }d }||fS )Nre  c              3   :   K   | ]  }|j                   d k(    yw)r  N)r	  rW  s     rD   rT  z"np_stack_common.<locals>.<genexpr>  s     8ACs   r  r   rH   c                     | j                  ||d   |j                  d   t        j                        }t	        | ||||      S r  )r   r   r   r   r  ro  s        rD   rj  z np_stack_common.<locals>.codegen  s9    ||GT!Wchhqk5::F#tTBBrF   )r6   r  r   r   )	rk  r$  r   r|   rq   r	  rl  r\   rj  s	            rD   np_stack_commonr    sa     &i&0&:KE4888ScF
++eTAXv
.C
fd
CC <rF   c                 D    t        | t        j                        rdd}|S y )Nc                     t        | |      S rP  )r  rs  s     rD   r   zimpl_np_stack.<locals>.impl  s    "6400rF   r   rt  ru  s      rD   impl_np_stackr    s    &%//*	1 +rF   c                     t        | ||      \  }}t        ||      }t        |      }t        j                  |||      }|S rP  )r6   r  r7   r   r   )rk  r   r$  ndim_minr|   rq   r	  rl  s           rD   NdStack_typerr    sA    %iFCKE4tXD)&1F
++eT6
*CJrF   c                 <    t        | d|d      } ||      }d }||fS )Nz	np.hstackrH   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   rH   c                 2    t        j                  |       S r{  r}  rs  s    rD   np_hstack_implz3_np_hstack.<locals>.codegen.<locals>.np_hstack_impl  s    ~~f488rF   r   rq   r   r   r   r  r  )r~   r>   r\   r   rX  rq   r  r   s          @rD   rj  z_np_hstack.<locals>.codegen  sz    Qx}}19''

A6D#GWc4FF
 	1qD9 ++G^S$OOrF   r  rk  rY  rl  r\   rj  s        rD   
_np_hstackr    s-    
	;Q
7C
c(CP& <rF   c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S rP  )r  r  s    rD   r   zimpl_np_hstack.<locals>.impl      c?"rF   rt  r  s     rD   impl_np_hstackr        #u'	# (rF   c                 <    t        | d|d      } ||      }d }||fS )Nz	np.vstackro  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  )r~  r*  hstackr$  s    rD   np_vstack_implz3_np_vstack.<locals>.codegen.<locals>.np_vstack_impl  s    ~~bii&7;;rF   rH   c                 0    t        j                  | d      S )Nr   r|  r}  r  s    rD   r  z3_np_vstack.<locals>.codegen.<locals>.np_vstack_impl      ~~f155rF   r  )r~   r>   r\   r   rX  rq   r  r   s           rD   rj  z_np_vstack.<locals>.codegen  sx    Qx}}19< QY''

A6D#GWc4FF6 ''dKKrF   r  r  s        rD   
_np_vstackr    s-    
	;Q
7C
c(CL& <rF   c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S rP  )r  r  s    rD   r   zimpl_np_vstack.<locals>.impl  r  rF   rt  r  s     rD   impl_np_vstackr    r  rF   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 )NrH   r  )r~  r  rd  r  s    rD   r  z3_np_dstack.<locals>.codegen.<locals>.np_vstack_impl  s     yy(00Ar::rF   rH   rP  ro  c                 0    t        j                  | d      S )Nro  r|  r}  r  s    rD   r  z3_np_dstack.<locals>.codegen.<locals>.np_vstack_impl  r  rF   )r   r   rq   r  r   r   r   r`  r   r$   r  r*  )r~   r>   r\   r   rX  rX  rq   r  r   stack_retty	stack_sig	stack_retr~  s                rD   rj  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OrF   r  r  s        rD   
_np_dstackr    s.    
	;Q
7C
c(C PD <rF   c                 B    t        | t        j                        rd }|S y )Nc                     t        |       S rP  )r  r  s    rD   r   zimpl_np_dstack.<locals>.impl*  r  rF   rt  r  s     rD   impl_np_dstackr  '  r  rF   fillc                     d }|S )Nc                     || d d  y rP  r  )r  r   s     rD   	fill_implzarr_fill.<locals>.fill_impl2  s    ArF   r  )r  r   r  s      rD   arr_fillr  /  s     rF   dotc                     d }|S )Nc                 .    t        j                  | |      S rP  )r~  r  )r  others     rD   dot_implzarray_dot.<locals>.dot_impl;  s    vvc5!!rF   r  )r  r  r  s      rD   	array_dotr  9  s    " OrF   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 )Nro  r7  r  .r~  r  rq   r   r  r^  s     rD   r   znp_flip_lr.<locals>.implG  s=    JJqM 66A:455TrT3rF   r  r  r   s     rD   
np_flip_lrr  A  s/     A  !>!BCC  KrF   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 )NrH   zInput must be >= 1-d.r  .r  r  s     rD   r   znp_flip_ud.<locals>.implX  s:    JJqM 66A:4552s|rF   r  r  s     rD   
np_flip_udr  R  s/     A  !>!BCC KrF   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  )r9   r0   r@  )lengthempty_tupler
  rn   s       rD   r   z6_build_flip_slice_tuple.<locals>.codegen.<locals>.impln  s1    C6]#CE$b,AB #JrF   )r   r   r   r$   r   get_constant_undefr  )r~   r>   r$   r   r   inner_argtypes	inner_sigll_idx_typer  
inner_argsr	  r   
tuple_types              rD   rj  z(_build_flip_slice_tuple.<locals>.codegenm  s{    	  **j1$$ZA.A	,,UZZ800<!$'5
&&wiL
rF   )	r   r   r  r	   r  r   r   r  slice3_type)r  szr\   rj  r   r  s       @@rD   _build_flip_slice_tupler  c  sf     b%../((,,r De&7&7tDJ
R.C" <rF   c                 p    t        | t        j                        st        j                  d| z        d }|S )NzCannot np.flip on %s typec                 6    t        | j                        }| |   S rP  )r  rq   )r  sls     rD   r   znp_flip.<locals>.impl  s    $QVV,urF   )r   r   r   r	   r   r  s     rD   np_flipr    s5     a%  !<q!@AA KrF   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 r{  )r~  array_splitr  r  indices_or_sectionsr   s      rD   r   znp_array_split.<locals>.impl  s$    >>

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

3s8$ + JJs=D%T:JKLMJrF   c              3   P   K   | ]  }t        |t        j                           y wrP  r   r   r   )rR  r8  s     rD   rT  z!np_array_split.<locals>.<genexpr>  s     P6O
1emm,6OrU  c                 4   t        | j                        }t        dd| j                  |      }g }d}t        |      D ]/  }t	        ||t        ||            }|j                  | |          |}1 |j                  | t	        ||t        d                       |S r  )r1   rq   r   r   r0   r@  rj   r  s           rD   r   znp_array_split.<locals>.impl  s    .sxx8I!*fchhEDCD%&9:#ItU45EF

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

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


	  	&4P6I6O6OPP
	  Q 	5rF   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 r{  )r~  splitr  r  s      rD   r   znp_split.<locals>.impl  s    88BJJsO-@tLLrF   c                     t        | j                  |   |      \  }}|dk7  rt        d      t        j                  | ||      S )Nr   z0array split does not result in an equal divisionr|  )r  rf   r   r~  r  )r  r  r   r  r  s        rD   r   znp_split.<locals>.impl  sM    CIIdO-@AFAsax F  >>(t rF   r|  r   )r   r   r  r  r  r   r  r  s       rD   np_splitr    s[     #

CD	M %u}}5	  c#6TBBrF   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 )Nro  z3vsplit only works on arrays of 2 or more dimensionsr   r|  rq   r   r~  r  r  r  s     rD   r   znumpy_vsplit.<locals>.impl  s5    88a< ? A Axx0q99rF   r   r   r   r	   r   r   r  r  r  r  r   r   s       rD   numpy_vsplitr    s    c5;;'3  %%)EMM5;;,1JJ,H IK  %%: KrF   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 dimensionsrH   r|  r  r  s     rD   r   znumpy_hsplit.<locals>.impl  sT    88q= ? A A88a<88C!41==xx0q99rF   r  r  s       rD   numpy_hsplitr    ss    c5;;'3  %%)EMM5;;,1JJ,H IK  %%: KrF   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 dimensionsro  r|  r  r  s     rD   r   znumpy_dsplit.<locals>.impl  s3    88a< * + +xx0q99rF   r  r  s       rD   numpy_dsplitr    r  rF   c                     | |k  S )z7
    Trivial comparison function between two keys.
    r  r  s     rD   
default_ltr  -  s     q5LrF   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
  )	rr   _sortsKeyErrorr+   make_jit_quicksortrun_quicksortr,   make_jit_mergesortrun_mergesort)r  lt_implr
  keyr  r  s         rD   get_sort_funcr  4  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 rP  )r   r   rY  r   r#  r   r  r  s    rD   lt_implementationr  L  s0    %%	E5==	)rF   z
array.sortc                     |j                   d   }t        dt        |j                              fd}| j	                  ||||      S )Nr   r+   )r  r  c                      |        y rP  r  r  	sort_funcs    rD   array_sort_implz#array_sort.<locals>.array_sort_impl\  s
    #rF   )r   r  r  r|   r  )r~   r>   r\   r   r  r  r  s         @rD   
array_sortr  U  sG    hhqkG;&7&FHI ##G_c4HHrF   c                 L    t        |       st        j                  d      d }|S )NzArgument "a" must be array-likec                 F    | j                         }|j                          |S rP  )r`  r  )r  r	  s     rD   np_sort_implz"impl_np_sort.<locals>.np_sort_impli  s    ffh

rF   r  )r  r  s     rD   impl_np_sortr   c  s/    A   "1 2 	2 rF   zarray.argsortc                    	 |j                   \  }}t        |j                  t        |j                        d      		fd}|j                  |j                   d d       }|d d }| j                  ||||      S )NT)r  r  r
  c                      |       S rP  r  r  s    rD   array_argsort_implz)array_argsort.<locals>.array_argsort_imply  s    ~rF   rH   r  )r   r  r   r  r|   replacer  )
r~   r>   r\   r   r  r  r#  innersig	innerargsr  s
            @rD   array_argsortr'  p  s|     HHMGT4#5#5&7&F)-/I {{!{-HRaI##G-?$,i9 9rF   c                 Z    |j                   |j                   k7  s|j                  dk(  sJ |S )Nr^  )rB  r	  )r~   r>   rN  rO  r   s        rD   array_to_arrayr)    s*     >>T\\)T[[C-???JrF   c                 z    d }t        ||      }| j                  ||||g      }t        | ||j                  |      S )Nc                 $    | j                  d      S r   )rB  r  s    rD   r   zarray0d_to_scalar.<locals>.impl  s    vvayrF   )r$   r  r"   r   r~   r>   rN  rO  r   r   r\   r	  s           rD   array0d_to_scalarr-    sB     D&
!C

"
"7D#u
=CgwEErF   c                 z    d }t        ||      }| j                  ||||g      }t        | ||j                  |      S )Nc                     t        | d         S r  )r  r  s    rD   r   z array_to_unichrseq.<locals>.impl  s    1R5zrF   )r$   r  r    r   r,  s           rD   array_to_unichrseqr0    sB     D&
!C

"
"7D#u
=CWgsDDrF   c                     t         )zR
    An intrinsic returning a derived array with the given shape and strides.
    r   )r  rf   r   s      rD   reshape_uncheckedr2    r  rF   c                     d fd}|S )Nc                 ^    t        | t        j                        xr t        d | D              S )Nc              3   P   K   | ]  }t        |t        j                           y wrP  r  r=  s     rD   rT  z>type_reshape_unchecked.<locals>.check_shape.<locals>.<genexpr>  s     @%QJq%--0%rU  )r   r   r\  r  rf   s    rD   r#  z+type_reshape_unchecked.<locals>.check_shape  s*    5%//2 A@%@@	BrF   c                     t        | t        j                        sy  |      r |      sy t        |      t        |      k7  ry | j	                  t        |      d      S )Nr^  r_  )r   r   r   r   r`  )r  rf   r   r#  s      rD   typerz%type_reshape_unchecked.<locals>.typer  sP    !U[[)5!W)=u:W%vv3u:cv22rF   r  )r~   r8  r#  s     @rD   type_reshape_uncheckedr9    s    B3 LrF   c                    |j                   d   }|j                  } t        |      | ||d         } t        |      | |      }t        j                  ||d         }t        j                  ||d         }	t        ||j                  ||	|j                  |j                         |j                         }
t        | |||
      S )Nr   rH   ro  r  )r   r   ry   r
   r   r   r   r   r   r  r    )r~   r>   r\   r   r   rX  r  r
  rf   r   r	  s              rD   impl_shape_uncheckedr;    s    HHQKEOOE
*U
GWd1g
6C
*U
GW
-C  $q'2E""7DG4G3"LL;; --/CWguc::rF   c                     |d t         j                  fv rt        d        nt        d        |d t         j                  fv rt        j                  d      t        d        dfd	}|S )Nc                     | j                   S rP  r6  rX  rf   s     rD   r}  zas_strided.<locals>.get_shape  s    77NrF   c                     |S rP  r  r>  s     rD   r}  zas_strided.<locals>.get_shape  s    LrF   z,as_strided() strides argument cannot be Nonec                     |S rP  r  )rX  r   s     rD   get_strideszas_strided.<locals>.get_strides  s    NrF   c                 >    t        |  | |       | |            } | S rP  )r2  )rX  rf   r   r}  rA  s      rD   as_strided_implz#as_strided.<locals>.as_strided_impl  s$    a1e!4k!W6MNrF   r  )r   r&  r&   r	   r   )rX  rf   r   rC  r}  rA  s       @@rD   
as_stridedrD    s    uzz""		 
	 
	 
	 4$$
   !OPP		 
	 rF   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 )NrH   c                     | fS rP  r  window_shapes    rD   get_window_shapez-sliding_window_view.<locals>.get_window_shape   s
     ?"rF   c                     | S rP  r  rG  s    rD   rI  z-sliding_window_view.<locals>.get_window_shape	  s    rF   z4window_shape must be an integer or tuple of integersc                 *    t        t        |            S rP  )r   r9   rH  r   rq   s      rD   get_axisz%sliding_window_view.<locals>.get_axis  s    d$$rF   c                      t        dd||      gS Nsliding_window_viewr   r   rL  s      rD   rM  z%sliding_window_view.<locals>.get_axis  s     4fdDI rF   c           	      D    |D cg c]  }t        dd||       c}S c c}w rO  rQ  )rH  r   rq   r  s       rD   rM  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 shaperH   )	rq   r   r   r9   r0   rf   r   r   r2  )rX  rH  r   	out_shapeout_stridesrn   r   r  trimmedrD  rM  rI  shape_bufferstride_buffers             rD   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{;rF   rP  )r   r   r   r   r9   rq   r&   r  r|   r   r	   r   r   )rX  rH  r   rY  rM  rI  rW  rX  s       @@@@rD   rP  rP    sx    ,.U166A:./eAFFQJ/0		# 
	# \5>>
2|))5==9U166C,=#=>?eAFFS->$>?@		  
	    B
 	

 4		% 
	% 
D%--	(		 
	
 T5>>
*tzz5==1		# 
	#
   @
 	
% %N $#rF   c                 B    t        | t        j                        rd }|S y )Nc                     | j                   dk(  rt        dk  ryt        d      | j                   dk(  rt        | j	                  d            S t        d      )Nr   )ro  ro  FziThe truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty.rH   z[The truth value of an array with more than one element is ambiguous. Use a.any() or a.all())r   r   r   r]  rB  rz  s    rD   r   zol_bool.<locals>.implX  s_    xx1} 6) $ 'J L L QCHHQK((  #- / /rF   rQ  r{  s     rD   ol_boolr\  U  s!    #u{{#	/  $rF   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 integer'The first argument "a" must be an arrayc                     t        dd|      }t        dd|      }t        ||      }t        |||      }t        j                  | |      S )Nznp.swapaxesaxis1axis2)r   r0   r~  r  )r  r`  ra  
axes_tuple	axes_listrq   s       rD   r   znumpy_swapaxes.<locals>.implx  sP    }gtUC}gtUC"9eU;
":ue<
||Az**rF   )
r   r   r   r   r	   r   r   rq   r   r9   )r  r`  ra  r   rc  rq   s       @@rD   numpy_swapaxesrd  i  s    ec5==12   "+ , 	,ec5==12   "+ , 	,a%  !JKK 66DeDk"I+ KrF   c                 ^   t        | t        j                        st        j                  d      t        |t        j
                        sSt        |t        j                        r$t        |j                  t        j
                        st        j                  d      t        |t        j
                        sSt        |t        j                        r$t        |j                  t        j
                        st        j                  d      | j                  d| j                  z  fd}|S )Nr^  zGThe second argument "source" must be an integer or sequence of integerszKThe third argument "destination" must be an integer or sequence of integersr  c                    t        dd
|      }t        dd
|      }t        |      t        |      k7  rt        d      t        | j                        D cg c]	  }||vs| }}t        t        ||            D ]  \  }}|j                  ||        }t        |      D ]  \  }}	t        |||	      } | j                  |      S c c}w )Nznp.moveaxissourcedestinationzL`source` and `destination` arguments must have the same number of parameters)r   r   r   r9   rq   r  r   r  r   r0   r  )r  rg  rh  r  
order_listri  rD  rN  rn   orq   
order_inits             rD   r   znumpy_moveaxis.<locals>.impl  s    %mXtVL*=$
 v;#k**0 
 "'qvvBA!6/a
BK 89ID#dC( : j)DAq!%A.E * {{5!! Cs   	C	!C	)	r   r   r   r	   r   r   r  r|   rq   )r  rg  rh  r   rq   rk  s       @@rD   numpy_moveaxisrl    s    a%  !JKK65==)vu~~.6<<7   &
 	

 	;.{ENN3;,,emm<   &
 	

 66DJ", KrF   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   rH   z*`arr` and `indices` dimensions don't matchr   )r   rq   r   rf   r   r   r   r0   r~  r  r   r9   r  r|   r@  r  )r  r   r   Ni_origNk_origindices_broadcast_shape	arr_shapern   d1d2new_valarr_broadcast_shapeNiNkJr
  np_s_iikka_1d
indices_1dout_1dr7  s                          rD   _take_along_axis_implr    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	 	 !  JrF   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 integersrH   z;`indices` and `arr` must have the same number of dimensionsc                 @    t        | j                         |ddd      S )Nr   r  )r  r  )r  r   r   rp  s      rD   take_along_axis_implz1arr_take_along_axis.<locals>.take_along_axis_impl
  s%    (B)@B BrF   r   zaxis must be a literal valuer   zaxis is out of boundsc                 $    t        | ||      S rP  )r  )r  r   r   rv  rw  rp  s      rD   r  z1arr_take_along_axis.<locals>.take_along_axis_impl  s    (gtR)@B BrF   )r   r   r   r	   r   r|   r   r   rq   r   r9   r   r  r>  r   )r  r   r   arr_ndimr  rv  rw  rp  s        @@@rD   arr_take_along_axisr    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  rF   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 rP  r  rX  r`  nanposinfneginfs        rD   r   znan_to_num_impl.<locals>.impl&      rF   c                 @   ||n't        j                  t        |             j                  }||n't        j                  t        |             j                  }t        j
                  |       r|S t        j                  |       r|S t        j                  |       r|S | S rP  )r~  finfor:   r  r  r  isneginfisposinf)rX  r`  r  r  r  min_infmax_infs          rD   r   znan_to_num_impl.<locals>.impl*  s     ) $q'*..  ) $q'*..  88A;J[[^"N[[^"NrF   c                     t        j                  | j                  |||      }t        j                  | j                  |||      }t	        ||      S )N)r  r  r  )r~  
nan_to_numr(  r*  complex)rX  r`  r  r  r  r  r  s          rD   r   znan_to_num_impl.<locals>.impl>  s>    MM!&&c&PMM!&&c&Pq!}$rF   z4Only Integer, Float, and Complex values are acceptedc                     | S rP  r  r  s        rD   r   znan_to_num_impl.<locals>.implJ  r  rF   c                    ||n(t        j                  | j                        j                  }||n(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 rP  )r~  r  r|   r  r  r  r`  r  r9   r   r  r  r  )rX  r`  r  r  r  r  r  x_outputoutput_flatrn   s              rD   r   znan_to_num_impl.<locals>.implM  s     ) !''*..  ) !''*..  ZZ](,"$kkv{{+AxxA/),A[^4)0A[^4)0A , rF   c                     t        j                  |       }|rt        j                  |      n|}t        j                  |j                  d|||       t        j                  |j
                  d|||       |S )NF)r`  r  r  r  )r~  r  r`  r  r(  r*  )rX  r`  r  r  r  r  r  s          rD   r   znan_to_num_impl.<locals>.implf  sg    ZZ](,"KK!! KK!! rF   z4The first argument must be a scalar or an array-likeTg        NN)
r   r   r  r   rY  r#  r	   r   r   r|   )rX  r`  r  r  r  r   s         rD   nan_to_num_implr  !  s   !U\\"a't Ko 5;;'l KG 5==)%D K{ $$F  
!	aggu}}-l Ki -f K7 /4 K $$F     ". / 	/rF   rP  r  r  r  r   )Fr  r  (  r  rI  rb  r  r<  llvmliter   llvmlite.irr   numpyr~  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.charseqr.   r/   numba.cpython.unsafe.tupler0   r1   r2   numba.core.typing.npydeclr3   r  r4   r  r5   r6   r7   rE   rJ   ry   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  ArrayIteratorBORROWEDr*  rC  r  rI  r  r   r1  rK  rM  r\  rZ  r`  Anyra  r   rf  r   rm  rr  rG  rt  r  r  r  r  r  r  rW  r  r  r  r!  r)  rG  rP  r\  rd  rm  rr  r|  r  r  r  r  broadcast_shapesr  r  r  r  r  r  r^  r  r  r  r  VarArgr
  r  r  r  r,  r  	geomspacer5  rot90r?  rN  rV  r^  r`  rd  rf  resizeru  rj   r~  r  rl  r  r  r  r  r  r  r  r  rf   r  r   r  uniquer  r  r   r  r  r  r  r  r$  r"  r%  
MemoryViewr(  r*  r,  r.  r0  r3  r7  r;  r@  rC  rI  rF  rL  r  r  rP  rW  r[  rY  r]  r_  rf  rj  rd  r|  r  DTypeNumberClassr  r  r  r  r  r  r  r  r  r  r  r  r  Bytesr  is_r  r  r  r  r  r  rH  rR  r  rz  rv  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  NumpyNdIterTyper  eqr  r  r  r  r  r  r  rh  r  r  r  r  r  r  r  r  r  r  rm  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  r  eyer%  diagr-  r   r2  diagflatr9  rA  rB  rT  r_  r0  rs  r  r{  r  r  r  r`  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r   r  r  r#  r&  r*  r-  r0  r=  r4  
atleast_1drF  
atleast_2drI  
atleast_3drL  rZ  rc  rj  rl  rp  ro  rv  rx  r  column_stackr  r  r  stackr  r  r  r  r  r  vstackr  	row_stackr  dstackr  r  r  r<  r  r=  r  r  flipr  r  r  r  r  vsplitr  hsplitr  dsplitr  r  r  r  r  r  r  r   argsortr'  r)  UnicodeCharSeqrY  r#  r  NPTimedelta
NPDatetimer-  r0  r2  type_callabler9  r;  libstride_tricksrD  rP  r]  r\  r;  rd  moveaxisrl  r  take_along_axisr  r  r  r  rF   rD   <module>r     s  
         * @ @; ; ; P O* * * * ( *A A + ! B L 5E E#69x(-M	

  BJH& 
 
. , 
 

,  ,^ y%,,' (.;* z5../w - ! 0-6  $A4H ;* xu}}=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 

"95
 6
 

"51 2*U%v&  %++.; /;
  %++u?3E @3El  %++|u||EII/FGF HF
 
",,  u{{C 9 !9& 
"++  
",,I IX 
"(( 4!H;< U__==E >=E@ \U\\%))-DE> F>
 6bjj 
 bjj  
"))+ +\ 
")) 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Vr 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;u= >* 
 
-`K#&   
"((" & &*   
"-- 0   l+ , 
"(("   
"--  
",,
 
 
"''   
",,
 
 
"''  
"++ 	 %& ' BFF1E  2 
"''# #L 
"** 6 
"++ 4  F 
"''f%^ & ^B4 
"))@ @F 
"++$ $N"PJ   |U[[)4 *4 
"'' ><B ? ? 
"


  
 
"

  ~u{{EOO<~u{{E,?,?@P A =P: ' 'T i( ) T Tn 
"--%*"Q  8 
&  
& !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((<<=[$ >[$| 
$ & 
"++ 0 
"++3 3l 8 8v 
"

(  ( V 
"--^ ^rF   