
    xKg                        d dl Z d dlZd dl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 d dlmZ d dl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! d dlm"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z*  G d d      Z+d Z, G d de      Z- G d dej\                  ej^                  e      Z0e!jb                  je                  e0       y)    N)jittypeof)cgutilstypes	serializesigutilserrors)	is_jittedoverload_attributeoverload_methodregister_jitable	intrinsic)npydecl)AbstractTemplate	signature)tuple_setitem)	_internal)	UfuncBaseUfuncLowererBase)array_analysis)ufuncbuilder)numpy_support)Callable)ir)global_compiler_lockc                   D    e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zy)UfuncAtIteratorNc                 f    || _         || _        || _        || _        || _        || _        || _        y N)ufuncaa_tyindices
indices_tybb_ty)selfr    r!   r"   r#   r$   r%   r&   s           Y/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/np/ufunc/dufunc.py__init__zUfuncAtIterator.__init__   s3    
	$	    c                     | j                  ||       | j                  j                         \  }}| j                  |||       | j                  j	                          y r   )_prepareindexerbegin_loops_call_ufunc	end_loops)r'   contextbuilderloop_indices_s        r(   runzUfuncAtIterator.run$   sH    gw',,224a'<8 r*   c                 J    t        | j                  t        j                        S r   )
isinstancer$   r   	BaseTupler'   s    r(   need_advanced_indexingz&UfuncAtIterator.need_advanced_indexing*   s    $//5??;;r*   c                 R   ddl m}m} | j                  | j                  }}| j
                  | j                  }} |j                  t        j                        d      }	| j                  t        j                  ||	      | _        | j                         r<t        j                  ||t!        |            }|j                  }
 ||||
|      \  }
}n|f}|f}
 ||||
|      \  }
} ||||||
|      | _        | j"                  j%                          | j'                  ||      | _        y )Nr   )normalize_indicesFancyIndexer)count)numba.np.arrayobjr<   r=   r!   r#   r"   r$   get_value_typer   intpr%   r   alloca_once_valueb_indicer:   unpack_tuplelenr-   prepare_compile_ufunccres)r'   r1   r2   r<   r=   r!   r#   r"   r$   zeroindex_typess              r(   r,   zUfuncAtIterator._prepare-   s   EVVT\\799dooj1w%%ejj1!466#55gtDDM&&(**7G14ZBG$**K#4Wg5@'$K K jG%-K#4Wg5@'$K K $GWdA$/:''9	r*   c           	         ddl m} t        j                  ||j                        }t        j                  ||j
                        }|j                  }	t        j                  |||	|||j                  |      }
 |||||
      }|
|fS )Nr   )	load_item)	r?   rL   r   rD   shapestridesdataget_item_pointer2layout)r'   r1   r2   r3   arrayarray_tyrL   shapesrN   rO   ptrvals               r(   	_load_valzUfuncAtIterator._load_valI   sw    /%%gu{{;&&w>zz''$(0G(C8Cxr*   c                 T   |j                  |      }|j                  |t        j                        }|j	                  t
        j                  |      } ||||f      }	 |j                  t        j                        d      }
|j                  ||
      }|j                  ||       d |	fS )N   )
loaddtyper   rA   get_functionoperatorgetitemr@   addstore)r'   r1   r2   r#   rR   rS   idxsigimplrV   ones              r(   
_load_flatzUfuncAtIterator._load_flatT   s    ll7#nnXuzz2##H$4$4c:7UCL) 1g$$UZZ03kk#s#c7#Syr*   c                     ddl m} | j                  j                  j                  }|j
                  }	|j                  ||||	      } ||||||       y )Nr   )
store_item)r?   rg   rH   r   return_typer[   cast)
r'   r1   r2   rR   rS   rU   rV   rg   fromtytotys
             r(   
_store_valzUfuncAtIterator._store_vala   sG    0$$00~~ll7C67GXsC8r*   c                 2   | j                   j                  d   }| j                  | j                  j                  f}n,| j                  j                  | j
                  j                  f}|j                  |      }|j                  |j                  f       |S Nr   )	r    keyr%   r"   r[   r&   r_   add_linking_libslibrary)r'   r1   r2   r    rb   rH   s         r(   rG   zUfuncAtIterator._compile_ufunch   sm    

q!66>99??$C99??DIIOO4Cyy~  $,,1r*   c                    | j                   }| j                  | j                  }}| j                  |||||      \  }}| j                  |f}	n@| j                  | j
                  | j                  }}}
| j                  ||||
|      \  }}||f}	|j                  ||j                  |j                  |	      }| j                  ||||||       y r   )rH   r!   r"   rW   r%   r&   rC   re   call_internalfndescr   rl   )r'   r1   r2   r3   rH   r!   r"   rU   rV   argsr%   r&   b_idxr4   val_bress                   r(   r/   zUfuncAtIterator._call_ufunct   s    yy&&$))4>>'7L!TJS66>6D!VVTYYUtAw4HHAu<D##GT[[$..$(*!T3<r*   NN)__name__
__module____qualname__r)   r5   r:   r,   rW   re   rl   rG   r/    r*   r(   r   r      s/    !<:8	9
=r*   r   c                      ddl m}  G  fdd|j                        }|xj                   j                  j                  z  c_        |S )Nr   npyimplc                   *     e Zd ZdZW Z fdZ xZS )(make_dufunc_kernel.<locals>.DUFuncKernelz
        npyimpl._Kernel subclass responsible for lowering a DUFunc kernel
        (element-wise function) inside a broadcast loop (which is
        generated by npyimpl.numpy_ufunc_kernel()).
        c                     t         |   |||       | j                  j                  |j                        \  | _        | _        y r   )superr)   dufuncfind_ewise_functionru   	inner_sigrH   )r'   r1   r2   	outer_sig	__class__s       r(   r)   z1make_dufunc_kernel.<locals>.DUFuncKernel.__init__   s8    GWgy9(,(G(G) %DNDIr*   )rz   r{   r|   __doc__r   r)   __classcell__)r   _dufuncs   @r(   DUFuncKernelr      s    	
 	  	 r*   r   )numba.npr   _Kernelrz   r    )r   r   r   s   `  r(   make_dufunc_kernelr      s9      w   W]]333r*   c                   "     e Zd ZdZ fdZ xZS )DUFuncLowererzHCallable class responsible for lowering calls to a specific DUFunc.
    c                 P    ddl m} t        |   |t        |j
                         y )Nr   r   )r   r   r   r)   r   numpy_ufunc_kernel)r'   r   r   r   s      r(   r)   zDUFuncLowerer.__init__   s!    $+ 33	5r*   )rz   r{   r|   r   r)   r   r   s   @r(   r   r      s    5 5r*   r   c                   P    e Zd ZdZ ed      Zddi fdZ fdZd Ze	d        Z
d	 Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zd Zd Z fdZd Zed d       Zd Zd!dZd!dZd!dZd!dZd  fd	Z d dZ!d Z"d Z# xZ$S )"DUFuncz
    Dynamic universal function (DUFunc) intended to act like a normal
    Numpy ufunc, but capable of call-time (just-in-time) compilation
    of fast loops specialized to inputs.
    )identity
_keepaliveninnoutNFc                     t        |      r|j                  }t        j                         5   t	        dd|d||      }d d d        | j                  |       t        j                  | |       y # 1 sw Y   2xY w)Nnpyufunc)_targetcacher}   )r
   py_funcr   3_suppress_deprecation_warning_nopython_not_suppliedr   _initialize	functoolsupdate_wrapper)r'   r   r   r   targetoptions
dispatchers         r(   r)   zDUFunc.__init__   sy    WooGMMO. .Z#(.,..57J P 	X.  w/ POs   A22A;c                 &   t        j                  |      }t        t        |   ||       |j
                  j                  | _        |j
                  j                  | _        t        |       | _	        | j                          | j                          y )N)r   )r   parse_identityr   r   r)   r   rz   r   r   	_lower_me_install_cg_install_type)r'   r   r   r   s      r(   r   zDUFunc._initialize   ss    ..x8fd$Z($C #**33!))11&t,r*   c                     t        | j                  j                  j                               }t	        | j                  | j
                  | j                  |      S )4
        NOTE: part of ReduceMixin protocol
        )r   r   frozensiglist)list_dispatcher	overloadskeysdictr   _frozen)r'   r   s     r(   _reduce_stateszDUFunc._reduce_states   sJ     t''116689'']]<<	
 	
r*   c                     t         j                  j                  |       }|j                  ||       |D ]  }|j	                  |        |r|j                          |S )r   )r   _DUFunc__new__r   r_   disable_compile)clsr   r   r   r   r'   rb   s          r(   _rebuildzDUFunc._rebuild   sS    
   ((-X.CHHSM   "r*   c                     | S )zK
        For compatibility with the various *UFuncBuilder classes.
        r}   r9   s    r(   build_ufunczDUFunc.build_ufunc   s	     r*   c                 .    | j                   j                  S r   )r   r   r9   s    r(   r   zDUFunc.targetoptions   s    ---r*   c                 .    | j                   j                  S r   )r    r   r9   s    r(   r   z
DUFunc.nin   s    zz~~r*   c                 .    | j                   j                  S r   )r    r   r9   s    r(   r   zDUFunc.nout   s    zzr*   c                 .    | j                   j                  S r   )r    nargsr9   s    r(   r   zDUFunc.nargs       zzr*   c                 .    | j                   j                  S r   )r    ntypesr9   s    r(   r   zDUFunc.ntypes   s    zz   r*   c                 .    | j                   j                  S r   )r    r   r9   s    r(   r   zDUFunc.types   r   r*   c                 .    | j                   j                  S r   )r    r   r9   s    r(   r   zDUFunc.identity   s    zz"""r*   c                 .    | j                   j                  S r   )r    r   r9   s    r(   r   zDUFunc.signature   s    zz###r*   c                 Z    t        | j                  j                        dkD  sJ d| _        y)zI
        Disable the compilation of new signatures at call time.
        r   TN)rE   r   r   r   r9   s    r(   r   zDUFunc.disable_compile  s*    
 4##--.222r*   c                 V    t        j                  |      \  }}| j                  ||      S )z=
        Compile the DUFunc for the given signature.
        )r   normalize_signature_compile_for_argtys)r'   rb   ru   rh   s       r(   r_   z
DUFunc.add  s,     %88=k''k::r*   c                 $   t         j                  j                  j                  }|t	        |j                               z   D ]>  }t        t        |      d|      |us |j                  | dg|i |}|t        us<|c S  t        | (  |i |S )z}
        Allow any argument that has overridden __array_ufunc__ (NEP-18)
        to take control of DUFunc.__call__.
        __array_ufunc____call__)r   npndarrayr   tuplevaluesgetattrtypeNotImplementedr   r   )r'   ru   kwsdefaultargoutputr   s         r(   r   zDUFunc.__call__  s    
  ""**::%

--CtCy"3W=WL,,,T:LLL/!M	 . 7#T1S11r*   c           	      &   | j                   j                  }|rJd|v r|j                  d      }||fz  }|r-t        ddj	                  d t        |      D              z        t        |      }||k(  s||| j                   j                  z   k(  sJ |rJ g }|d | D ]Z  }t        |      }t        |t        j                        r|j                  }nt        j                  |      }|j                  |       \ | j!                  t#        |            S )Noutz)unexpected keyword arguments to ufunc: %sz, c              3   2   K   | ]  }t        |        y wr   )repr).0ks     r(   	<genexpr>z+DUFunc._compile_for_args.<locals>.<genexpr>)  s     +I[DG[   )r    r   pop	TypeErrorjoinsortedrE   r   r   r7   r   Arrayr[   r   map_arrayscalar_typeappendr   r   )	r'   ru   r   r   r   args_lenargtysr   argtys	            r(   _compile_for_argszDUFunc._compile_for_args!  s    jjnn|ggen K"&))+IVC[+I"I!J K K t9CXtzz1F%FGGw:C3KE%- &::3?MM%   ''f66r*   c                    | j                   rt        d|       t        |t              sJ ||}n || }| j                  j
                  j                         D ]B  \  }}||j                  k(  sd| d}t        j                  |t        j                         |c S  t        j                  | j                  | j                  |      \  }}}t        j                  |||      }t        j                   ||      \  }}	}
| j#                  t%        |	      |       | j&                  j)                  |	|j*                  |
f       | j,                  j.                  j)                  |j*                         |S )a/  
        Given a tuple of argument types (these should be the array
        dtypes, and not the array types themselves), compile the
        element-wise function for those inputs, generate a UFunc loop
        wrapper, and register the loop with the Numpy ufunc object for
        this DUFunc.
        compilation disabled for z>Compilation requested for previously compiled argument types (z~). This has no effect and perhaps indicates a bug in the calling code (compiling a ufunc more than once for the same signature)r   RuntimeErrorr7   r   r   r   itemsru   warningswarnr	   NumbaWarningr   _compile_element_wise_functionr   _finalize_ufunc_signature!_build_element_wise_ufunc_wrapper	_add_loopintr   r   rq   r   libs)r'   r   rh   rb   r   rH   msg
actual_sig	dtypenumsrU   envs              r(   r   zDUFunc._compile_for_argtys@  sO    <<FGG&%(((Cv&C''11779GAt""( *EE c6#6#67 : %1$O$Od00#%7!fk!;;&+'
*LL*	3s3x+T\\378""4<<0r*   c                      |j                   |k(  S r   )ru   )r'   ewise_typesrb   s      r(   match_signaturezDUFunc.match_signaturee  s    xx;&&r*   c                     dt         dt        fd}t        j                  |      }d}|D ]  } ||      } t	        ||      |        y )Nattrreturnc                       fd}|S )Nc                 B    t        | j                  d         fdS )Nr   c                     S r   r}   )r    rV   s    r(   <lambda>zUDUFunc._install_ufunc_attributes.<locals>.get_attr_fn.<locals>.impl.<locals>.<lambda>n  s    Sr*   )r   ro   )r    rV   r  s    @r(   rc   zCDUFunc._install_ufunc_attributes.<locals>.get_attr_fn.<locals>.impll  s    eiilD1((r*   r}   )r  rc   s   ` r(   get_attr_fnz5DUFunc._install_ufunc_attributes.<locals>.get_attr_fnj  s    ) Kr*   )r   r   r   r   r   )strr   r   Functionr   )r'   templater
  at
attributesr  attr_fns          r(   _install_ufunc_attributesz DUFunc._install_ufunc_attributesh  sR    	c 	h 	 ^^H%/
D!$'G(r4(1 r*   c                 H    | j                  |       | j                  |       y r   )_install_ufunc_reduce_install_ufunc_at)r'   r  s     r(   _install_ufunc_methodszDUFunc._install_ufunc_methods}  s    ""8,x(r*   c                 Z     t        j                  |      }t        |d      d fd	       }y )Nr  c                     t        j                  dt        j                         t	        |t
        j                        sd}t        j                  |      t	        |t
        j                        }t	        |t
        j                        }t	        |t
        j                        }t	        |t
        j                        }|xs |xs | }	|xr t        |      dk(  }
t	        |t
        j                  t
        j                  t
        j                  t
        j                  f      }t        j                  |      |xs  }t        |g      }j                   j"                  }|dk(  r*t        j                  |      rt        j$                  d      |dk(  r,t        j                  |      sd}t        j$                  |      t        j                  |      rj'                  |j(                  f       nG|rj'                  |j(                  |f       n'j'                  |j(                  |j(                  f        fd	t*        fd
       t*        fd       dfd	}dfd	}dd}dfd	}|r|S |
r|r|S |	r|r|S |S )Nz ufunc.at feature is experimentalcategoryz)The first argument "a" must be array-liker      zsecond operand needed for ufuncrY   z+second operand provided when ufunc is unaryc           	         ddl m} t        |      dk(  r|j                  \  }}}}|\  }}	}
}n|j                  dz   \  }}}}|dz   \  }}	}
}  ||      | ||	      }	t	        |	||
|||      }|j                  | |       y )Nr   )
make_array   r   )r?   r  rE   ru   r   r5   )r1   r2   rb   ru   r  r4   atyidxtybtyr!   r#   r%   at_iterr    s                r(   apply_ufunc_codegenzDDUFunc._install_ufunc_at.<locals>.ol_at.<locals>.apply_ufunc_codegen  s    8t9>),&AsE3'+$Aq'1),G);&AsE3'+g~$Aq'1#JsOGWa8)%C%CPGW-r*   c                 <    t        j                  ||||      }|fS r   r   none)	typingctxr    r!   r#   r%   rb   r"  s         r(   apply_a_b_ufuncz@DUFunc._install_ufunc_at.<locals>.ol_at.<locals>.apply_a_b_ufunc  s#    jj7A6///r*   c                 :    t        j                  |||      }|fS r   r$  )r&  r    r!   r#   rb   r"  s        r(   apply_a_ufuncz>DUFunc._install_ufunc_at.<locals>.ol_at.<locals>.apply_a_ufunc  s!    jj73///r*   c                     r%| j                  |t        j                  |            S | j                  |t        j                  |      t        j                  |            S r   )r  r   asarrayr    r!   r#   r%   b_nones       r(   	impl_castz:DUFunc._install_ufunc_at.<locals>.ol_at.<locals>.impl_cast  sJ     88Arzz'':;; 88A$&JJw$7$&JJqM3 3r*   c                     r | ||       y t        j                  |      }||   }t        j                  ||j                        } | |||j                         y r   )r   r+  broadcast_torM   flat)	r    r!   r#   r%   b_a_r'  r)  r-  s	         r(   impl_genericz=DUFunc._install_ufunc_at.<locals>.ol_at.<locals>.impl_generic  sN    !%G5AB7BRXX6B#E1grww?r*   c                 "     | |d   |      |d<   y )Nr}   r}   )r    r!   r#   r%   s       r(   impl_indices_empty_b_scalarzLDUFunc._install_ufunc_at.<locals>.ol_at.<locals>.impl_indices_empty_b_scalar  s    aeQ"r*   c                 F    r | ||         ||<   y  | ||   |      ||<   y r   r}   r,  s       r(   impl_scalar_scalarzCDUFunc._install_ufunc_at.<locals>.ol_at.<locals>.impl_scalar_scalar  s,    !&qz!2AgJ!&qz1!5AgJr*   r   )r   r   r	   NumbaExperimentalFeatureWarningr7   r   r   NumbaTypeErrorListTuple	SliceTyperE   Sequencer   is_nonelikeanyr    r   TypingErrorr_   r[   r   )r    r!   r#   r%   r   indices_arrindices_listindices_tupleindices_sliceindices_scalarindices_empty_tupleb_arrayb_scalar	need_castr   r.  r4  r6  r8  r'  r)  r"  r-  r'   s   `                  @@@@r(   ol_atz'DUFunc._install_ufunc_at.<locals>.ol_at  s   MM<#)#I#IK a-A++C00$Wekk:K%guzz:L&w<M&w@M"-"O"O-PN"/"ECLA4E U[[%..%**%*[[%2 3G((+F#-v.H\N+I**..C axG//2(()JKK ax 3 3A 6C((--""1%!''$!''1&!''177+,. 0 0 0 03@(6   $22H))##r*   r   r   r  r   )r'   r  r  rK  s   `   r(   r  zDUFunc._install_ufunc_at  s,    ^^H%	T	"_	$ 
#_	$r*   c                 Z     t        j                  |      }t        |d      d fd	       }y )Nreducec                    t        j                  dt        j                         t	        |t
        j                        sd}t        j                  |      t	        |t
        j                        }t	        |t
        j                        xr$ t	        |j                  t
        j                        }t	        |t
        j                        xr t        |      dk(  }t        j                  |      }	|rt        |      nd}
j                  j                   <|r|
dk(  s5|s3|s1|	s/dj                  j"                   d}t        j                  |      d|j$                  z  d|j$                  dz
  z  t        j                  |      r|j                  n|j                   t        j                        t        j                  |      t&        fd	       t&        fd
       t(        d        t&        d        t&        d        dfd	}	 	 	 dfd	}	 	 	 dfd	}	 	 	 dd}	 	 	 dfd	}|j$                  dk(  r|s|S |r|S |	r t+        t-        |j$                              |S |rdt        |      dz
  z  |S |dk(  s9t	        |t
        j                  t
        j.                  t
        j0                  f      r|S y )Nz$ufunc.reduce feature is experimentalr  z-The first argument "array" must be array-liker   rY   zreduction operation 'z:' is not reorderable, so at most one axis may be specified)r   c                 f    }d}t        |       D ]  \  }}||k(  rt        |||      }|dz  } |S Nr   rY   )	enumerater   )tuppossijetup_init_m1s         r(   tuple_slicezDDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.tuple_slice	  sI      %cNDAqCx %aA.AFA	 +
 r*   c                     }ddt        |      }}}||k  r5||k(  rt        |||      }n| |   }t        |||      }|dz  }|dz  }||k  r5|S rQ  )rE   r   )	rS  rT  rV   rU  rV  rW  szrX  tup_inits	           r(   tuple_slice_appendzKDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.tuple_slice_append  sp     aQb1"fCx)!Q4F)!Q2QFA "f r*   c                 j    t        j                  ||||      }t        |      fdfd}||fS )Nc                    |\  }}}}| j                  |      }| j                  |      5   t        j                  d      d      }	|	}
|dk(  r^t	        d      D ]M  }| j                  ||dz
        }| j                  ||      }| j                  ||      }| j                  |
|      }
O n&d|cxk  rdz
  k  rn nt	        d|      D ]J  }| j                  ||      }| j                  ||      }| j                  ||      }| j                  |
|      }
L t	        |dz         D ]M  }| j                  ||dz
        }| j                  ||      }| j                  ||      }| j                  |
|      }
O n\t	        ddz
        D ]J  }| j                  ||      }| j                  ||      }| j                  ||      }| j                  |
|      }
L | j                  |       d d d        ||
fS # 1 sw Y   |
fS xY w)Nname@   r   rY   )	append_basic_block
goto_blockr   IntTyperangeextract_valuemulr_   branch)r2   	block_pos
block_namebb_endru   rN   r4   ra   bbrI   flat_idxrV  strideidx_imlen_idxs                  r(   	gen_blockz\DUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idx.<locals>.gen_block+  s   )-&GQQ 333DB ++B/-rzz"~a0#'$>%*1g%6)0)>)>wA)N(/(=(=c1(E$+KK$>+2;;x+C	 &7
 8Wq[8%*1i%8)0)>)>w)J(/(=(=c1(E$+KK$>+2;;x+C	 &9 &+9q='%B)0)>)>wA)N(/(=(=c1(E$+KK$>+2;;x+C	 &C &+1gk%:)0)>)>w)J(/(=(=c1(E$+KK$>+2;;x+C	 &;  v.; 0> x<'? 0> x<'s   F8G00G<c                 J   |\  }}}}|j                   }|j                  d      }	g }
t              D ]'  } ||d| |	|      \  }}|
j                  ||f       ) |j	                  |      5  |j                  ||
d   d         }t              D ]  }|j                  ||
|   d           	 d d d        |j                  |	       |j                  |
d   d   j                        }|
D ]  \  }}|j                  ||        |j                  ||      S # 1 sw Y   ixY w)Naxis_endra  axis_r   rY   )basic_blockrd  rg  r   re  switchadd_caseposition_at_endphir   add_incomingsdiv)r1   r2   rb   ru   rN   itemsizera   axisrn  
switch_endlrV  blockro  rz  r}  valuert  rs  s                    r(   codegenzZDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idx.<locals>.codegenP  s&   370GXsD ,,B!(!;!;!;!LJA"7^*3GQ%s4>+Fx%!23 ,
 !++B/!(aeAh!?!&wA"OOAqtAw7 "0 0
 ++J7!++ad1gll3C()u((6 )*"<<X66 0/s   /ADD")r   rA   rE   )	r&  rN   r  ra   r  rb   r  rt  rs  s	          @@r(   compute_flat_idxzIDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idx&  s7    jj(C>c(#(J7, G|#r*   c                     | }t        t        |             D ]$  }| |   dk  r| |   |z   n| |   }t        |||      }& |S rn   )rg  rE   r   )r  ndimaxrV  rV   s        r(   
fixup_axiszCDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.fixup_axish  sL    s4y)A,0GaK$q'D.T!WC&r1c2B * 	r*   c                 j    d| d   }}t        t        |             D ]  }| |   |k  s|| |   }} ||fS rn   )rg  rE   )rS  ra   rX  rV  s       r(   find_minzADUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.find_minp  sD    CFQs3xA1vz!"CFQ ) Avr*   c                     d}r
	rd}|d   }nr
}n|}|j                   d   }t        ||      D ]  } | |||         } |S rQ  )rM   rg  )r    rR   r  r[   initialstartrr\  rV  id_noner   	init_nones            r(   impl_1dz@DUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_1dx  s[    EaA AA[[^ub)Aaq*A *r*   c                 B   |t        d      |dk  r||j                  z  }|dk  s||j                  k\  rt        d       |j                  |      }|IGt        j                  |      }t        j
                  |      D ]  \  }} ||d      }	||	   ||<    n5|t        j                  |      }nt        j                  ||      }|j                         }
|\Zt        j
                  |      D ]@  \  }}||   dk(  r |j                  |j                  ||      }|
|   |}} | ||      |
|<   B |S t        j
                  |      D ]D  \  }}|	||   dk(  r |j                  |j                  ||      }|
|   |}} | ||      |
|<   F |S )Nz'axis' must be specifiedr   Invalid axis)r[   )
fill_valuer[   )

ValueErrorr  rM   r   emptyndenumeratefullravelrN   r  )r    rR   r  r[   r  rM   r  ra   r4   
result_idxviewrV   flat_poslhsrhsr  r   nb_dtyperZ  r^  s                  r(   impl_nd_axis_intzIDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_nd_axis_int  s   
 <$%?@@!8EJJ&D!8tuzz1$^44 $EKK6?x'7h7A"$.."3Q%7T1%E
!&z!2# #4 _)= ((KA'JA wwy?x'7$&NN5$9St9>$'7		1::8;T(CH'+H~sC-23_DN %:"  %'NN5$9S"?x/? #D	Q$#3AIIqzz47$?#'>3S).sCX %: r*   c                 P    ||j                         }t        dt        |            D ]Z  }||   dk  s||   |j                   k\  rt        d      t        |dz   t        |            D ]  }||   ||   k(  st        d       \  |      \  }}	| j	                  ||	||      }
t        |      dk(  r|
S t        |      dk(  r| j	                  |
||dz   dz     dz
        S }t        t        |            D ]  }||k7  s	t        ||||         } | j	                  |
|      S )Nr   r  rY   zduplicate value in 'axis')r  r[   r  r  )r  )r  rg  rE   r  rN  r   )r    rR   r  r[   r  rw  rV  rW  min_idxmin_elemr  r  axis_tupr  r  s               r(   impl_nd_axis_tuplezKDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_nd_axis_tuple  s:   
 #44q#e*-AQx!|uQx5::'=(88"1q5#e*5 8uQx/",-H"II 6	 . %-UO!LL&.',)0 ! 2 t9>HY!^ <<w{a6G0H10L<MM!B"3r7^<!.r1eAh!?B , !<<<33r*   c                     |S r   r}   )r    rR   r  r[   r  s        r(   impl_axis_empty_tuplezNDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_axis_empty_tuple  s	    
 r*   c                 ,    | j                  |||      S r   )rN  )r    rR   r  r[   r  r  s        r(   impl_axis_nonezGDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_axis_none  s    
 ||E8UGDDr*   r   NN)r   r   r	   r9  r7   r   r   r:  IntegerUniTupler[   r<  rE   r   r?  r    r   rz   r  r   r   r   rg  OmittedIntegerLiteral)r    rR   r  r[   r  r   axis_intaxis_int_tupleaxis_empty_tuple	axis_noneaxis_tuple_sizer  r  r  r  r  r  r  r  r  r  r   r  r  r]  rY  rZ  r^  r'   s                   @@@@@@@@@@@@r(   	ol_reducez/DUFunc._install_ufunc_reduce.<locals>.ol_reduce  s    MM@#)#I#IK eU[[1E++C00!$6H'enn= 64::u}}5 )$<OTa++D1I+9c$iqOzz""*#1(<$I.tzz/B/B.C DK K++C00uzz*H%**q.1K&-&9&9%&@u{{eH}}H))(3G++G4I
 
   ?$ ?$B    " '('+)-	7 7v )*)-+/	4@ ,-,0.2	 %&%)'+	E zzQ'7!,, uzz!23%%  3t9q=1))j05050D0D0F G
 ('Gr*   r  rL  )r'   r  r  r  s   `   r(   r  zDUFunc._install_ufunc_reduce  s,    ^^H%	X	&U	( 
'U	(r*   c                 Z   t        j                  |      r|fn||f}d |D        }t        d |D              }| j                  |      dk(  r,| j                  rd| d}t        |       | j                  |  t        j                  |      rt        | !  ||      S t        |    |||f S )Nc              3   2   K   | ]  }t        |        y wr   )r   r   r   s     r(   r   zDUFunc.at.<locals>.<genexpr>  s     .#&+r   c              3   l   K   | ],  }t        |t        j                        r|j                  n| . y wr   )r7   r   r   r[   r  s     r(   r   zDUFunc.at.<locals>.<genexpr>  s.      /'- *4C)ECII3N'-s   24ry   r   z.at(...))	r   r?  r   r   r   r   r   r   r  )	r'   r!   r#   r%   ru   r   r  r   r   s	           r(   r  z	DUFunc.at  s    **1-tAq6.. /'-/ / ##K0L@||?CE"3''"D""D) q!7:a))7:7A//r*   c                 ,   | | j                   j                  j                  }t        d| j                  j
                  z   t        ft        | | j                              }|j                  | |       | j                  |       | j                  |       y)a*  Constructs and installs a typing class for a DUFunc object in the
        input typing context.  If no typing context is given, then
        _install_type() installs into the typing context of the
        dispatcher object (should be same default context used by
        jit() and njit()).
        NDUFuncTyping_)ro   generic)r   targetdescrtyping_contextr   r    rz   r   r   _type_meinsert_user_functionr  r  )r'   r&  _ty_clss      r(   r   zDUFunc._install_type  s~     ((44CCI)<)<<(*dmm<> 	&&tW5&&w/##G,r*   c                 ,   | j                   rGt        j                  | |      }|yt        |j                  |j
                  z         dt        |       }| j                  j                  j                         D ]  \  }}|j                  |k(  s||fc S  y)a  
        Given a tuple of element-wise argument types, find a matching
        signature in the dispatcher.

        Return a 2-tuple containing the matching signature, and
        compilation result.  Will return two None's if no matching
        signature was found.
        Nry   )r   r   ufunc_find_matching_loopr   inputsoutputsrE   r   r   r   ru   )r'   r  looprb   rH   s        r(   r   zDUFunc.find_ewise_function(  s     << 99$LD|!dll :;<MS=MNK))3399;ICxx;&Dy  < r*   c                    |rJ | j                   }t        j                  j                  |||      }|\  }}}}t	        |      }	|	dkD  rt        |dt	        |              }
nt        |      }
| j                  |
      \  }}|F| j                  rt        d| d|      | j                  |
       | j                  |
      \  }}|J |	dkD  rt        |      }nP|j                  dk(  r6|dkD  r#t        j                  |j                  ||      g}n|j                  g}nt        d      |j!                  |       t#        | S )z
        Implement AbstractTemplate.generic() for the typing class
        built by DUFunc._install_type().

        Return the call-site signature after either validating the
        element-wise signature or compiling for it.
        r   Nzcannot call z with types rY   ztyping gufuncs (nout > 1))r    r   Numpy_rules_ufunc_handle_inputsrE   r   r   r   r   r   r   r   r   r   rh   NotImplementedErrorextendr   )r'   r   kwtysr    _handle_inputs_result
base_typesexplicit_outputsndimsrQ   explicit_output_countr  rb   rH   outtyss                 r(   r  zDUFunc._type_me<  sM    y

 ' 9 9 H H65!"6K3
$eV #$4 5 1$
+BS1A-B,B CDK
+K,,[9	T; ||#'!1 2 2$$[100=IC?"? 1$*+FZZ1_qy++cooufEF//*%&ABBf&!!r*   r   )r  N)%rz   r{   r|   r   set_DUFunc__base_kwargsr)   r   r   classmethodr   r   propertyr   r   r   r   r   r   r   r   r   r_   r   r   r   r   r  r  r  r  r  r  r   r   r  r   r   s   @r(   r   r      s>    ABM)-U" 0	

   . .         ! !     # # $ $;27> " "H'2*)c$JY(z0*- (&"r*   r   )3r   r]   r   numpyr   numbar   r   
numba.corer   r   r   r   r	   numba.core.extendingr
   r   r   r   r   numba.core.typingr   numba.core.typing.templatesr   r   numba.cpython.unsafe.tupler   numba.np.ufuncr   numba.np.ufunc.ufunc_baser   r   numba.parforsr   r   r   r   typingr   llvmliter   numba.core.compiler_lockr   r   r   r   ReduceMixinr   r   	MAP_TYPESr   r}   r*   r(   <module>r     s         B B- - & C 4 $ A ( ' "   9j= j=Z(5$ 5~
"Y""I$5$5y ~
"B      'r*   