
    ϑi                        S SK Jr  S SKJr  S SKJrJrJr  SSKJ	r	  SSK
Jr  SSKJrJrJrJrJrJrJrJrJrJr  \(       a  S S	KJr   " S
 S5      rg)    )annotations)contextmanager)TYPE_CHECKINGAnyCallable   )log   CompileSIRCache)
ApiStatementASTStatementCallStatementLayerStatementMethodStatementParametersHolderStatementContextStatementIRStatementIRFactorySymbol)	InputSpecc                      \ rS rSrSrS rS r\SS j5       rSS jr	S r
S rS	 rS
 rS rSS jr\SS j5       rS rSS jr      SS jrSrg)StatementIRBuilder'   z!
A class to build a StatementIR.
c                $    U R                  5         g N)resetselfs    _/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/jit/sot/symbolic/builder.py__init__StatementIRBuilder.__init__,   s    

    c                n    [        5       U l        / U l        U R                  R                  5       U l        g)z
Reset the context.
N)r   statement_factory_current_statement_ctxscreate_current_sirr   s    r    r   StatementIRBuilder.reset/   s.    
 "4!5')$)-)?)?)F)F)Hr#   c                    U R                   $ )z
Get the current SIR.
)r(   r   s    r    current_sirStatementIRBuilder.current_sir8   s    
    r#   c                F    Xl         U R                  R                  U5        g)z)
Replace the current SIR with a new SIR.
N)r(   r%   update)r   sirs     r    replace_current_sir&StatementIRBuilder.replace_current_sir?   s      %%c*r#   c                |    [        XU[        U R                  5      U5      nU R                  R	                  U5        g)z"
Call a SIR, which is a subgraph.
N)r   listr&   r+   add_statement)r   sirnameinputsoutputsstacksstmts         r    call_SIRStatementIRBuilder.call_SIRF   s8    
 Wd4+G+G&H&
 	&&t,r#   c                    [        U5      (       d   S5       e[        XU[        U R                  5      U5      nU R                  R                  U5        g)z
Call a paddle api.
z#call_API must receive a paddle api.N)callabler   r3   r&   r+   r4   )r   apir6   r7   r8   r9   s         r    call_APIStatementIRBuilder.call_APIP   sL     }}CCC}$t'C'C"Df
 	&&t,r#   c                    [        U[        5      (       d   S5       e[        US   S   [        5      (       d   S5       e[        UUU[	        U R
                  5      U5      nU R                  R                  U5        g)z>
Call a method of a api. The API here can be python or Paddle
z)call_METHOD must method api name. string.r   z3call_METHOD first argument must be Symbol Variable.N)
isinstancestrr   r   r3   r&   r+   r4   )r   method_namer6   r7   r8   r9   s         r    call_METHODStatementIRBuilder.call_METHODZ   s     +s++ 	
7	
+ &)A,// 	
A	
/ --.
 	&&t,r#   c                |    [        XU[        U R                  5      U5      nU R                  R	                  U5        g)z
Call a layer of a api.
N)r   r3   r&   r+   r4   )r   layerr6   r7   r8   r9   s         r    
call_LAYERStatementIRBuilder.call_LAYERm   s8     7D)E)E$F
 	&&t,r#   c                ~    [        UUU[        U R                  5      U5      nU R                  R	                  U5        g r   )r   r3   r&   r+   r4   )r   static_functionr6   r7   r8   r9   s         r    call_ASTStatementIRBuilder.call_ASTv   s<    --.
 	&&t,r#   c                     U R                   U   $ )zo
Get a SIR from statement_factory.

Args:
    name (str): the name of SIR.

Returns:
    StatementIR: the SIR.
)r%   )r   names     r    get_sirStatementIRBuilder.get_sir   s     %%d++r#   c              #     #    U R                   R                  U5         Sv   U R                   R                  5         g! U R                   R                  5         f = f7f)z0
Attach a statement context to the current SIR.
N)r&   appendpop)r   ctxs     r    attach_statement_context_guard1StatementIRBuilder.attach_statement_context_guard   sG     
 	$$++C0	/((,,.D((,,.s   A> AAAc                    U R                   nUR                  5       u  Ul        Ul        Xl        [        SS5        [        SUS5        U$ )Nr   z&start subgraph compile and execution.

)r+   analyse_inputsr6   paramsr7   r	   )r   ret_valsr+   s      r    finalizeStatementIRBuilder.finalize   sI    #'#3#31<1K1K1M.K.&A89A{D!r#   c                $     " S S5      nU" 5       $ )z
Return a dummy function, which will return an empty list.

Args:
    ret_vals (list[Symbol]): the return values of the function.
c                       \ rS rSrS rS rSrg)8StatementIRBuilder.compile_do_nothing.<locals>.DummyFunc   c                     / $ r    )argskwargss     r    __call__AStatementIRBuilder.compile_do_nothing.<locals>.DummyFunc.__call__   s    	r#   c                    g)Nr   re   r   s    r    
graph_sizeCStatementIRBuilder.compile_do_nothing.<locals>.DummyFunc.graph_size   s    r#   re   N)__name__
__module____qualname____firstlineno__rh   rk   __static_attributes__re   r#   r    	DummyFuncrb      s    r#   rr   re   )r   rr   s     r    compile_do_nothing%StatementIRBuilder.compile_do_nothing   s    	 	 {r#   c                *    [        5       " XX#40 UD6nU$ )z[
start compile and return the python function, which must can be to_static without errors.
r   )r   sir_nameparameters_holder
input_specrg   static_funcs         r    
compile_fnStatementIRBuilder.compile_fn   s'     &'-
=C
 r#   )r(   r&   r%   N)returnr   )r/   r   )rP   rC   )rV   r   )r|   zCallable[..., Any])rv   rC   rw   r   rx   ztuple[InputSpec | None, ...])rm   rn   ro   rp   __doc__r!   r   propertyr+   r0   r:   r?   rE   rI   rM   rQ   r   rW   r^   rs   rz   rq   re   r#   r    r   r   '   s    I ! !+---&--
, / /" , 1	r#   r   N)
__future__r   
contextlibr   typingr   r   r   utilsr	   compile_cacher   statement_irr   r   r   r   r   r   r   r   r   r   paddle.staticr   r   re   r#   r    <module>r      s<    # % / /  *   'W Wr#   