
    GJjȞ                        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           _/Users/ahmed/devFolder/claude-voice/.venv/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_indicess       r(   runzUfuncAtIterator.run$   sD    gw'||//1'<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           	      .   ddl m}m}m}m} | j
                  | j                  }}| j                  | j                  }
}	 |j                  t        j                        d      }| j                  t        j                  ||      | _        | j!                         r<t        j"                  ||t%        |
            }|
j                  } |||||      \  }}n|f}|
f} |||||      \  }}g }t'        |      D ]J  \  }}||   }t)        |t        j*                        s&  ||      |||      }|j-                  ||||f       L |r ||||      }nd} ||||	||||      | _        | j.                  j1                          | j3                  ||      | _        y )Nr   )normalize_indicesFancyIndexer
make_arrayget_subspace_shape)count )numba.np.arrayobjr;   r<   r=   r>   r!   r#   r"   r$   get_value_typer   intpr%   r   alloca_once_valueb_indicer9   unpack_tuplelen	enumerater6   Arrayappendr-   prepare_compile_ufunccres)r'   r1   r2   r;   r<   r=   r>   r!   r#   r"   r$   zeroindex_typesarray_indicesiidxtyidxidx_makesubspace_shape_tuples                      r(   r,   zUfuncAtIterator._prepare-   s   	G 	G VVT\\799dooj1w%%ejj1!466#55gtDDM&&(**7G14ZBG$**K#4Wg5@'$K K jG%-K#4Wg5@'$K K !+.HAu!*C%-,:e,WgsC$$aeX%>?	 / "7G]C ! $& #GWdA$/:NP''9	r*   c           	         ddl m} t        j                  ||j                        }t        j                  ||j
                        }|j                  }	t        j                  |||	|||j                  |      }
 |||||
      }|
|fS )Nr   )	load_item)	rA   rW   r   rF   shapestridesdataget_item_pointer2layout)r'   r1   r2   r3   arrayarray_tyrW   shapesrY   rZ   ptrvals               r(   	_load_valzUfuncAtIterator._load_valV   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   rC   get_functionoperatorgetitemrB   addstore)r'   r1   r2   r#   r]   r^   rS   sigimplra   ones              r(   
_load_flatzUfuncAtIterator._load_flata   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)rA   rq   rM   r   return_typerf   cast)
r'   r1   r2   r]   r^   r`   ra   rq   fromtytotys
             r(   
_store_valzUfuncAtIterator._store_valn   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"   rf   r&   rj   add_linking_libslibrary)r'   r1   r2   r    rl   rM   s         r(   rL   zUfuncAtIterator._compile_ufuncu   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   )rM   r!   r"   rb   r%   r&   rE   ro   call_internalfndescr   rv   )r'   r1   r2   r3   rM   r!   r"   r`   ra   argsr%   r&   b_idx_val_bress                   r(   r/   zUfuncAtIterator._call_ufunc   s    yy&&$))4>>'7L!TJS66>6D!VVTYYUtAw4HHAu<D##GT[[$..$(*!T3<r*   NN)__name__
__module____qualname__r)   r4   r9   r,   rb   ro   rv   rL   r/   r@   r*   r(   r   r      s0    !<':R	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_functionr   	inner_sigrM   )r'   r1   r2   	outer_sig	__class__s       r(   r)   z1make_dufunc_kernel.<locals>.DUFuncKernel.__init__   s8    GWgy9(,(G(G) %DNDIr*   )r   r   r   __doc__r   r)   __classcell__)r   _dufuncs   @r(   DUFuncKernelr      s    	
 	  	 r*   r   )numba.npr   _Kernelr   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*   )r   r   r   r   r)   r   r   s   @r(   r   r      s    5 5r*   r   c                   R    e Zd ZdZ ed      Zd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!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noutc                    |i }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__   s     MWooGMMO. .Z#(.,..57J P 	X.  w/ POs   A66A?c                 V   t        j                  |      }t        t        |   ||       |t
        j                  k7  | _        |j                  j                  | _	        |j                  j                  | _
        t        |       | _        | j                          | j                          y )N)r   )r   parse_identityr   r   r)   r   PyUFunc_Nonereorderabler   r   r   r   	_lower_me_install_cg_install_type)r'   r   r   r   s      r(   r   zDUFunc._initialize   s    ..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   rj   disable_compile)clsr   r   r   r   r'   rl   s          r(   _rebuildzDUFunc._rebuild   sS    
   ((-X.CHHSM   "r*   c                     | S )zK
        For compatibility with the various *UFuncBuilder classes.
        r@   r8   s    r(   build_ufunczDUFunc.build_ufunc   s	     r*   c                 .    | j                   j                  S r   )r   r   r8   s    r(   r   zDUFunc.targetoptions   s    ---r*   c                 .    | j                   j                  S r   )r    r   r8   s    r(   r   z
DUFunc.nin   s    zz~~r*   c                 .    | j                   j                  S r   )r    r   r8   s    r(   r   zDUFunc.nout   s    zzr*   c                 .    | j                   j                  S r   )r    nargsr8   s    r(   r   zDUFunc.nargs       zzr*   c                 .    | j                   j                  S r   )r    ntypesr8   s    r(   r   zDUFunc.ntypes  s    zz   r*   c                 .    | j                   j                  S r   )r    r   r8   s    r(   r   zDUFunc.types  r   r*   c                 .    | j                   j                  S r   )r    r   r8   s    r(   r   zDUFunc.identity  s    zz"""r*   c                 .    | j                   j                  S r   )r    r   r8   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)rG   r   r   r   r8   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'   rl   r   rr   s       r(   rj   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'   r   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>9  s     +I[DG[   )r    r   pop	TypeErrorjoinsortedrG   r   r   r6   r   rI   rf   r   map_arrayscalar_typerJ   r   r   )	r'   r   r   r   r   args_lenargtysr   argtys	            r(   _compile_for_argszDUFunc._compile_for_args1  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   RuntimeErrorr6   r   r   r   itemsr   warningswarnr	   NumbaWarningr   _compile_element_wise_functionr   _finalize_ufunc_signature!_build_element_wise_ufunc_wrapper	_add_loopintr   rJ   r{   r   libs)r'   r   rr   rl   r   rM   msg
actual_sig	dtypenumsr`   envs              r(   r   zDUFunc._compile_for_argtysP  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   )r   )r'   ewise_typesrl   s      r(   match_signaturezDUFunc.match_signatureu  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    ra   s    r(   <lambda>zUDUFunc._install_ufunc_attributes.<locals>.get_attr_fn.<locals>.impl.<locals>.<lambda>~  s    Sr*   )r   ry   )r    ra   r  s    @r(   rm   zCDUFunc._install_ufunc_attributes.<locals>.get_attr_fn.<locals>.impl|  s    eiilD1((r*   r@   )r  rm   s   ` r(   get_attr_fnz5DUFunc._install_ufunc_attributes.<locals>.get_attr_fnz  s    ) Kr*   )r   r   r   r   r   )strr   r   Functionr   )r'   templater  at
attributesr  attr_fns          r(   _install_ufunc_attributesz DUFunc._install_ufunc_attributesx  sR    	c 	h 	 ^^H%/
D!$'G(r4(1 r*   c                 j    | j                  |       | j                  |       | j                  |       y r   )_install_ufunc_reduce_install_ufunc_reduceat_install_ufunc_at)r'   r  s     r(   _install_ufunc_methodszDUFunc._install_ufunc_methods  s,    ""8,$$X.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 ufuncrd   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   )r=      r   )rA   r=   rG   r   r   r4   )r1   r2   rl   r   r=   r   atyrR   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%   rl   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#   rl   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   r4  broadcast_torX   flat)	r    r!   r#   r%   b_a_r0  r2  r6  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@   r5  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	   NumbaExperimentalFeatureWarningr6   r   rI   NumbaTypeErrorListTuple	SliceTyperG   Sequencer   is_nonelikeanyr    r   TypingErrorrj   rf   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   r7  r=  r?  rA  r0  r2  r+  r6  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  rT  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                        xr$ t	        |j                  t
        j                        }t	        |t
        j                        xr t        |      dk(  }t        j                  |      }j                  j                   d u j                  j"                  j$                  s+|r)t        |      dkD  rd 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
        j0                  t
        j2                  f      r|
S y )Nz$ufunc.reduce feature is experimentalr#  -The first argument "array" must be array-liker   rd   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   rd   )rH   r   )tuppossrQ   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 r\  rG   r   )	r]  r^  ra   r_  rQ   r`  szra  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   rd   )	append_basic_block
goto_blockr   IntTyperangeextract_valuemulrj   branch)r2   	block_pos
block_namebb_endr   rY   r   rS   bbrN   flat_idxrQ   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_endrk  axis_r   rd   )basic_blockrn  rq  rJ   ro  switchadd_caseposition_at_endphir   add_incomingsdiv)r1   r2   rl   r   rY   itemsizerS   axisrx  
switch_endlrQ   blockry  r  r  valuer~  r}  s                    r(   codegenzZDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idx.<locals>.codegenb  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   rC   rG   )	r/  rY   r  rS   r  rl   r  r~  r}  s	          @@r(   compute_flat_idxzIDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idx8  s7    jj(C>c(#(J7, G|#r*   c                     | }t        t        |             D ]$  }| |   dk  r| |   |z   n| |   }t        |||      }& |S rx   )rq  rG   r   )r  ndimaxrQ   ra   s        r(   
fixup_axiszCDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.fixup_axisz  sL    s4y)A,0GaK$q'D.T!WC&r1c2B * 	r*   c                 j    d| d   }}t        t        |             D ]  }| |   |k  s|| |   }} ||fS rx   )rq  rG   )r]  rS   ra  rQ   s       r(   find_minzADUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.find_min  sD    CFQs3xA1vz!"CFQ ) Avr*   c                     r!|t        |      dk(  rd d}t        |      d}r

rd}|d   }nr}n|}|j                  d   }t        ||      D ]  }	 | |||	         } |S )Nr   'zero-size array to reduction operation  which has no identityrd   )rG   
ValueErrorrX   rq  )r    r]   r  rf   initialr  startrrf  rQ   id_noner   identity_none	init_none
ufunc_names             r(   impl_1dz@DUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_1d  s     W_UqD(\)?AC$S/)EaA AA[[^ub)Aaq*A *r*   c                    |t        d      |dk  r||j                  z  }|dk  s||j                  k\  rt        d      r%|#|j                  |   dk(  rd d}t        |       |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 axisr  r  rf   )
fill_valuerf   )
r  r  rX   r   emptyndenumeratefullravelrY   r  )r    r]   r  rf   r  r  rX   r  rS   r   
result_idxviewra   flat_poslhsrhsr  r   r  nb_dtyperc  rh  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 W_T9Ja9OD(\)?AC$S/) $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  rd   zduplicate value in 'axis')r  rf   r  r%  r  )r  rq  rG   r  rW  r   )r    r]   r  rf   r  r  rQ   r`  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    r]   r  rf   r  s        r(   impl_axis_empty_tuplezNDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_axis_empty_tuple  s	    
 r*   c                 ,    | j                  |||      S r   )rW  )r    r]   r  rf   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	   rB  r6   r   rI   rC  UniTuplerf   IntegerrE  rG   r   rH  r    r   r   r   r  r   r   r   rq  OmittedIntegerLiteral)r    r]   r  rf   r  r  axis_int_tupleaxis_empty_tuple	axis_noner  r  r  r  r  r  r  r  r  r  r   r  r  r  rg  rb  rc  rh  r  r'   s                 @@@@@@@@@@@@@@r(   	ol_reducez/DUFunc._install_ufunc_reduce.<locals>.ol_reduce  s    MM@#)#I#IK eU[[1E++C00'enn= 64::u}}5 )$<OTa++D1I JJ//47M,,J ##3t9q=.zl ;K K++C00uzz*H%**q.1K&-&9&9%&@u{{eH}}H))(3G++G4I
 
   ?$ ?$B     , '('+)-	< <@ )*)-+/	4@ ,-,0.2	 %&%)'+	E zzQ'7!,, uzz!23%%  3t9q=1))j05050D0D0F G
 ('Gr*   r  rU  )r'   r  r  r  s   `   r(   r  zDUFunc._install_ufunc_reduce  s,    ^^H%	X	&`	( 
'`	(r*   c                 Z     t        j                  |      }t        |d      d fd	       }y )Nreduceatc                 l   t        j                  dt        j                         j                  j
                  dk7  rd}t        j                  |      t        j                  |      sd}t        j                  |      t        j                  |      sd}t        j                  |      t        |t        j                  t        j                  t        j                  t        f      sd}t        j                  |      t        j                   |      s/t        |t        j"                        st        j                  d      t        |t        j"                        }|r|j$                  nd	d
dz
  z  t        |t        j"                        }t        j                   |      r|j&                  n||xr | }	|r3|j$                  dk7  r$d|j$                   }t        j(                  |      |	rdd}
|
S t*        fd       d	dlm}  ||j$                  d      dfd	}|S )Nz&ufunc.reduceat feature is experimentalr#  r%  z,reduceat only supported for binary functionsrY  z0The second argument "indices" must be array-likez"axis" must be an integerzoutput must be an arrayr   rZ  rd   z8Expect "indices" array to have at most 1 dimension. Got c                 z    | j                  t        j                  |      t        j                  |      |||      S )N)rf   r   )r  r   r4  )r    r]   r#   r  rf   r   s         r(   r7  zFDUFunc._install_ufunc_reduceat.<locals>.ol_reduceat.<locals>.impl_castI  s8     >>"**U*;*,**W*=*.05.1	 * 3 3r*   c                     }d\  }}|t        |       k  r.||k7  rt        ||| |         }|dz  }|dz  }|t        |       k  r.|S )N)r   r   rd   re  )r]  r^  r_  rQ   r`  tup_m1s        r(   rc  zHDUFunc._install_ufunc_reduceat.<locals>.ol_reduceat.<locals>.tuple_sliceQ  s[    1#c(lCx)!QA7QFA	 #c(l
 r*   )"generate_getitem_setitem_with_axissetitemc                    |j                   d   }|}|dk  r|z  }|dk  s|k\  rt        d| d       t        |j                   ||      }s|j                   |k7  rd}	t        |	      rt        j                  |      }t        |      dk(  r|S d}
t        t        |      dz
        D ]  }||   ||dz      k  r`t        j                  ||   ||dz            }dkD  rt        j                  |||      }n||   }| j                  ||      } ||
||       nz||   ||dz      k\  rQ||   }t        j                  |||      }dkD  r$ |j                   |      }|j                  |      } ||
||       n||   |k\  s||   dk  rt        d      |
dz  }
 t        j                  |d	   |j                   |         }dkD  rt        j                  |||      }n||   }| j                  ||      } ||
||       |S )
Nr   zaxis z) is out of bounds for array of dimension z=operands could not be broadcast together with remmaped shapesr  rd   r  zInvalid value for indicesr  )rX   r  r   r   zerosrG   rq  arangetakerW  reshape)r    r]   r#   r  rf   r   rf  r  rX   r  r`  rQ   rS   	arr_slice
arr_reduce_slice
array_ndimdtout_noner  rc  s                   r(   rm   zADUFunc._install_ufunc_reduceat.<locals>.ol_reduceat.<locals>.impla  s5   ]]1%!8J&D!8tz1$uRD 155?L&B C C &ekk4<CII$6-C$S/)((53C w<1$Js7|a/0AqzGAEN2 ii
GAENC%>(*sD(AI(-c
I%*\\)$\%G
Qj9 wq1u~5%aj$&GGE3$=	%>%0d%CF(1(9(9&(AIQi8 r)WQZ!^()DEEFA% 1* iiU[[->?> "sD 9I %c
I"\\)T:
Qj1
r*   r  )r   r   r	   rB  r    r   rC  r   type_can_asarrayr6   r   r  r  r  r  r   rH  rI   r  rf   NumbaValueErrorr   rA   r  )r    r]   r#   r  rf   r   r  	array_arrrK  rS  r7  r  rm   r  r  r  r  r  rc  r'   s                @@@@@@r(   ol_reduceatz3DUFunc._install_ufunc_reduceat.<locals>.ol_reduceat   s    MMB#)#I#IK zz~~"D++C00 11%8E++C00 11':H++C00dU]]EMM%*%9%93%@ A1++C00**3/HJsEKK$@++,EFF"5%++6I'0aJZ!^,F$Wekk:K ' 3 3E :B&6;7Iw||q0%ll^-,,S113 !   M8YOG8 8t Kr*   r  rU  )r'   r  r  r  s   `   r(   r  zDUFunc._install_ufunc_reduceat  s,    ^^H%	Z	(z	 
)z	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   )r6   r   rI   rf   r  s     r(   r   zDUFunc.at.<locals>.<genexpr>  s.      /'- *4C)ECII3N'-s   24r   r   z.at(...))	r   rH  r   r   r   r   r   r   r  )	r'   r!   r#   r%   r   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_)ry   generic)r   targetdescrtyping_contextr   r    r   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.
        Nr   )r   r   ufunc_find_matching_loopr   inputsoutputsrG   r   r   r   r   )r'   r  looprl   rM   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                  |
      \  }}|P| j                  rt        j                  d| d|      | j                  |
       | j                  |
      \  }}|J |	dkD  rt        |      }nZ|j                  dk(  r6|dkD  r#t        j                  |j                  ||      g}n#|j                  g}nt        j                   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 rd   ztyping gufuncs (nout > 1))r    r   Numpy_rules_ufunc_handle_inputsrG   r   r   r   r	   rC  r   r   r   r   rI   rr   NumbaNotImplementedErrorextendr   )r'   r   kwtysr    _handle_inputs_result
base_typesexplicit_outputsndimsr\   explicit_output_countr  rl   rM   outtyss                 r(   r  zDUFunc._type_me  sY    y

 ' 9 9 H H65!"6K3
$eV #$4 5 1$
+BS1A-B,B CDK
+K,,[9	T; ||++/3V-= > >$$[100=IC?"? 1$*+FZZ1_qy++cooufEF//*112MNNf&!!r*   )NFNr   )r  N)&r   r   r   r   set_DUFunc__base_kwargsr)   r   r   classmethodr   r   propertyr   r   r   r   r   r   r   r   r   rj   r   r   r   r   r  r  r   r  r  r  r  r   r   r  r   r   s   @r(   r   r      s>    ABM
0


   . .         ! !     # # $ $;27> " "H'2*)
c$Jd(L	~@0*- (&"r*   r   )3r   rh   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_TYPESrJ   r@   r*   r(   <module>r     s         B B- - & C 4 $ A ( ' "   9w= w=t(5$ 5K"Y""I$5$5y K"\      'r*   