
    iq                     z   S r SSKrSSKrSSKrSSKJr  SSKJr  SSKr	SSK
r
SSKJrJrJr  SSKJr  SSKJrJrJrJr  SSKJrJrJrJrJrJr  SSKJrJrJ r J!r!  SS	K"J#r#  SS
K$J%r%  SSK&J'r'J(r(  SSKJ)r)  \" S5      r* " S S\+5      r, " S S\+5      r- " S S\" SS5      5      r. " S S\" SS5      5      r/ " S S\" SS5      5      r0S-S jr1\Rd                  (       a^  \Rf                  " \Rf                  \Rh                  " \Rf                  5      \Rf                  \Rh                  " \Rf                  5      5      r5O]\Rl                  " \Rl                  \Rh                  " \Rl                  5      \Rl                  \Rh                  " \Rl                  5      5      r5S r7S r8S r9S r:S  r;S! r<S" r= " S# S$\+5      r>S% r?S& r@ S.S' jrAS.S( jrB\*R                  \
R                  \R                  5      S) 5       rFS* rG\G" \R                  " 5       \*R                  5        \(S+ 5       rI\'" \	R                  5      S, 5       rKg)/z3
Implementation of functions in the Numpy package.
    N)
namedtuple)arrayobjufunc_dbnumpy_support)parse_signature)Registryimpl_ret_new_refforce_error_modelimpl_ret_borrowed)typingtypesutilscgutilscallconvconfig)ufunc_find_matching_loopselect_array_wrapper
from_dtype_ufunc_loop_sig)_getitem_array_generic)npydecl)overload	intrinsic)errorsnpyimplc                        \ rS rSrS rS rSrg)_ScalarIndexingHelper-   c                     g N )selfloop_indicesnames      K/var/www/html/trading/venv/lib/python3.13/site-packages/numba/np/npyimpl.pyupdate_indices$_ScalarIndexingHelper.update_indices.           c                     g r    r!   r"   s    r%   	as_values_ScalarIndexingHelper.as_values1   r(   r)   r!   N__name__
__module____qualname____firstlineno__r&   r,   __static_attributes__r!   r)   r%   r   r   -   s    r)   r   c                   @    \ rS rSrSrS rS rS rS r\	S 5       r
Srg	)
_ScalarHelper5   a0  Helper class to handle scalar arguments (and result).
Note that store_data is only used when generating code for
a scalar ufunc and to write the output value.

For loading, the value is directly used without having any
kind of indexing nor memory backing it up. This is the use
for input arguments.

For storing, a variable is created in the stack where the
value will be written.

Note that it is not supported (as it is unneeded for our
current use-cases) reading back a stored value. This class
will always "load" the original value it got at its creation.
c                 X   Xl         X l        X0l        X@l        UR	                  [
        R                  5      n[        R                  " US5      /U l	        U[
        R                  :w  a  UR                  U5      O[        R                  " S5      n[        R                  " X&5      U l        g N   )contextbuilderval	base_typeget_value_typer   intpirConstantshapebooleanget_data_typeIntTyper   alloca_once_ptr)r"   ctxtbldr<   tyintptyltys          r%   __init___ScalarHelper.__init__E   sv    $$UZZ0kk&!,-
(*emm(;d  $A''1	r)   c                     [        5       $ r    )r   r+   s    r%   create_iter_indices!_ScalarHelper.create_iter_indicesP   s    $&&r)   c                     U R                   $ r    )r<   r"   indicess     r%   	load_data_ScalarHelper.load_dataS   s    xxr)   c                 N    U R                   R                  X R                  5        g r    )r;   storerG   )r"   rT   r<   s      r%   
store_data_ScalarHelper.store_dataV   s    3		*r)   c                 L    U R                   R                  U R                  5      $ r    )r;   loadrG   r+   s    r%   
return_val_ScalarHelper.return_valY   s    ||  ++r)   )rG   r=   r;   r:   rB   r<   N)r/   r0   r1   r2   __doc__rM   rP   rU   rY   propertyr]   r3   r!   r)   r%   r5   r5   5   s/    	2'+ , ,r)   r5   c                        \ rS rSrS rS rSrg)_ArrayIndexingHelper^   c                 N   U R                   R                  nU R                   R                  R                  [        R
                  5      n[        R                  " [        R                  " UR                  5      S5      nU[        U5      [        U R                  5      -
  S  n[        X`R                  U R                   R                  5       HC  u  pxn	UR                  SX5      n
UR                  U
5         UR!                  Xx5        S S S 5        ME     g ! , (       d  f       MW  = f)Nr9   >)arrayr;   r:   r>   r   r?   r@   rA   rE   widthlenrT   ziprB   icmp_unsignedif_thenrX   )r"   r#   r$   rI   rK   ONErT   srcdstdimconds              r%   r&   #_ArrayIndexingHelper.update_indices`   s    jj  ##225::>kk"**V\\2A6
 s<03t||3DDEF ,,

8H8HIMCc$$S#3DT"		## #" J""s   6D
D$	c                     U R                   R                  nU R                   Vs/ s H  o!R                  U5      PM     sn$ s  snf )z
The indexing helper is built using alloca for each value, so it
actually contains pointers to the actual indices to load. Note
that update_indices assumes the same. This method returns the
indices as values
)rf   r;   rT   r\   )r"   rI   indexs      r%   r,   _ArrayIndexingHelper.as_valuesn   s5     jj  -1\\:\E\:::s   Ar!   Nr.   r!   r)   r%   rb   rb   ^   s    $;r)   rb   )rf   rT   c                   0    \ rS rSrSrS rS rS rS rSr	g)	_ArrayHelpery   zHelper class to handle array arguments/result.
It provides methods to generate code loading/storing specific
items as well as support code for handling indices.
c                    U R                   R                  [        R                  5      n[        R
                  " [        R                  " UR                  5      S5      n/ n[        U R                  5       Hn  n[        R                  " U R                  [        R                  " UR                  5      5      nU R                  R                  X%5        UR                  U5        Mp     [        X5      $ Nr   )r:   r>   r   r?   r@   rA   rE   rg   rangendimr   rF   r;   rX   appendrb   r"   rK   ZEROrT   ixs         r%   rP    _ArrayHelper.create_iter_indices   s    ,,UZZ8{{2::fll3Q7tyy!A##DLL"**V\\2JKALLt'NN1 " $D22r)   c           
          [         R                  " U R                  U R                  U R                  U R
                  U R                  U R                  US9$ N)datarB   strideslayoutinds)r   get_item_pointer2r:   r;   r   rB   r   r   rS   s     r%   _load_effective_address$_ArrayHelper._load_effective_address   sA    (()-.2ii/3zz1504.57 	7r)   c                     U R                   R                  U R                     nU R                  U5      nUR	                  U R
                  U5      $ r    )r:   data_model_managerr=   r   load_from_data_pointerr;   )r"   rT   modelptrs       r%   rU   _ArrayHelper.load_data   sA    //?**73++DLL#>>r)   c                    U R                   nU R                  nUR                  X@R                  U5      nUR	                  U R                  5      UR
                  :X  d   eUR                  XPR                  U5      5        g r    )r:   r;   get_value_as_datar=   rD   typerX   r   )r"   rT   valuectxrI   store_values         r%   rY   _ArrayHelper.store_data   sd    llll++CG  0K4D4DDDD		+;;GDEr)   r!   N)
r/   r0   r1   r2   r_   rP   r   rU   rY   r3   r!   r)   r%   rv   rv   y   s    	37?
Fr)   rv   )	r:   r;   rB   r   r   r   r=   r{   r]   c                   B    \ rS rSrSrS rS rS rS rSS S\	4S	 jr
S
rg)_ArrayGUHelper   zHelper class to handle array arguments/result.
It provides methods to generate code loading/storing specific
items as well as support code for handling indices.

Contrary to _ArrayHelper, this class can create a view to a subarray
c                    U R                   R                  [        R                  5      n[        R
                  " [        R                  " UR                  5      S5      n/ n[        U R                  U R                  R                  -
  5       Hn  n[        R                  " U R                  [        R                  " UR                  5      5      nU R                  R                  X%5        UR                  U5        Mp     [!        X5      $ ry   )r:   r>   r   r?   r@   rA   rE   rg   rz   r{   inner_arr_tyr   rF   r;   rX   r|   rb   r}   s         r%   rP   "_ArrayGUHelper.create_iter_indices   s    ,,UZZ8{{2::fll3Q7tyy4#4#4#9#99:A##DLL"**V\\2JKALLt'NN1 ; $D22r)   c           
      f   U R                   nU R                  n[        R                  " U R                  U R
                  U R                  5      nUR                  U5      " X#U R                  5      n[        R                  " UUUR                  U R                  U R                  U R                  US9$ r   )r:   r;   r   Arrayr=   r{   r   
make_arrayr   r   r   rB   r   )r"   rT   r:   r;   arr_tyarrs         r%   r   &_ArrayGUHelper._load_effective_address   s    ,,,,T^^TYYD  (499E(()0.1hh/3zz1504.57 	7r)   c           
         U R                   U R                  p2U R                  R                  S:X  aL  U R                  (       a;  UR
                  U R                     nU R                  U5      nUR                  X55      $ U R                  R                  S:X  Ga  U R                  (       Gdt  UR                  [        R                  5      nU" S5      n[        R                  " U R                  U R                  U R                  5      n[        R                  " U R                  SU R                  5      n	U" [        R                  " X(5      5      n
U R                   R!                  U5      " UUU R"                  5      nU R                   R!                  U	5      " X#5      n[        R$                  " UU R                  U5      [&        R(                  " X7/5      [&        R(                  " X:/5      UR*                  UR,                  UR.                  S9  UR1                  5       $ [        R2                  4U R                  U R                  R                  -
  -  n[        R                  " U R                  U R                  U R                  5      nU R                   R!                  U5      " X#U R"                  5      n[5        X#U R                  XX5      n[7        X#U R                  U5      $ )Nr   r9   )r   rB   r   itemsizememinfoparent)r:   r;   r   r{   is_input_argr   r=   r   r   r>   r   r?   r   r   r   get_itemsizer   r   populate_arrayr   
pack_arrayr   r   r   	_getvalueint64r   r   )r"   rT   r:   r;   r   r   rK   onefromtytotyr   arr_fromarr_toindex_typesarrtyr   ress                    r%   rU   _ArrayGUHelper.load_data   s.   <<!!Q&4+<+<..t~~>E..w7C//==##q(1B1B1B ++EJJ7F)C[[DKKHF;;t~~q$++>Dh33GDEH ||..v6w7>7;yyBH \\,,T27DF##11':((%8**7J?!** ((( ##%% !;;.DII8I8I8N8N,NOKKK		4;;GE,,))%0499MC()-):):E)4?C %Wt7H7H#NNr)   c           	        ^ U R                   R                  mU4S jnU R                  U R                  pC[        R
                  " [        R                  " [        R                  [        U5      5      [        R                  " [        R                  [        U R                  5      5      5      nUR                  XER                  S   U5      UR                  XER                  S   U R                  5      4nUR                  XBXV5        g )Nc                    > [        U5      T-
  nU[        U 5      :  nU(       d  [        U5       H  nX1U   X   :g  -  nM     U(       a  [        S5      eg )Nz&Loop and array shapes are incompatiblerh   rz   
ValueError)
loop_shapearray_shape	remaining_raiser   
inner_ndims        r%   
raise_impl._ArrayGUHelper.guard_shape.<locals>.raise_impl   s]    
 K(:5I#j/1Fy)A1~>?F *
 !!IJJ r)   r   r9   )r   r{   r:   r;   r   noneUniTupler?   rh   rB   
make_tupleargscompile_internal)r"   	loopshaper   r:   r;   sigtupr   s          @r%   guard_shape_ArrayGUHelper.guard_shape   s    &&++
	K"  <<jjNN5::s9~6NN5::s4::7
 !!'88A;	B!!'88A;

CE  c?r)   otherndimsc           	        ^ U4S jnU R                   U R                  pT[        R                  " [        R                  " [        R
                  [        U R                  5      5      [        R                  " [        R
                  [        UR                  5      5      5      nUR                  XVR                  S   U R                  5      UR                  XVR                  S   UR                  5      4nUR                  XSXg5        g )Nc                    > Sn[        U 5      T-
  [        U5      T-
  pC[        T5       H  nX X5-      XU-      :H  -  nM     U(       d  Sn[        U5      eg )NTzOperand has a mismatch in one of its core dimensions. Please, check if all arguments to a @guvectorize function have the same core dimensions.r   )
self_shapeother_shapesameabr   msgr   s          r%   r   8_ArrayGUHelper.guard_match_core_dims.<locals>.raise_impl  sg    Dz?U*C,<u,Dq5\15)[Q-??? "A !o% r)   r   r9   )r:   r;   r   r   r   r?   rh   rB   r   r   r   )r"   r   r   r   r:   r;   r   r   s     `     r%   guard_match_core_dims$_ArrayGUHelper.guard_match_core_dims  s    	&"  <<jjNN5::s4::7NN5::s5;;'78
 !!'88A;

C!!'88A;DG  c?r)   r!   N)r/   r0   r1   r2   r_   rP   r   rU   r   intr   r3   r!   r)   r%   r   r      s5    	37)OV@8 @+;  @C  @r)   r   )
r:   r;   rB   r   r   r   r=   r{   r   r   c                 2   [        U[        R                  5      (       a   UnUR                  nU R	                  XXS5      n[        U[        R
                  5      (       a  U R                  U5      " XU5      n[        R                  " XR                  UR                  5      n[        R                  " XR                  UR                  5      n[        XXxUR                  UR                  UR                  UR                  U5	      $ [        R                   " U5      [        R"                  [        R$                  1-  ;   d)  [        U[        R&                  R(                  5      (       a  [+        XX#5      $ [-        SR/                  U[1        U5      5      5      e)zreturns an instance of the appropriate Helper (either
_ScalarHelper or _ArrayHelper) class to handle the argument.
using the polymorphic interface of the Helper classes, scalar
and array cases can be handled with the same codezunsupported type for {0}: {1})
isinstancer   Optionalr   castArrayCompatibler   r   unpack_tuplerB   r{   r   rv   r   r   dtype	unliteralnumber_domainrC   scalars_NPDatetimeBaser5   NotImplementedErrorformatstr)	rH   rI   inptyinpwhereotyaryrB   r   s	            r%   _prepare_argumentr   /  s)    %((

ii#- %..////%(C8&&sIIuzzB&&sKKDDusxx!LL%++uzz3H 	H
//%
 E$7$75==/$I
Iu}}<<==T33!"A"H"H"%e*#. / 	/r)   c                     X:  a  gSnX -
  nX@:  a;  X   nX5   nUS:w  a  Xg:w  a  US:w  a  US-   * $ O
US:w  a  XcU'   US-  nUS-  nX@:  a  M;  U$ )aq  Low-level utility function used in calculating a shape for
an implicit output array.  This function assumes that the
destination shape is an LLVM pointer to a C-style array that was
already initialized to a size of one along all axes.

Returns an integer value:
>= 1  :  Succeeded.  Return value should equal the number of dimensions in
         the destination shape.
0     :  Failed to broadcast because source shape is larger than the
         destination shape (this case should be weeded out at type
         checking).
< 0   :  Failed to broadcast onto destination axis, at axis number ==
         -(return_value + 1).
r   r9   r!   )src_ndim	src_shape	dest_ndim
dest_shape	src_index
dest_indexsrc_dim_sizedest_dim_sizes           r%   _broadcast_ontor   Q  s      	)
"$/L&2M !  0\Q5F'!^,,")5:&NI!OJ "  r)   c                   ^ ^^  U Vs/ s H0  n[        U[        R                  5      (       a  UR                  OUPM2     nnT R	                  [        R
                  5      nU 4S jnU" S5      nU" S5      n	[        R                  " TXbR                  S5      n
U" UR                  5      n[        R                  " TXbR                  S5      m [        UU 4S j[        UR                  5       5       5      nU H  nTR                  X5        M     [        U5       GH5  u  p[        US5      (       d  M  U" UR                  5      n[        UR                  5       H8  nTR                  UR                  U   [        R                  " TU
U5      5        M:     T R!                  T["        [$        UXT /5      n[        R&                  " TTR)                  SUU	5      5         S	U4-  n[*        R,                  R/                  S
S5      nUb  USUR0                  UR2                  4-  -  nT R4                  R7                  T[8        U45        SSS5        GM8     UR:                  n[        U4S jU 5       5      n[<        R>                  " T TUU5      n[A        U5      nUU   n T RC                  SU" UU5      5      nUU   RD                  URG                  5       4nU" TU5      nUR                  n[        RN                  " TUR                  U5      n[        RN                  " TURP                  U5      n[S        T TUUURT                  URV                  URX                  UU5	      $ s  snf ! , (       d  f       GM\  = f! [H         a<    URJ                  [        RL                  RJ                  :w  a  e URG                  5       n Nf = f)zUtility function to handle allocation of an implicit output array
given the target context, builder, output array type, and a list of
_ArrayHelper instances.
c                 D   > TR                  [        R                  U 5      $ r    )get_constantr   r?   )r<   r:   s    r%   make_intp_const%_build_array.<locals>.make_intp_const  s    ##EJJ44r)   r   r9   r   r   c              3   T   >#    U  H  n[         R                  " TTU5      v   M     g 7fr    )r   gep_inbounds).0rs   r;   r   s     r%   	<genexpr>_build_array.<locals>.<genexpr>  s+      @*> %11':uMM*>s   %(r{   <z/unable to broadcast argument %d to output arraylocNz
File "%s", line %d, c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr    )r\   )r   dest_shape_addrr;   s     r%   r   r    s%      D2B #<<882Bs   !__array_wrap__)-r   r   r   r   r>   r?   r   rF   r{   tuplerz   rX   	enumeratehasattrrB   r   r   r   _broadcast_onto_sigif_unlikelyicmp_signedr   loc_infogetfilenameline	call_convreturn_user_excr   as_arrayr   _empty_nd_implr   get_functionr]   r   r   array_priorityr   r   r   rv   r   r   r   )!r:   r;   array_tyinput_typesinputsr   intp_tyr   r~   rl   r   r   dest_shape_addrsr  
arg_numberargarg_ndimrs   
arg_resultr   r  real_array_tydest_shape_tup	array_valarray_wrapper_indexarray_wrapper_ty
array_wrap	wrap_argsout_valr{   rB   r   r   s!   ``                              @r%   _build_arrayr(  y  sy    ()'q (5>>::166A'  ) $$UZZ0G5 1D
!
C##GWmm$/1I.I$$Wg}}%13J @*/*>@ @ ,c+ , %V,
sF##"388,388_EMM#))E*!..w	5IK % --_&9yZ8:
   !(!4!4S*c!JLCG C //%%eT2C/3<<2JJJ--gzC6JL L -* %%M D2BD DN''-(68I /{;"#671))*:*23C]*SU
 /0;;Y=P=P=RS	Wi0==D""7IOOTBE""7I,=,=tDG%).. ! !S)FL L2  ( **ekk.H.HH%%'(s%   7M!A*M&M9 &
M6	9AN?>N?c                 f    U R                   S:X  a  UR                  /$ [        UR                  5      $ r8   )noutreturn_typelist)ufuncr   s     r%   _unpack_output_typesr.    s)    zzQ  COO$$r)   c                 T    U R                   S:X  a  U/$ [        R                  " X5      $ r8   )r*  r   r   )r-  r;   valuess      r%   _unpack_output_valuesr1    s%    zzQx##G44r)   c                 P    U R                   S:X  a  US   $ UR                  X#U5      $ )Nr9   r   )r*  r   )r-  r:   r;   typr0  s        r%   _pack_output_valuesr4    s*    zzQay!!'77r)   c           
      *   [        X2R                  5       VVs/ s H  u  pg[        XXg5      PM     nnn[        U5      UR                  :  a9  [        SR                  UR                  UR                  [        U5      5      5      e[        [        XB5      5       H  u  pUR                  U	-   [        U5      :  a{  [        U
[        R                  5      (       a  [        XXR                  U5      nO1[        X[        R                  " U R!                  U
5      S 5      U
5      nUR#                  U5        M  U R$                  (       d  M  U R&                  R)                  XX4R                  U	-      5        M     US UR                   nXR                  S  n[        U5      UR*                  :X  d   e[-        U Vs/ s H  oR.                  PM     snU Vs/ s H  oR.                  PM     sn5      nU" XU5      nU R!                  [        R0                  5      nU Vs/ s H  nUR3                  5       PM     nnUS   R4                  nU Vs/ s H&  n[        U[6        5      (       d  M  UR8                  PM(     nn[        U Vs/ s H  nUS:X  d  M  UPM     sn5      n[        U Vs/ s H  nUS:X  d  M  UPM     sn5      nUU:  a  SnOSn[:        R<                  " UUUUS9 n/ n[        [        UU5      5       HI  u  nu  nnUR?                  UU5        UR#                  URA                  URC                  5       5      5        MK     [E        XAURF                  " U6 5      n[        UU5       H  u  nnURI                  UU5        M     S S S 5        [K        X@XRL                  U V s/ s H  n U RN                  PM     sn 5      n![Q        XURL                  U!5      $ s  snnf s  snf s  snf s  snf s  snf s  snf s  snf ! , (       d  f       N{= fs  sn f )Nz+Not enough inputs to {}, expected {} got {}r   CFr?   order))ri   r   r   rh   ninRuntimeErrorr   r/   r  r.  r   r   r   r(  r@   rA   r>   r|   
enable_nrtnrtincrefr*  r   r=   r?   rP   rB   rv   r   r   	loop_nestr&   rU   r,   r1  generaterY   r4  r+  r]   r	   )"r:   r;   r   r   r-  kernel_classr  tyarg	argumentsout_iret_tyoutputr  outputsr   	outer_sigkernelrK   r   rT   r   input_layoutsr   num_c_layoutnum_f_layoutr9  r#   vals_inr   rs   vals_outval_outoouts"                                     r%   numpy_ufunc_kernelrR    sw    $'tXX#68#6ZS #7S@#6  8 9~		!9VENNEIIs9~>@ 	@ ##7#CD99uI.&%"7"788%g)T*KK 6 6v >EvO V$KKwYY5F0GH E z		"F		
#Gw<5::%%%%&gg&$%ff%I 'I6F##EJJ/F4:;FSs&&(FG; 
  I ,2 76C"35  SZZ6M 7===aAH==>L===aAH==>L l"			7IF%	HL(Wf)=>OA|s  q1NN3==):;<  ? )'9RS"8W5OGVlG4  6 
I eg_fHg_fZ[_fHg
hCGcoosCCC86 	'%
 <7== 
I	H IhsN   O9O!O&
O+O0(O0
O5O5'
O:5O:$B&O?'P?
Pc                 l   / nUR                   R                  5       nUS   US   -   nS/UR                  -  S/UR                  -  -   n[	        X2R
                  Xx5       GH	  u  pp[        U
[        R                  5      (       a  U R                  U
5      " XU	5      n[        R                  " XR                  U
R                  5      n[        R                  " XR                  U
R                  5      nU
R                  US9nU
R                  nU
R                   nU
R"                  n[%        XXU	UUUUU5
      nUR'                  U5        M  [)        XX5      nUR'                  U5        GM     U" XU5      nU V	s/ s H&  n	[        U	[$        5      (       d  M  U	R                   PM(     nn	[+        U Vs/ s H  nUS:X  d  M  UPM     sn5      n[+        U Vs/ s H  nUS:X  d  M  UPM     sn5      nUU:  a  SnOSnXdR                  S  nU R-                  [        R.                  5      nU Vs/ s H  nUR1                  5       PM     nnUS   R                  US   R2                  R                  -
  n US   R                  S U  n![5        UR6                  R8                  5      n"[:        R<                  " [	        [?        [+        U5      5      U"S   U"S   -   5      SS	9 H^  u  u  n#n$u  n%n&UU#   UU%   n(n'U$U&:X  d  M  [A        S
 U'U(4 5       5      (       d  M9  UU#   UU%   n(n'U'RC                  U([+        U$5      5        M`     US UR                    H+  n	[        U	[$        5      (       d  M  U	RE                  U!5        M-     [        RF                  " UU!UUS9 n)/ n*[I        [	        UU5      5       HI  u  n+u  n,n	U,RK                  U)U+5        U*R'                  U	RM                  U,RO                  5       5      5        MK     URP                  " U*6   S S S 5        g s  sn	f s  snf s  snf s  snf ! , (       d  f       g = f)Nr   r9   TF)r{   r6  r7     )rc              3   B   #    U  H  n[        U[        5      v   M     g 7fr    )r   r   )r   r   s     r%   r   &numpy_gufunc_kernel.<locals>.<genexpr>k  s     J>aJq.11>s   r8  ))dufuncexpected_ndimsr:  r*  ri   r   r   r   r   r   r   r   rB   r{   r   copyr   r   r   r|   r5   rh   r>   r?   rP   r   r   gufunc_builder	signature	itertoolscombinationsrz   allr   r   r?  r  r&   rU   r,   r@  )-r:   r;   r   r   r-  rA  rC  rY  is_inputr  rJ   exp_ndimis_inpr   rB   r   r   r{   r   r=   array_helperscalar_helperrI  layoutsr   rK  rL  r9  rG  rK   r   rT   loopshape_ndimr   _sigidx_asig_aidx_bsig_barg_aarg_br#   rM  r   rs   s-                                                r%   numpy_gufunc_kernelrn  3  s   I!((779N#A&)::Nv		!UGejj$88H%(xx%R!b%//00 $$R(3?C(())RWWEE**7KKIG7771L77DYYFI)'*/#*0)T*6@L \*)'CDM]+% &S& 'C0F%. 3YcS.1 szzYG 3777aa3h778L777aa3h778L l"		
#G##EJJ/F4=>ISs&&(IG>QZ__wqz'>'>'C'CCN
  "2N3I5//99:D*3*@*@c)n%Gd1g+& !'5)9uE>JE5>JJJ$U+Yu-=5E''s5z:+ %))$c>**OOI& % 
		7$ &!&
( ,8(Wi)@AOA|s  q1NN3==):;<  B 	!
( 
(M377 ?,
( 
(s7   :PP2
P P
P$P-P A4P%%
P3c                   &    \ rS rSrS rS rS rSrg)_Kerneli  c                 (    Xl         X l        X0l        g r    )r:   r;   rH  )r"   r:   r;   rH  s       r%   rM   _Kernel.__init__  s    "r)   c                 ^   [        U[        R                  5      (       ah  [        U[        R                  5      (       dI  UR                  nU R                  R                  US5      nU" U R                  U R                  X!S5      nUnU R                  R                  U R                  XU5      $ )zNumpy uses cast semantics that are different from standard Python
(for example, it does allow casting from complex to float).

This method acts as a patch to context.cast so that it allows
complex to real/int casts.

real)r   r   Complexunderlying_floatr:   get_getattrr;   r   )r"   r<   r   r   newtyattrs         r%   r   _Kernel.cast  s     vu}}--4// ++E<<++FF;Dt||T\\6GCF ||  sDAAr)   c           
         U R                   nU R                  n[        XR                  UR                  5       VVVs/ s H  u  pEnU R	                  XEU5      PM     nnnnU R
                  R                  (       aZ  U R                  R                  R                  [        R                  [        R                  /[        UR                  5      -  5      nO:U R                  R                  R                  UR                  UR                  5      nU R                  R                  R                   R"                  n	[$        R&                  " XU R
                  R(                  R*                  5      n
U
R,                  R/                  S5        U R                  R                  R1                  U R                  XR                  UR                  U5      u  pU R	                  XR                  UR                  5      $ s  snnnf )Nalwaysinline)	inner_sigrH  ri   r   r   cres
objectmoder:   r  get_function_typer   pyobjectrh   r+  r;   blockfunctionmoduler   get_or_insert_functionfndescllvm_func_name
attributesaddcall_function)r"   r   isigosigr<   intyoutty	cast_args	func_typer  entry_point_r   s                r%   r@  _Kernel.generate  sx   ~~~~ yy$))464 *E YYs%04 	 6 99..@@ 03tyy> ACI ..@@  $))-I##,,3344II++- 	"">2''55LL+'7'7 yy..0@0@AA%6s   G7)r;   r:   rH  N)r/   r0   r1   r2   rM   r   r@  r3   r!   r)   r%   rp  rp    s    #
B(Br)   rp  c                 0   ^ ^  " UU 4S jS[         5      mT$ )a  Use the ufunc loop type information to select the code generation
function from the table provided by the dict_of_kernels. The dict
of kernels maps the loop identifier to a function with the
following signature: (context, builder, signature, args).

The loop type information has the form 'AB->C'. The letters to the
left of '->' are the input types (specified as NumPy letter
types).  The letters to the right of '->' are the output
types. There must be 'ufunc.nin' letters to the left of '->', and
'ufunc.nout' letters to the right.

For example, a binary float loop resulting in a float, will have
the following signature: 'ff->f'.

A given ufunc implements many loops. The list of loops implemented
for a given ufunc can be accessed using the 'types' attribute in
the ufunc object. The NumPy machinery selects the first loop that
fits a given calling signature (in our case, what we call the
outer_sig). This logic is mimicked by 'ufunc_find_matching_loop'.
c                   4   >^  \ rS rSrUU U4S jrS rSrU =r$ )'_ufunc_db_function.<locals>._KernelImpli  c           
        > [         TU ]  XU5        [        TUR                  [	        [        TU5      5      -   5      nUR                  T5      R                  UR                  5      U l	        [        UR                  UR                  5      U l        U R                  c'  Sn[        UR                  TR                   U5      5      eg )Nz2Don't know how to lower ufunc '{0}' for loop '{1}')superrM   r   r   r  r.  get_ufunc_infor  	ufunc_sigfnr   rG  r  r}  r   r   r/   )	r"   r:   r;   rH  loopr   _KernelImpl	__class__r-  s	         r%   rM   0_ufunc_db_function.<locals>._KernelImpl.__init__  s    +t-g	J+y~~.B5).T(UUWD,,U377GDG,T\\4;;GDNwwJ)#**U^^T*JKK r)   c           
      D   U R                   nU R                  n[        XR                  UR                  5       VVVs/ s H  u  pEnU R	                  XEU5      PM     nnnn[        U R                  S5         U R                  U R                  U R                  X'5      nS S S 5        U R                  R                  n	XR                     R                  U R                  W5      nU R	                  XR                  UR                  5      $ s  snnnf ! , (       d  f       Ny= f)Nnumpy)r}  rH  ri   r   r   r
   r:   r  r;   r   r+  from_return)
r"   r   r  r  r<   r  r  r  r   dmms
             r%   r@  0_ufunc_db_function.<locals>._KernelImpl.generate  s    >>D>>D 25T9959YY2@A2@-S 3e42@  A #4<<9ggdllDLL$J :,,11C&&'33DLL#FC99S"2"2D4D4DEEA :9s   D
6(D
D)r  r}  )r/   r0   r1   r2   rM   r@  r3   __classcell__)r  r  r-  s   @r%   r  r    s    		L	F 	Fr)   r  )rp  )r-  r  s   `@r%   _ufunc_db_functionr    s    ,F Fg F2 r)   c                    ^ ^ UU 4S jn[         R                  nU4T R                  -  n[        T R                  S-   5       H(  n[         R
                  4U-  nU" T /UQUQ76 " U5        M*     T$ )Nc                     > [        XX#TT5      $ r    rR  r:   r;   r   r   rI  r-  s       r%   do_ufunc'register_ufunc_kernel.<locals>.do_ufunc      !'CufMMr)   r9   )r   Anyr:  rz   r*  r   )r-  rI  lowerr  _anyin_argsn_explicit_outout_argss   ``      r%   register_ufunc_kernelr    sk    N 99Dg		!G  

Q/KK>N2e)g))(3 0 Mr)   c                 d   ^^ U(       a   eUU4S jn[         R                  nU" X5      " U5        g )Nc                     > [        XX#TT5      $ r    r  r  s       r%   lower_unary_operator<register_unary_operator_kernel.<locals>.lower_unary_operator  r  r)   )r   r   )operatorr-  rI  r  inplacer  	_arr_kinds    ``    r%   register_unary_operator_kernelr    s(    ;NI	(34r)   c                    ^^ UU4S jnUU4S jn[         R                  n[         R                  nX4Xx4X4/n	U	 H*  n
U(       d  U" U /U
Q76 " U5        M  U" U /U
Q76 " U5        M,     g )Nc                     > [        XX#TT5      $ r    r  r  s       r%   lower_binary_operator>register_binary_operator_kernel.<locals>.lower_binary_operator   r  r)   c                    > [        U5      US   4-   n[        R                  " UR                  /UR                  UR                  S   4-   Q76 n[        XX#TT5      $ ry   )r  r   r\  r+  r   rR  r  s       r%   lower_inplace_operator?register_binary_operator_kernel.<locals>.lower_inplace_operator  sV     T{d1gZ'sKSXXa[N1JK!'CufMMr)   )r   r  r   )opr-  rI  r  r  r  r  r  r  formal_sigsr   s    ``        r%   register_binary_operator_kernelr    sg    NN 99DI)D+<y>OPK"OsO12"OsO23	 r)   c                 X     " S S[         5      n[        XX#[        R                  U5      $ )zLowering function for +(array) expressions.  Defined here
(numba.targets.npyimpl) since the remaining array-operator
lowering functions are also registered in this module.
c                       \ rS rSrS rSrg)1array_positive_impl.<locals>._UnaryPositiveKerneli  c                     Uu  nU$ r    r!   )r"   r   r<   s      r%   r@  :array_positive_impl.<locals>._UnaryPositiveKernel.generate  s    ESJr)   r!   N)r/   r0   r1   r2   r@  r3   r!   r)   r%   _UnaryPositiveKernelr    s    	r)   r  )rp  rR  nppositive)r:   r;   r   r   r  s        r%   array_positive_implr    s*    w 
 g2;;24 4r)   c           
         0 nU  H  n[        U5      n[        X4U5      X#'   M     [        R                  R                  [        R
                  R                  4 Hu  nUR                  5        H^  u  pg[        [        U5      nX#   nUR                  S:X  a  [        XcX5        M7  UR                  S:X  a  [        XcX5        MU  [        S5      e   Mw     [        R                  R                  4 Hs  nUR                  5        H\  u  pg[        [        U5      nX#   nUR                  S:X  a  [        XcXSS9  M6  UR                  S:X  a  [        XcXSS9  MS  [        S5      e   Mu     g )Nr9   rT  z4There shouldn't be any non-unary or binary operatorsT)r  )r  r  r   NumpyRulesUnaryArrayOperator_op_mapNumpyRulesArrayOperatoritemsgetattrr  r:  r  r  r;  NumpyRulesInplaceArrayOperator)	ufuncsr  kernelsr-  db_funcr  r  
ufunc_namerI  s	            r%   register_ufuncsr  '  s8   G$U+.uuE  88@@33;; %,MMO HB
+E^FyyA~.xNa/O"#YZZ %4 ::BB $+MMO HB
+E^FyyA~.x7;=a/8<> ##YZZ %4r)   c                 |  ^ U4S jn[        T[        R                  5      (       a1  [        [        R
                  " TR                  5      5      nU" U5      $ [        T[        R                  R                  5      (       a<  [        TR
                  5      n[        [        R
                  " U5      5      nU" U5      $ g)zPGiven a string or NumberClass description *desc*, returns the dtype object.
    c                 L   > [         R                  " U 5      nU" T5      nS nX#4$ )Nc                 "    U R                  5       $ r    )get_dummy_value)r:   r;   r\  r   s       r%   codegen9_make_dtype_object.<locals>.from_nb_type.<locals>.codegenT  s     **,,r)   )r   DType)nb_typer+  r   r  descs       r%   from_nb_type(_make_dtype_object.<locals>.from_nb_typeP  s*    kk'*$	-
 |r)   N)
r   r   Literalr   r  r   literal_value	functionsNumberClassr   )	typingctxr  r  r  thestrs    `   r%   _make_dtype_objectr  L  s    	 $&&RXXd&8&89:G$$	D%//55	6	6TZZRXXf-.G$$	 
7r)   c                     [        U [        R                  [        R                  R                  45      (       a  S nU$ [
        R                  " SR                  U 5      5      e)zKProvide an implementation so that numpy.dtype function can be lowered.
    c                     [        U 5      $ r    )r  )r  s    r%   impnumpy_dtype.<locals>.impj  s    %d++r)   zunknown dtype descriptor: {})r   r   r  r  r  r   NumbaTypeErrorr   )r  r  s     r%   numpy_dtyper  e  sK     $(C(CDEE	,
##$B$I$I$$OPPr)   )zinput operand)F)Lr_   mathsysr]  collectionsr   llvmlite.irr@   r  r  r  numba.npr   r   r   numba.np.ufunc.sigparser   numba.core.imputilsr   r	   r
   r   
numba.corer   r   r   r   r   r   numba.np.numpy_supportr   r   r   r   numba.np.arrayobjr   numba.core.typingr   numba.core.extendingr   r   r   registryobjectr   r5   rb   rv   r   r   USE_LEGACY_TYPE_SYSTEMr?   CPointerr
  np_intpr   r(  r.  r1  r4  rR  rn  rp  r  r  r  r  r  posr   r  r  
get_ufuncsr  r   r  r!   r)   r%   <module>r     s  
  
  "    6 6 34 4 F F  5 % 4 IF &,F &,R;:&<&:< ;6&F:n /= > &FRJ@Z 1Q R J@Z/6 
  **UZZ

1K$)JJuzz0JL  --u~~emm7T$)MM5>>%--3PR&PQ!j%58MD`I"Z/Bf /Bd/j  ,1542 
ekk*4 +4[D ##%x~~ 6 % %0 
"((Q Qr)   