
    SiZ(                       S SK Jr  S SKrS SKrS SKrS SKJrJr  S SKJ	r	  S SK
JrJrJr  S SKJrJrJrJrJr  S SKJr  S SKJrJr  \" S	 \" 5        5       S
 S9r\" S \" 5        5       S S9r\" S \" 5        5       S S9r    SS jr S           SS jjr " S S\R>                  5      r \!S:X  a  \RD                  " 5         gg)    )annotationsN)TensorProto	TypeProto)ValidationError)OpSchemaget_all_schemas_with_history
get_schema)
make_graph	make_nodemake_opsetidmake_tensor_type_protomake_tensor_value_info)
from_array)InferenceErrorinfer_node_outputsc              #  l   #    U  H*  oR                   S :X  d  M  UR                  S:X  d  M&  Uv   M,     g7f)Add Nnamedomain.0ss     `/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx/test/inference_function_test.py	<genexpr>r      s)     U.1&&E/QahhRTnQQ.   44	4c                    U R                   $ Nsince_versionr   s    r   <lambda>r#          !//    )keyc              #  n   #    U  H+  nUR                   S :X  d  M  UR                  S:X  d  M'  Uv   M-     g7f)Reshaper   Nr   r   s     r   r   r      s5      /A66Y 	
#$88r> 	
/s   55	5c                    U R                   $ r   r    r"   s    r   r#   r#   "   r$   r%   c              #  l   #    U  H*  oR                   S :X  d  M  UR                  S:X  d  M&  Uv   M,     g7f)Clipr   Nr   r   s     r   r   r   %   s*     V.1&&F2BQqxxSU~QQ.r   c                    U R                   $ r   r    r"   s    r   r#   r#   &   r$   r%   c                f    U R                  5        VVs0 s H  u  pU[        U6 _M     snn$ s  snnf r   )itemsr   )tensor_typesr&   values      r   _to_tensor_typesr1   *   s6     COBTBTBVWBVJCC'//BVWWWs   -c                    Uc  0 n[        U [        U R                  XU R                  S9UUR	                  5        VVs0 s H  u  pVU[        U5      _M     snn5      $ s  snnf )N)r   )r   r   r   r   r.   r   )schemainput_namesoutput_namesinput_types
input_datar&   arrs          r   	_run_caser9   0   sd     
&++{O.8.>.>.@A.@(#jo	.@A	  	Bs   Ac                  Z    \ rS rSrSS jrSS jrSS jrSS jrSS jrSS jr	SS jr
S	rg
)TestInferenceFunctionCallA   c           	        [         R                  S4[         R                  S4S.S[         R                  S404[         R                  S4[         R                  S4S.S[         R                  S404[         R                  S4[         R                  S4S.S[         R                  S404[         R                  S4[         R                  S4S.S[         R                  S404[         R                  S	4[         R                  S
4S.S[         R                  S404/nU H2  u  p#[        [        SS/S/[        U5      5      [        U5      :X  a  M2   e   g )N ABC)N   )rC   )   rC   )nm)rD   rE   rF   )xrC   )yrC   r@   rA   )r   FLOATDOUBLEr9   
ADD_SCHEMAr1   )selfcasesinsoutss       r   test_add_inference,TestInferenceFunctionCall.test_add_inferenceB   s|    #(("-[5F5F4KL{(("-. &++Y7%++T2 {(()45 &++Y7%++V4 {(()45 &,,j9%,,m< {))=9: &++X6%++X6 {(()455!
D ICc
 %	
 "$'( ( ( r%   c                    / SQnS/n[        [        R                  S4[        R                  S4S.5      n[        S[        R                  S405      n[        [        XU5      U:X  d   eg )N)Xr   maxY      r>   )rS   rT   )r1   r   rI   r9   CLIP_SCHEMA)rL   r4   r5   r6   expected_output_typess        r   'test_clip_inference_with_optional_inputATestInferenceFunctionCall.test_clip_inference_with_optional_inputm   sq    &u&$$f-{7H7H"6MN
 !1#8I8I67R1S Tk;kJ$%	
%r%   c                    U R                  [        5         [        [        S/S/[	        S[
        R                  S405      5        S S S 5        U R                  [        5         [        [        SS/S/[	        [
        R                  S4SS.5      5        S S S 5        U R                  [        5         [        [        SS/S/[	        [
        R                  S4[
        R                  S4S.5      5        S S S 5        U R                  [        5         [        [        SS/S/[	        S[
        R                  S405      5        S S S 5        g ! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g = f)Nr@   rB   rV   rA   )rC   rV   r?   )rC   rX   )	assertRaisesr   r9   rK   r1   r   rI   r   KeyErrorrL   s    r    test_add_inference_raises_errors:TestInferenceFunctionCall.test_add_inference_raises_errorsz   sF   / #(9(96'B!CD	 0 /c
 (9(96'B!UV	 0 ~.c
 )//8)//8	
 / x(c
 #(9(96'B!CD	 )(5 0/ 0/ /. )(s0   0E#2E2AE.1E?
E
E+.
E<?
Fc                   [        [        SS/S/[        [        R                  S4[        R
                  S4S.5      S[        R                  " / SQ[        R                  S905      [        S[        R                  S405      :X  d   eg )	NrG   trH   )   rX   )rW   )rG   rd   )rC   rC   re   )dtype)	r9   RESHAPE_SCHEMAr1   r   rI   INT64nparrayint64r`   s    r   test_reshape_inference0TestInferenceFunctionCall.test_reshape_inference   s    #JE%++V4%++T2 "((9BHH56
 s[%6%6	$BCDE 	E Er%   c                   SnSnSn[        S[        R                  S 5      [        S[        R                  S 5      [        S[        R                  S 5      /n[        S[        R                  S 5      [        S[        R                  X45      /n[	        [        S	S/S/5      [        S
SS/S/5      /SUU5      n[        [        SS5      [        S/ SQSS/SUS9[        [        R                  U44[        R                  X44[        R                  U44S.5      [        SS5      /SS9[        [        R                  U44[        R                  X44S.5      :X  d   eg )NsequencerC   rW   loop_state_ininputouterloop_state_outoutputIdentityr   subgraphScan	   )loop_state_orig
scan_input
scan_outerloop_state_finalscan_outputrD   )num_scan_inputsbodyr   rX   )opset_imports
ir_version)r|   r}   )
r   r   	UNDEFINEDrI   r
   r   r   r	   r1   r   )rL   seq_len
input_sizeloop_state_sizeinput_value_infosoutput_value_infosrv   s          r   !test_scan_inference_with_subgraph;TestInferenceFunctionCall.test_scan_inference_with_subgraph   s   
 #?K4I4I4P"7K,A,A4H"7K,A,A4H
 ##3[5J5JDQ"8[->->@UV

 *&7:J9KL%'7!3hZ@ 
 "vq!?#]3 ! (3(9(9O;M'N#.#4#4w6K"L#.#4#4zm"D (A./%
& %0%6%68J$K + 1 1G3HI
'
 	
 
r%   c                D   Sn[         R                  R                  U5      n[         R                  R	                  USS9  U R                  [         R                  R                  5         [         R                  R	                  USS9  S S S 5        g ! , (       d  f       g = f)Na  
        <
            ir_version: 8,
            opset_import: ["" : 18, "onnxscript.atenlib" : 1],
            producer_name: "pytorch",
            producer_version: "2.1.0"
        >
        torch_jit (float input_0) => (float reault, int64 index)
        {
            reault, index = onnxscript.atenlib.aten_min_dim <dim = 0, keepdim = 1> (input_0)
        }
        <
            domain: "onnxscript.atenlib",
            opset_import: ["" : 18]
        >
        aten_min_dim <dim>(self) => (result_7, indices_6)
        {
            tmp = Shape (self)
            tmp_0 = Size (tmp)
            tmp_1 = Constant <value = int64 tmp_1 {0}> ()
            tmp_1_cast = CastLike (tmp_1, tmp_0)
            tmp_2 = Equal (tmp_0, tmp_1_cast)
            cond = Not (tmp_2)
            indices_6, result_7 = If (cond) <
                then_branch = thenGraph_4 () => ( indices,  result) {
                    dim = Constant <value_int: int = @dim> ()
                    tmp_3 = Constant <value_ints = [-1]> ()
                    dims = Reshape (dim, tmp_3)
                    result = ReduceMin <keepdims: int = @keepdim> (self, dims)
                    indices = ArgMin <axis: int = @dim, keepdims: int = @keepdim> (self)
                }, else_branch = elseGraph_4 () => ( indices_4,  result_5) {
                    indices_4 = Constant <value_int = 0> ()
                    result_5 = Identity (self)
                }
            >
        }
        Fstrict_modeT)onnxparserparse_modelshape_inferenceinfer_shapesr^   r   rL   model_scriptmodels      r   test_inference_with_conflow5TestInferenceFunctionCall.test_inference_with_conflow   sy    $J ''5))%U)Ct33BBC  --e-F DCCs   )B
Bc                    Sn[         R                  R                  U5      n[         R                  R	                  USS9  g )Na  
        <
            ir_version: 8,
            opset_import: ["" : 18, "custom" : 1],
            producer_name: "",
            producer_version: "1.0"
        >
        MeanVarianceNormalization (float[N] x) => (float[M] y)
        {
            y = custom.custom_mvn <axes = [0]> (x)
        }
        <
            domain: "custom",
            opset_import: ["" : 18]
        >
        custom_mvn <axes>(X) => (Y)
        {
          Exponent = Constant <value = float {2.0}>()
          Epsilon = Constant <value = float {1e-9}>()
          axes = Constant <value_ints: ints = @axes>()
          X_RM = ReduceMean (X, axes)
          EX_squared = Pow (X_RM, Exponent)
          X_squared = Pow (X, Exponent)
          E_Xsquared = ReduceMean (X_squared, axes)
          Variance = Sub (E_Xsquared, EX_squared)
          STD = Sqrt (Variance)
          X_variance = Sub (X, X_RM)
          Processed_STD = Add (STD, Epsilon)
          Y = Div (X_variance, Processed_STD)
        }
        Tr   )r   r   r   r   r   r   s      r   test_inference_with_attribute7TestInferenceFunctionCall.test_inference_with_attribute	  s8    > ''5))%T)Br%   r>   N)returnNone)__name__
__module____qualname____firstlineno__rP   r[   ra   rl   r   r   r   __static_attributes__r>   r%   r   r;   r;   A   s,    )(V
!FE1
f)GV"Cr%   r;   __main__)r/   z3dict[str, tuple[int, tuple[int | str | None, ...]]]r   dict[str, TypeProto]r   )r3   r   r4   	list[str]r5   r   r6   r   r7   zdict[str, np.ndarray] | Noner   r   )#
__future__r   unittestnumpyri   r   r   r   onnx.checkerr   	onnx.defsr   r   r	   onnx.helperr
   r   r   r   r   onnx.numpy_helperr   onnx.shape_inferencer   r   rT   rK   rg   rY   r1   r9   TestCaser;   r   mainr>   r%   r   <module>r      s   #    ' ( H H  ) CU,.U!
 -/
 	" V,.V!XEXX 04  &	
 - "jC 1 1 jCZ zMMO r%   