
    J/Phq                     0   d Z ddlZddlZddlZddlmZ ddlmZ ddlZ	ddl
Z
ddlmZmZmZ ddlmZ ddlmZmZmZmZ ddlmZmZmZmZmZmZ ddlmZmZm Z m!Z! dd	l"m#Z# dd
l$m%Z% ddl&m'Z'm(Z( ddlm)Z)  ed          Z* G d de+          Z, G d de+          Z- G d d edd                    Z. G d d edd                    Z/ G d d edd                    Z0d/dZ1ej2        rD ej3        ej3         ej4        ej3                  ej3         ej4        ej3                            Z5nC ej6        ej6         ej4        ej6                  ej6         ej4        ej6                            Z5d Z7d Z8d Z9d  Z:d! Z;d" Z<d# Z= G d$ d%e+          Z>d& Z?d' Z@	 d0d)ZAd0d*ZBe*C                    e
jD        ejE                  d+             ZFd, ZG eG ejH                    e*jC                   e(d-             ZI e'e	jJ                  d.             ZKdS )1z3
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                       e Zd Zd Zd ZdS )_ScalarIndexingHelperc                     d S N )selfloop_indicesnames      P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/np/npyimpl.pyupdate_indicesz$_ScalarIndexingHelper.update_indices.           c                     d S r   r    r!   s    r$   	as_valuesz_ScalarIndexingHelper.as_values1   r&   r'   N__name__
__module____qualname__r%   r*   r    r'   r$   r   r   -   s2              r'   r   c                   @    e Zd ZdZd Zd Zd Zd Zed             Z	dS )_ScalarHelpera\  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   || _         || _        || _        || _        |                    t
          j                  }t          j        |d          g| _	        |t
          j
        k    r|                    |          nt          j        d          }t          j        ||          | _        d S N   )contextbuilderval	base_typeget_value_typer   intpirConstantshapebooleanget_data_typeIntTyper   alloca_once_ptr)r!   ctxtbldr6   tyintptyltys          r$   __init__z_ScalarHelper.__init__E   s    $$UZ00k&!,,-
(*em(;(;d  $$$A'S11			r'   c                     t                      S r   )r   r)   s    r$   create_iter_indicesz!_ScalarHelper.create_iter_indicesP   s    $&&&r'   c                     | j         S r   )r6   r!   indicess     r$   	load_dataz_ScalarHelper.load_dataS   s	    xr'   c                 F    | j                             || j                   d S r   )r5   storerA   )r!   rL   r6   s      r$   
store_dataz_ScalarHelper.store_dataV   s"    3	*****r'   c                 @    | j                             | j                  S r   )r5   loadrA   r)   s    r$   
return_valz_ScalarHelper.return_valY   s    |  +++r'   N)
r,   r-   r.   __doc__rG   rI   rM   rP   propertyrS   r    r'   r$   r0   r0   5   su         	2 	2 	2' ' '  + + + , , X, , ,r'   r0   c                       e Zd Zd Zd ZdS )_ArrayIndexingHelperc                 "   | j         j        }| j         j                            t          j                  }t          j        t          j        |j	                  d          }|t          |          t          | j                  z
  d          }t          || j        | j         j                  D ]`\  }}}	|                    d|	|          }
|                    |
          5  |                    ||           d d d            n# 1 swxY w Y   ad S )Nr3   >)arrayr5   r4   r8   r   r9   r:   r;   r?   widthlenrL   zipr<   icmp_unsignedif_thenrO   )r!   r"   r#   rC   rE   ONErL   srcdstdimconds              r$   r%   z#_ArrayIndexingHelper.update_indices`   s1   j #225:>>k"*V\22A66
 s<003t|3D3DDEEF $,
8HII 	$ 	$MCc$$S#s33DT"" $ $		#s###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $	$ 	$s    DD	
D	c                 B    | j         j        fd| j        D             S )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
        c                 :    g | ]}                     |          S r    rR   ).0indexrC   s     r$   
<listcomp>z2_ArrayIndexingHelper.as_values.<locals>.<listcomp>v   s#    :::E:::r'   )rZ   r5   rL   )r!   rC   s    @r$   r*   z_ArrayIndexingHelper.as_valuesn   s+     j ::::T\::::r'   Nr+   r    r'   r$   rW   rW   ^   s2        $ $ $; ; ; ; ;r'   rW   )rZ   rL   c                   *    e Zd ZdZd Zd Zd Zd ZdS )_ArrayHelperzHelper 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                    | j                             t          j                  }t	          j        t	          j        |j                  d          }g }t          | j	                  D ]c}t          j        | j        t	          j        |j                            }| j                            ||           |                    |           dt          | |          S Nr   )r4   r8   r   r9   r:   r;   r?   r[   rangendimr   r@   r5   rO   appendrW   r!   rE   ZEROrL   ixs         r$   rI   z _ArrayHelper.create_iter_indices   s    ,,UZ88{2:fl33Q77ty!! 	 	A#DL"*V\2J2JKKALtQ'''NN1#D'222r'   c           	      t    t          j        | j        | j        | j        | j        | j        | j        |          S N)datar<   strideslayoutinds)r   get_item_pointer2r4   r5   rx   r<   ry   rz   rK   s     r$   _load_effective_addressz$_ArrayHelper._load_effective_address   s<    ()-.2i/3z1504.57 7 7 	7r'   c                     | j         j        | j                 }|                     |          }|                    | j        |          S r   )r4   data_model_managerr7   r}   load_from_data_pointerr5   )r!   rL   modelptrs       r$   rM   z_ArrayHelper.load_data   s>    /?**733++DL#>>>r'   c                     | j         }| j        }|                    || j        |          }|                    | j                  |j        k    sJ |                    ||                     |                     d S r   )r4   r5   get_value_as_datar7   r>   typerO   r}   )r!   rL   valuectxrC   store_values         r$   rP   z_ArrayHelper.store_data   su    ll++CGG  00K4DDDDD		+t;;GDDEEEEEr'   N)r,   r-   r.   rT   rI   r}   rM   rP   r    r'   r$   rl   rl   y   s_         	3 	3 	37 7 7? ? ?
F F F F Fr'   rl   )	r4   r5   r<   ry   rx   rz   r7   rp   rS   c                   :    e Zd ZdZd Zd Zd Zd Zdd defdZ	d	S )
_ArrayGUHelperzHelper 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                    | j                             t          j                  }t	          j        t	          j        |j                  d          }g }t          | j	        | j
        j	        z
            D ]c}t          j        | j        t	          j        |j                            }| j                            ||           |                    |           dt!          | |          S rn   )r4   r8   r   r9   r:   r;   r?   r[   ro   rp   inner_arr_tyr   r@   r5   rO   rq   rW   rr   s         r$   rI   z"_ArrayGUHelper.create_iter_indices   s    ,,UZ88{2:fl33Q77ty4#4#99:: 	 	A#DL"*V\2J2JKKALtQ'''NN1#D'222r'   c           	         | j         }| j        }t          j        | j        | j        | j                  } |                    |          ||| j                  }t          j
        |||j        | j        | j        | j        |          S rw   )r4   r5   r   Arrayr7   rp   rz   
make_arrayrx   r   r|   r<   ry   )r!   rL   r4   r5   arr_tyarrs         r$   r}   z&_ArrayGUHelper._load_effective_address   s    ,,T^TYDD(g  (('49EE()0.1h/3z1504.57 7 7 	7r'   c           	         | j         | j        }}| j        j        dk    rD| j        r=|j        | j                 }|                     |          }|                    ||          S | j        j        dk    r\| j        sT|	                    t          j                  } |d          }t          j        | j        | j        | j                  }t          j        | j        d| j                  }	 |t          j        ||                    }
 | j                             |          ||| j                  } | j                             |	          ||          }t          j        ||                     |          t'          j        ||g          t'          j        ||
g          |j        |j        |j                   |                                S t          j        f| j        | j        j        z
  z  }t          j        | j        | j        | j                  } | j                             |          ||| j                  }t5          ||| j        ||||          }t7          ||| j        |          S )Nr   r3   )rx   r<   ry   itemsizememinfoparent)r4   r5   r   rp   is_input_argr   r7   r}   r   r8   r   r9   r   rz   r   get_itemsizer   rx   populate_arrayr   
pack_arrayr   r   r   	_getvalueint64r   r   )r!   rL   r4   r5   r   r   rE   onefromtytotyr   arr_fromarr_toindex_typesarrtyr   ress                    r$   rM   z_ArrayGUHelper.load_data   sH   <!Q&&4+<&.t~>E..w77C//===#q((1B( ++EJ77F&))C[DKHHF;t~q$+>>Dvh3GVDDEEH 7t|..v66w7>7;yB BH 3T\,,T227GDDF#11'::(3%88*7XJ??!* (( ( ( ( ##%%% !;.DI8I8N,NOKK	4;GGE0$,))%00'49MMC(')-):E3)4g? ?C %Wgt7H#NNNr'   c           	         | j         j        fd}| j        | j        }}t	          j        t	          j        t          j        t          |                    t	          j        t          j        t          | j	                                      }|
                    ||j        d         |          |
                    ||j        d         | j	                  f}|                    ||||           d S )Nc                     t          |          z
  }|t          |           k    }|s't          |          D ]}|||         | |         k    z  }|rt          d          d S )Nz&Loop and array shapes are incompatibler\   ro   
ValueError)
loop_shapearray_shape	remaining_raisert   
inner_ndims        r$   
raise_implz._ArrayGUHelper.guard_shape.<locals>.raise_impl   s    
 K((:5I#j//1F @y)) @ @A{1~A>?FF K
 !!IJJJK Kr'   r   r3   )r   rp   r4   r5   r   noneUniTupler9   r\   r<   
make_tupleargscompile_internal)r!   	loopshaper   r4   r5   sigtupr   s          @r$   guard_shapez_ArrayGUHelper.guard_shape   s    &+
	K 	K 	K 	K 	K"  <jN5:s9~~66N5:s4:77
 
 !!'38A;	BB!!'38A;
CCE  *c3?????r'   otherndimsc           	         fd}| j         | j        }}t          j        t          j        t          j        t          | j                            t          j        t          j        t          |j                                      }|                    ||j	        d         | j                  |                    ||j	        d         |j                  f}|
                    ||||           d S )Nc                     d}t          |           z
  t          |          z
  }}t                    D ]}|| ||z            |||z            k    z  }|sd}t          |          d S )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brt   msgr   s          r$   r   z8_ArrayGUHelper.guard_match_core_dims.<locals>.raise_impl  s    Dz??U*C,<,<u,DqA5\\ @ @
1q5)[Q-??? 
&A !oo%
& 
&r'   r   r3   )r4   r5   r   r   r   r9   r\   r<   r   r   r   )r!   r   r   r   r4   r5   r   r   s     `     r$   guard_match_core_dimsz$_ArrayGUHelper.guard_match_core_dims  s    	& 	& 	& 	& 	&"  <jN5:s4:77N5:s5;'7'788
 
 !!'38A;
CC!!'38A;DDG  *c3?????r'   N)
r,   r-   r.   rT   rI   r}   rM   r   intr   r    r'   r$   r   r      s         	3 	3 	37 7 7)O )O )OV@ @ @8 @+;  @C  @  @  @  @  @  @r'   r   )
r4   r5   r<   ry   rx   rz   r7   rp   r   r   input operandc                    t          |t          j                  r!|}|j        }|                     ||||          }t          |t          j                  r |                     |          | ||          }t          j        ||j	        |j
                  }t          j        ||j        |j
                  }t          | ||||j        |j        |j        |j
        |	  	        S t          j        |          t          j        t          j        hz  v st          |t          j        j                  rt+          | |||          S t-          d                    |t1          |                              )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_tupler<   rp   ry   rl   rx   rz   dtype	unliteralnumber_domainr=   scalars_NPDatetimeBaser0   NotImplementedErrorformatstr)	rB   rC   inptyinpwhereotyaryr<   ry   s	            r$   _prepare_argumentr   /  sN    %(( .
iiS#u-- %.// /($//%((sC88&sCIuzBB&sCKDDD#ugsx!L%+uz3H H 	H
/%
 
 E$75=/$I
I
Iu}<== JT3U333!"A"H"H"%e**#. #. / / 	/r'   c                     | |k    rdS d}|| z
  }|| k     rD||         }||         }|dk    r||k    r|dk    r|dz    S n|dk    r|||<   |dz  }|dz  }|| k     D|S )a  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   r3   r    )src_ndim	src_shape	dest_ndim
dest_shape	src_index
dest_indexsrc_dim_sizedest_dim_sizes           r$   _broadcast_ontor   Q  s     ) q	)
(""$Y/L&z2M !!  =00\Q5F5F'!^,,"")5
:&NI!OJ (""  r'   c                     d |D             }                      t          j                  } fd} |d          } |d          }t          j        ||j        d          }	 ||j                  }
t          j        ||j        d          t          fdt          |j                  D                       }|D ]}                    ||           t          |          D ]9\  }}t          |d          s ||j                  }t          |j                  D ]7}                    |j        |         t          j        |	|                     8                     t          t          ||	|
g          }t          j                            d	||                    5  d
|fz  }t$          j                            dd          }||d|j        |j        fz  z  } j                            t2          |f           ddd           n# 1 swxY w Y   ;|j        }t          fd|D                       }t7          j         ||          }t;          |          }||         }	                      d |||                    }||         j        |                                 f} ||          }n?# tB          $ r2 |j"        t          j#        j"        k    r |                                 }Y nw xY w|j        }t          j$        |j        |          }t          j$        |j%        |          }tM           |||j'        |j(        |j)        ||	  	        S )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                 T    g | ]%}t          |t          j                  r|j        n|&S r    )r   r   r   r   rh   ru   s     r$   rj   z _build_array.<locals>.<listcomp>  s?     ) ) ) (5>::A166 ) ) )r'   c                 D                         t          j        |           S r   )get_constantr   r9   )r6   r4   s    r$   make_intp_constz%_build_array.<locals>.make_intp_const  s    ##EJ444r'   r   r3   r   r   c              3   D   K   | ]}t          j        |          V  d S r   )r   gep_inbounds)rh   ri   r5   r   s     r$   	<genexpr>z_build_array.<locals>.<genexpr>  sN       @ @!& %1':uMM @ @ @ @ @ @r'   rp   <z/unable to broadcast argument %d to output arraylocNz
File "%s", line %d, c              3   B   K   | ]}                     |          V  d S r   rg   )rh   dest_shape_addrr5   s     r$   r   z_build_array.<locals>.<genexpr>  sK       D D. #<<88 D D D D D Dr'   __array_wrap__)*r8   r   r9   r   r@   rp   tuplero   rO   	enumeratehasattrr<   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_functionrS   r   r   array_priorityr   r   ry   rl   rx   rz   r   ) r4   r5   array_tyinput_typesinputsintp_tyr   rs   r`   r   r   dest_shape_addrsr   
arg_numberargarg_ndimri   
arg_resultr   r   real_array_tydest_shape_tup	array_valarray_wrapper_indexarray_wrapper_ty
array_wrap	wrap_argsout_valrp   r<   ry   r   s    ``                             @r$   _build_arrayr  y  s   ) )') ) )K $$UZ00G5 5 5 5 5 ?1D
/!

C#GWhm$/1 1I..I$Wgx}%13 3J @ @ @ @ @*/*>*>@ @ @ @ @ , , ,c?++++
 %V,, K K
CsF## 	"?38,,38__ 	K 	KEMM#)E*!.w	5IIK K K K--_&9y)Z8: :
  !(!4!4S*c!J!JL L 		K 		KCG C /%%eT22C/3<2JJJ--gzC6JJJ		K 		K 		K 		K 		K 		K 		K 		K 		K 		K 		K 		K 		K 		K 		K %M D D D D2BD D D D DN'-(68 8I /{;;"#671))*:*2(3C]*S*SU U
 /0;Y=P=P=R=RS	*Wi00  ( ( ( *ek.HHH%%''( =D"7IOTBBE"7I,=tDDG%). ! ! !s%   -AHH	H	6 K 9L ?L c                 P    | j         dk    r|j        gS t          |j                  S r2   )noutreturn_typelist)ufuncr   s     r$   _unpack_output_typesr    s(    zQ  CO$$$r'   c                 H    | j         dk    r|gS t          j        ||          S r2   )r  r   r   )r  r5   valuess      r$   _unpack_output_valuesr    s'    zQx#GV444r'   c                 V    | j         dk    r|d         S |                    |||          S )Nr3   r   )r  r   )r  r4   r5   typr  s        r$   _pack_output_valuesr    s/    zQay!!'3777r'   c           
           fdt          ||j                  D             }t          |          |j        k     r;t	          d                    |j        |j        t          |                              t          t          ||                    D ]\  }}|j        |z   t          |          k    rt          |t          j                  rt           ||j        |          }	n8t           t          j                             |          d           |          }	|                    |	            j        r* j                            |||j        |z                       |d |j                 }
||j        d          }t          |          |j        k    sJ t-          d |D             d |
D                       } | |          }                     t          j                  }d |
D             }|d         j        }d |
D             }t          d |D                       }t          d	 |D                       }||k    rd
}nd}t3          j        |||          5 }g }t          t          ||
                    D ]X\  }\  }}|                    ||           |                    |                    |                                                     Yt=          | |j        |           }t          ||          D ]\  }}	|	                     ||           	 d d d            n# 1 swxY w Y   tC          | |j"        d |D                       }tG           |j"        |          S )Nc                 :    g | ]\  }}t          ||          S r    )r   )rh   r  tyargr5   r4   s      r$   rj   z&numpy_ufunc_kernel.<locals>.<listcomp>  s;     8 8 8S% #7GS%@@ 8 8 8r'   z+Not enough inputs to {}, expected {} got {}c                     g | ]	}|j         
S r    r7   rh   r   s     r$   rj   z&numpy_ufunc_kernel.<locals>.<listcomp>
  s    &&&&&&r'   c                     g | ]	}|j         
S r    r"  r#  s     r$   rj   z&numpy_ufunc_kernel.<locals>.<listcomp>  s    %%%%%%r'   c                 6    g | ]}|                                 S r    rI   rh   r   s     r$   rj   z&numpy_ufunc_kernel.<locals>.<listcomp>  s$    ;;;Ss&&((;;;r'   r   c                 F    g | ]}t          |t                    |j        S r    )r   rl   rz   r'  s     r$   rj   z&numpy_ufunc_kernel.<locals>.<listcomp>  s8     7 7 7C"3557SZ 7 7 7r'   c                     g | ]
}|d k    |S Cr    r   s     r$   rj   z&numpy_ufunc_kernel.<locals>.<listcomp>      ===aAHHHHHr'   c                     g | ]
}|d k    |S Fr    r   s     r$   rj   z&numpy_ufunc_kernel.<locals>.<listcomp>  r,  r'   r/  r+  r9   orderc                     g | ]	}|j         
S r    )rS   )rh   os     r$   rj   z&numpy_ufunc_kernel.<locals>.<listcomp>/  s    HgHgHgZ[HgHgHgr'   )$r]   r   r\   ninRuntimeErrorr   r,   r   r  r   r   r   r  r   r:   r;   r8   rq   
enable_nrtnrtincrefr  r   r9   r<   r   	loop_nestr%   rM   r*   r  generaterP   r  r  r	   )r4   r5   r   r   r  kernel_class	argumentsout_iret_tyoutputr  outputs	outer_sigkernelrE   rL   r   input_layoutsnum_c_layoutnum_f_layoutr1  r"   vals_inrt   ri   r  vals_outval_outouts   ``                           r$   numpy_ufunc_kernelrJ    s	   8 8 8 8 8#&tSX#6#68 8 8I 9~~	!!9VENEIs9~~>>@ @ 	@ ##7s#C#CDD I Iv9uI..&%"788 O%gw)TT*WK 6 6v > >EEvO O V$$$$ 	IKwUY5F0GHHHz	z"F	

#Gw<<5:%%%%&&g&&&%%f%%% I \'7I66F##EJ//F;;F;;;G 
 I7 76 7 7 7M======>>L======>>L l""		7IF%	H	H	H 5L(Wf)=)=>> 	= 	=OA|s  q111NN3==):):;;<<<<('9RSS"8W55 	5 	5OGVlG4444	55 5 5 5 5 5 5 5 5 5 5 5 5 5 5 eWgsHgHg_fHgHgHg
h
hCGWcosCCCs   *B>L55L9<L9c                    g }|j                                         }|d         |d         z   }dg|j        z  dg|j        z  z   }t	          ||j        ||          D ]\  }	}
}}t          |
t          j                  r | 	                    |
          | ||	          }t          j        ||j        |
j                  }t          j        ||j        |
j                  }|
                    |          }|
j        }|
j        }|
j        }t%          | ||||	|||||
  
        }|                    |           t)          | ||	|
          }|                    |            || ||          }d |D             }t+          d |D                       }t+          d |D                       }||k    rd	}nd
}||j        d          }|                     t          j                  }d |D             }|d         j        |d         j        j        z
  }|d         j        d |         }t3          |j        j                  } t9          j        t	          t=          t+          |                    | d         | d         z             d          D ]o\  \  }!}"\  }#}$||!         ||#         }&}%|"|$k    rNt?          d |%|&fD                       r3||!         ||#         }&}%|%                     |&t+          |"                     p|d |j                 D ],}	t          |	t$                    r|	!                    |           -t          j"        ||||          5 }'g }(tG          t	          ||                    D ]X\  })\  }*}	|*$                    |'|)           |(                    |	%                    |*&                                                     Y |j'        |(  d d d            d S # 1 swxY w Y   d S )Nr   r3   TF)rp   c                 F    g | ]}t          |t                    |j        S r    )r   r   rz   )rh   r  s     r$   rj   z'numpy_gufunc_kernel.<locals>.<listcomp>M  s8     3 3 3cS.113sz 3 3 3r'   c                     g | ]
}|d k    |S r*  r    r   s     r$   rj   z'numpy_gufunc_kernel.<locals>.<listcomp>O      777aa3hhhhhr'   c                     g | ]
}|d k    |S r.  r    r   s     r$   rj   z'numpy_gufunc_kernel.<locals>.<listcomp>P  rN  r'   r/  r+  c                 6    g | ]}|                                 S r    r&  r'  s     r$   rj   z'numpy_gufunc_kernel.<locals>.<listcomp>]  s$    >>>Ss&&((>>>r'      )rc              3   @   K   | ]}t          |t                    V  d S r   )r   r   r   s     r$   r   z&numpy_gufunc_kernel.<locals>.<genexpr>k  s,      JJaJq.11JJJJJJr'   r0  )(dufuncexpected_ndimsr4  r  r]   r   r   r   r   r   r   r   r<   rp   ry   copyrz   r   r   rq   r0   r\   r8   r9   r   r   gufunc_builder	signature	itertoolscombinationsro   allr   r   r9  r   r%   rM   r*   r:  )+r4   r5   r   r   r  r;  r<  rU  is_inputr  rD   exp_ndimis_inpr   r<   ry   r   rp   rz   r7   array_helperscalar_helperrB  layoutsrD  rE  r1  r@  rE   rL   loopshape_ndimr   _sigidx_asig_aidx_bsig_barg_aarg_br"   rF  rt   ri   s+                                              r$   numpy_gufunc_kernelrj  3  s~   I!(7799N#A&)::Nv	!UGej$88H%(sx%R%R , ,!R6b%/00 	, )'$$R(('3??C(#)RWEEE*7CKIIG77711L7DYFI)'7*/#*0)T*6@ @L \****)'7CDDM]++++\'7C00F3 3Y 3 3 3G77777788L77777788L l""	

#G##EJ//F>>I>>>GQZ_wqz'>'CCN
 "2N"23I5/9::D*3*@c)nn%%Gd1g + + + ; ;& !'5)9uE>>JJE5>JJJJJ $U+Yu-=5E''s5zz:::%)$ ' 'c>** 	'OOI&&&		7$ &!&
( 
( 
( 	" ,8(Wi)@)@AA 	= 	=OA|s  q111NN3==):):;;<<<<!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   BOO"%O"c                        e Zd Zd Zd Zd ZdS )_Kernelc                 0    || _         || _        || _        d S r   )r4   r5   rA  )r!   r4   r5   rA  s       r$   rG   z_Kernel.__init__  s    "r'   c                 (   t          |t          j                  rWt          |t          j                  s=|j        }| j                            |d          } || j        | j        ||d          }|}| j                            | j        |||          S )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_floatr4   get_getattrr5   r   )r!   r6   r   r   newtyattrs         r$   r   z_Kernel.cast  s     vu}-- 	4//	 +E<++FF;;D$t|T\63GGCF |  sFDAAAr'   c                      j         } j        } fdt          ||j        |j                  D             } j        j        rK j        j                            t          j
        t          j
        gt          |j                  z            }n* j        j                            |j        |j                  } j        j        j        j        }t#          j        || j        j        j                  }|j                            d            j        j                             j        ||j        |j        |          \  }}	                     |	|j        |j                  S )Nc                 F    g | ]\  }}}                     |||          S r    r   rh   r6   intyouttyr!   s       r$   rj   z$_Kernel.generate.<locals>.<listcomp>  s?     6 6 6)dE YYsD%00 6 6 6r'   alwaysinline)	inner_sigrA  r]   r   cres
objectmoder4   r   get_function_typer   pyobjectr\   r  r5   blockfunctionmoduler   get_or_insert_functionfndescllvm_func_name
attributesaddcall_functionr   )
r!   r   isigosig	cast_args	func_typer  entry_point_r   s
   `         r$   r:  z_Kernel.generate  sO   ~~6 6 6 6ty$)446 6 6	 9 	-.@@ 03ty>> AC CII .@@ $)- -I#,34II+- - 	"">222'55L+t'7 3 yyd.0@AAAr'   N)r,   r-   r.   rG   r   r:  r    r'   r$   rl  rl    sI        # # #
B B B(B B B B Br'   rl  c                 6      G  fddt                     S )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                   *     e Zd Z fdZd Z xZS )'_ufunc_db_function.<locals>._KernelImplc           
         t          |                               |||           t          |j        t	          t          |                    z             }|                                                  |j                  | _	        t          |j        |j                  | _        | j	        *d}t          |                    j        |                    d S )Nz2Don't know how to lower ufunc '{0}' for loop '{1}')superrG   r   r   r   r  get_ufunc_infor   	ufunc_sigfnr   r@  r  r|  r   r   r,   )	r!   r4   r5   rA  loopr   _KernelImpl	__class__r  s	         r$   rG   z0_ufunc_db_function.<locals>._KernelImpl.__init__  s    +t$$--gw	JJJ+y~.B5).T.T(U(UUW WD,,U3377GGDG,T\4;GGDNwJ)#**U^T*J*JKKK r'   c                      j         } j        } fdt          ||j        |j                  D             }t	           j        d          5                        j         j        ||          }d d d            n# 1 swxY w Y    j        j        }||j	                 
                     j        |          }                     ||j	        |j	                  S )Nc                 F    g | ]\  }}}                     |||          S r    rw  rx  s       r$   rj   zD_ufunc_db_function.<locals>._KernelImpl.generate.<locals>.<listcomp>  sE     A A A-S$ 3e44 A A Ar'   numpy)r|  rA  r]   r   r
   r4   r  r5   r   r  from_returnr   )r!   r   r  r  r  r   dmms   `      r$   r:  z0_ufunc_db_function.<locals>._KernelImpl.generate  s1   >D>DA A A A14T4959Y2@ 2@A A AI #4<99 K KggdlDL$	JJK K K K K K K K K K K K K K K,1Cd&'33DL#FFC99S$"2D4DEEEs   #A;;A?A?)r,   r-   r.   rG   r:  __classcell__)r  r  r  s   @r$   r  r    s`        		L 		L 		L 		L 		L 		L 		L	F 	F 	F 	F 	F 	F 	Fr'   r  )rl  )r  r  s   `@r$   _ufunc_db_functionr    sP    ,F F F F F F F Fg F F F2 r'   c                       fd}t           j        }|f j        z  }t           j        dz             D ]&}t           j        f|z  }  | g||R  |           'S )Nc                 ,    t          | |||          S r   rJ  r4   r5   r   r   rB  r  s       r$   do_ufuncz'register_ufunc_kernel.<locals>.do_ufunc      !'7CufMMMr'   r3   )r   Anyr4  ro   r  r   )r  rB  lowerr  _anyin_argsn_explicit_outout_argss   ``      r$   register_ufunc_kernelr    s    N N N N N N 9Dg	!G  
Q// 4 4K>N2)e)g))))(3333Mr'   Fc                 `    |rJ fd}t           j        }  || |          |           d S )Nc                 ,    t          | |||          S r   r  r  s       r$   lower_unary_operatorz<register_unary_operator_kernel.<locals>.lower_unary_operator  r  r'   )r   r   )operatorr  rB  r  inplacer  	_arr_kinds    ``    r$   register_unary_operator_kernelr    s^    N N N N N NIEE(I344444r'   c                     fd}fd}t           j        }t           j        }||f||f||fg}	|	D ])}
|s  || g|
R  |             || g|
R  |           *d S )Nc                 ,    t          | |||          S r   r  r  s       r$   lower_binary_operatorz>register_binary_operator_kernel.<locals>.lower_binary_operator   r  r'   c                     t          |          |d         fz   }t          j        |j        g|j        |j        d         fz   R  }t          | |||          S rn   )r   r   rX  r  r   rJ  r  s       r$   lower_inplace_operatorz?register_binary_operator_kernel.<locals>.lower_inplace_operator  s\     T{{d1gZ'sKSXa[N1JKKK!'7CufMMMr'   )r   r  r   )opr  rB  r  r  r  r  r  r  formal_sigsr   s    ``        r$   register_binary_operator_kernelr    s    N N N N N NN N N N N N 9DIy)D)+<y$>OPK 4 4 	4EE"OsOOO12222EE"OsOOO23333	4 4r'   c                 d     G d dt                     }t          | |||t          j        |          S )zLowering function for +(array) expressions.  Defined here
    (numba.targets.npyimpl) since the remaining array-operator
    lowering functions are also registered in this module.
    c                       e Zd Zd ZdS )1array_positive_impl.<locals>._UnaryPositiveKernelc                     |\  }|S r   r    )r!   r   r6   s      r$   r:  z:array_positive_impl.<locals>._UnaryPositiveKernel.generate  s    ESJr'   N)r,   r-   r.   r:  r    r'   r$   _UnaryPositiveKernelr    s#        	 	 	 	 	r'   r  )rl  rJ  nppositive)r4   r5   r   r   r  s        r$   array_positive_implr    sO        w   
 gwT2;24 4 4r'   c           	         i }| D ]%}t          |          }t          |||          ||<   &t          j        j        t          j        j        fD ]}|                                D ]l\  }}t          t          |          }||         }|j	        dk    rt          ||||           @|j	        dk    rt          ||||           ^t          d          t          j        j        fD ]}|                                D ]p\  }}t          t          |          }||         }|j	        dk    rt          ||||d           B|j	        dk    rt          ||||d           bt          d          d S )Nr3   rQ  z4There shouldn't be any non-unary or binary operatorsT)r  )r  r  r   NumpyRulesUnaryArrayOperator_op_mapNumpyRulesArrayOperatoritemsgetattrr  r4  r  r  r5  NumpyRulesInplaceArrayOperator)	ufuncsr  kernelsr  db_funcr  r  
ufunc_namerB  s	            r$   register_ufuncsr  '  s   G F F$U++.uguEE8@3; [ [ %,MMOO 	[ 	[ HjB
++EU^FyA~~.xNNNNa/%OOOO"#YZZZ	[ :B  [ [$+MMOO 
	[ 
	[ HjB
++EU^FyA~~.x7;= = = = =a/%8<> > > > > ##YZZZ
	[[ [r'   c                 f   fd}t          t          j                  r1t          t	          j        j                            } ||          S t          t          j        j                  r@t          j                  }t          t	          j        |                    } ||          S dS )zPGiven a string or NumberClass description *desc*, returns the dtype object.
    c                 P    t          j        |           } |          }d }||fS )Nc                 *    |                                  S r   )get_dummy_value)r4   r5   rX  r   s       r$   codegenz9_make_dtype_object.<locals>.from_nb_type.<locals>.codegenT  s     **,,,r'   )r   DType)nb_typer  r   r  descs       r$   from_nb_typez(_make_dtype_object.<locals>.from_nb_typeP  s<    k'**k$	- 	- 	-
 G|r'   N)
r   r   Literalr   r  r   literal_value	functionsNumberClassr   )	typingctxr  r  r  thestrs    `   r$   _make_dtype_objectr  L  s    	 	 	 	 	 $&& %RXd&899::|G$$$	D%/5	6	6 %TZRXf--..|G$$$	% %r'   c                     t          | t          j        t          j        j        f          rd }|S t          j        d                    |                     )zKProvide an implementation so that numpy.dtype function can be lowered.
    c                      t          |           S r   )r  )r  s    r$   impz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  sW     $(CDEE Q	, 	, 	,
#$B$I$I$$O$OPPPr'   )r   )F)LrT   mathsysrY  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   r0   rW   rl   r   r   USE_LEGACY_TYPE_SYSTEMr9   CPointerr   np_intpr   r  r  r  r  rJ  rj  rl  r  r  r  r  r  posr   r  r  
get_ufuncsr  r   r  r    r'   r$   <module>r     s   
  



     " " " " " "            6 6 6 6 6 6 6 6 6 6 3 3 3 3 3 34 4 4 4 4 4 4 4 4 4 4 4 F F F F F F F F F F F F F F F F            5 4 4 4 4 4 % % % % % % 4 4 4 4 4 4 4 4      8I    F   &, &, &, &, &,F &, &, &,R; ; ; ; ;::&<&:< < ; ; ;6&F &F &F &F &F::n /= > > &F &F &FRJ@ J@ J@ J@ J@ZZ 1Q R R J@ J@ J@Z/ / / /6 
  R$%*UZ
1K1K$)Juz0J0JL L (%-~u~em7T7T$)M>5>%-3P3PR R& & &PQ! Q! Q!j% % %5 5 58 8 8MD MD MD`I" I" I"Z/B /B /B /B /Bf /B /B /Bd/ / /j    ,15 5 5 54 4 4 42 
ek**4 4 +*4[ [ [D ##%%x~ 6 6 6 % % %0 
"(Q Q Q Q Qr'   