
    J/Ph                     R    d dl mZ d dlZd dlmZmZ d dlmZ  G d de          Z	dS )    )
ModuleTypeN)ConstantInferenceError
NumbaError)irc                   >    e Zd ZdZd Zd
dZd Zd Zd Zd Z	d	 Z
dS )ConstantInferencez
    A constant inference engine for a given interpreter.
    Inference inspects the IR to try and compute a compile-time constant for
    a variable.

    This shouldn't be used directly, instead call Interpreter.infer_constant().
    c                 F    t          j        |          | _        i | _        d S N)weakrefproxy_func_ir_cache)selffunc_irs     Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/core/consts.py__init__zConstantInference.__init__   s       g..    Nc                 *   || j         vrP	 d|                     |          f| j         |<   n/# t          $ r"}d|j        |j        ff| j         |<   Y d}~nd}~ww xY w| j         |         \  }}|r|S |\  }}t          |t                    r ||d|i || )z
        Infer a constant value for the given variable *name*.
        If no value can be inferred, numba.errors.ConstantInferenceError
        is raised.
        TFNloc)r   	_do_inferr   	__class__args
issubclassr   )r   namer   excsuccessvalr   s          r   infer_constantz ConstantInference.infer_constant   s     t{""G%)4>>$+?+?$@D!!) G G G &+S]CH,E$FD!!!!!!G {4( 	!JIC#z** !c4)S)))c4j s   + 
AAAc                 *    t          d|d           )Nz%Constant inference not possible for: r   )r   )r   r   s     r   _failzConstantInference._fail/   s,     %$9<>DJ J J 	Jr   c                    t          |t                    st          d|          	 | j                            |          }n # t
          $ r t          d|          w xY w	 |                                }nV# t          $ rI t          |t          j	                  r| 
                    |          cY S |                     |           Y nw xY w|S )Nz%infer_constant() called with non-str zno single definition for )
isinstancestr	TypeErrorr   get_definitionKeyErrorr   r   r   Expr_infer_exprr!   )r   r   defnconsts       r   r   zConstantInference._do_infer8   s   $$$ 	')#t& ' ' '	9=//55DD 	9 	9 	9((1579 9 9	9	''))EE% 	 	 	$(( .''-----JJt	 s#   A A!%A: :9C5CCc                     j         dk    r<                     j        j        j                  }                     |          S j         dk    r<                     j        j        j                  }                     |          S j         dk    r fdj        D             S j         dk    r!t           fdj        D                       S  
                               d S )Ncallr    getattr
build_listc                 R    g | ]#}                     |j        j                   $S r    r   r   r   .0iexprr   s     r   
<listcomp>z1ConstantInference._infer_expr.<locals>.<listcomp>R   s<          !D''DH'==      r   build_tuplec              3   Z   K   | ]%}                     |j        j                   V  &dS )r    Nr2   r3   s     r   	<genexpr>z0ConstantInference._infer_expr.<locals>.<genexpr>U   sJ       % %q,,QV,BB % % % % % %r   )opr   funcr   r   _infer_callvalue_infer_getattritemstupler!   )r   r6   r<   r>   s   ``  r   r)   zConstantInference._infer_exprI   s)   7f&&ty~48&DDD##D$///W	!!''
TX'FFE&&ud333W$$         J       W%% % % % % %% % % % % %

4r   c                 @    j         sj        r                                |t          fv }t	          |t
                    ot          |t                    }|s|r+ fdj        D             }|r || S |r||fS J d                                            d S )Nc                 R    g | ]#}                     |j        j                   $S r1   r2   )r4   ar6   r   s     r   r7   z1ConstantInference._infer_call.<locals>.<listcomp>`   s<       !D''DH'==   r   r   Unreachable)	kwsvarargr!   slicer#   typer   BaseExceptionr   )r   r<   r6   _slice_excr   s   ` `   r   r=   zConstantInference._infer_callY   s    8 	t{ 	JJt%!$%%I*T=*I*I 	(T 	(    I  D 	(tT{" (
 Tz!'-'''

4r   c                     t          |t          t          f          r&	 t          ||j                  S # t
          $ r Y nw xY w|                     |           d S r
   )r#   r   rI   r.   attrAttributeErrorr!   )r   r>   r6   s      r   r?   z ConstantInference._infer_getattro   sh    ej$/00 	udi000!   

4s   3 
A A r
   )__name__
__module____qualname____doc__r   r   r!   r   r)   r=   r?    r   r   r   r   	   s           ! ! ! !.J J J  "     ,    r   r   )
typesr   r   numba.core.errorsr   r   
numba.corer   objectr   rT   r   r   <module>rY      s           @ @ @ @ @ @ @ @      m m m m m m m m m mr   