
     Tiu                        S SK Jr  S SKrS SKrS SKrS SKJrJrJrJ	r	J
r
  S SKJr  S SKrS SKJr  S SKJrJrJrJr  \
" S5      r\" S5      r S           SS	 jjr  S       SS
 jjrSS jrSS jrSS jrg)    )annotationsN)AnyCallableOptionalSequenceTypeVar)	ParamSpec)ir)	ast_utils	converter	irbuildervalues_R_Pc                R    [         R                  " UUUUS9nUR                  U 5      $ )zACheck that a function falls into the ONNXScript subset of Python.)opsetglobal_namessourcedefault_opset)r   	Convertertranslate_function_def)fr   r   r   r   converts         X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnxscript/_internal/main.pyscript_checkr      s3     !!!#	G ))!,,    c                   ^ ^^ T =(       d    [         R                  " SS5      m [        T [         R                  5      (       d  [        S5      eSUUU 4S jjnU$ )a  Main decorator. Declares a function as an onnx function.

Args:
    opset: Opset the function belongs to (see :ref:`l-api-opsets`).
    default_opset: Opset to use for operators not in the function's opset.
    kwargs: Additional keyword arguments.

Returns:
    an instance of :class:`onnxscript.values.OnnxFunction`

Example:
::

    @script()
    def log2(x):
        one = op.Constant(value=make_tensor('one', TensorProto.FLOAT, [1], [1]))
        return op.Div(op.Log(x), op.CastLike(op.Log(cst), x))

Or:

::

    from onnxscript.onnx_opset import opset16

    @script(opset16)
    def log2(x):
        one = op.Constant(value=make_tensor('one', TensorProto.FLOAT, [1], [1]))
        return op.Div(op.Log(x), op.CastLike(op.Log(cst), x))
this   zLScript parameter must be an opset. Did you use @script instead of @script()?c                  > [         R                  " U 5      (       d  [        S5      e[        R                  " U 5      u  p[         R
                  " U 5      n[         R                  " U 5      nUR                  R                  5       nUR                  UR                  5        [        UT	XQTS9n[        R                  " T	XUT5      $ )Nz=The ONNXScript decorator should be applied to functions only.)r   )inspect
isfunction	TypeErrorr   get_src_and_ast	getmodulegetclosurevars__dict__copyupdate	nonlocalsr   
onnxscriptOnnxFunction)
r   srcf_astmoduleclosureenvresultr   kwargsr   s
          r   	transformscript.<locals>.transformQ   s    !!!$$[\\..q1

 ""1%((+oo""$

7$$%eUCMR&&uafEEr   )r   zCallable[_P, _R]returnzonnxscript.OnnxFunction[_P, _R])r   Opset
isinstancer#   )r   r   r3   r4   s   ``` r   scriptr9   )   sP    D ,V\\&!,EeV\\**Z
 	
F F" r   c                    ^^ [         R                  " S5      m[         R                  " S5      n U R                  S   nUR                  R                  mSUU4S jjnU$ )a  A parametric decorator used to annotate nested-functions that are used
as graph-attributes.

Returns:
    A decorator that returns its input function, but attaches a graph_proto
    attribute representing the input function. The translation is not
    done at this time, but previously when the outer-level function
    was translated to an OnnxFunction. The decorator just looks up
    and retrieves the GraphProto representation previously generated.

Example:
::

    @script()
    def cumulative_sum(X: INT64['N']):

        # Translation of cumulative_sum by @script will also translate Sum
        # into a GraphProto, which will be stored in the OnnxFunction generated
        # for cumulative_sum. At run-time (in eager-mode), the @graph decorator
        # retrieves the pre-computed GraphProto and attaches it to the Sum function.
        @graph()
        def Sum(sum_in, next):
            sum_out = sum_in + next
            scan_out = op.Identity(sum_out)
            return sum_out, scan_out
        zero = op.Constant(value_int=0)
        # The call to higher-order operator Scan below uses the above function
        # Sum as a graph-attribute.
        all_sum, result = op.Scan (zero, X, body=Sum, num_scan_inputs=1)
        return result

r      selfc                N   > [         R                  " TU R                     TU 5      $ N)r   OnnxClosure__name__)r   function_framenested_functionss    r   r4   graph.<locals>.transform   s#    !!"21::">PQRRr   )r   r   r6   zvalues.OnnxClosure)sys	_getframef_localsfunction_irrB   )wrapper_frameonnx_functionr4   rA   rB   s      @@r   graphrJ   e   sX    T ]]1%NMM!$M!**62M$00AAS S r   c                6    [        U [        R                  5      $ )zAReturn True if f is a function converted by onnxscript decorator.)r8   r+   r,   )r   s    r   is_converted_funrL      s    a0011r   c           
        [         R                  " [         R                  " / / / SS0S9U  Vs/ s H0  n[         R                  R	                  UR                  5       5      PM2     snSSS9n[         R                  " X15        g s  snf )N    )inputsoutputsnodesopset_imports
   p2o)	functions
ir_versionproducer_name)r
   ModelGraphserdedeserialize_functionto_function_protosave)rV   filenamer   models       r   export_onnx_libra      sx     HH
r(		
 R[[QZA288001D1D1FGQZ[
E GGE	 \s   7B
r>   )r   zast.FunctionDefr   zvalues.Opsetr   zdict[str, Any]r   strr   Optional[values.Opset]r6   zirbuilder.IRFunction)NN)r   rc   r   rc   r3   r   r6   z=Callable[[Callable[_P, _R]], onnxscript.OnnxFunction[_P, _R]])r6   z(Callable[[Callable], values.OnnxClosure])r   r   r6   bool)rV   zSequence[values.OnnxFunction]r_   rb   r6   None)
__future__r   astr!   rD   typingr   r   r   r   r   typing_extensionsr	   r+   r
   onnxscript._internalr   r   r   r   r   r   r   r9   rJ   rL   ra    r   r   <module>rl      s    # 
  
 = = '   H HT]t_ -1--- !- 	-
 *- -* %),09!9)9 9 C	9x2j2
r   