
    Si$                        S SK Jr  S SKrS SKrS SKrS SKrS SKr " S S\R                  5      r\	S:X  a  \R                  " 5         gg)    )annotationsNc                  t    \ rS rSrSS jrSS jrS rS rS rS r	S r
S	 rSS
 jrS rS rS rS rS rSrg)TestModelInference   c                   [         R                  R                  U5      n[         R                  R	                  U5      nUR
                  R                  n[        XRSS9 Hz  u  pgUR                  nU R                  UR                  S5      5        UR                  n	U R                  U	R                  S5      5        U	R                  n
U R                  X5        M|     g)zCheck that the model inference infers the expected types for outputs.
Restricted to the simple case of tensor types, so expected types specify
only the element type (ints corresponding to onnx.TensorProto.DataType).
Fstricttensor_type	elem_typeN)onnxparserparse_modelshape_inferenceinfer_shapesgraphoutputziptype
assertTrueHasFieldr
   r   assertEqual)self
model_textexpectedmodelinferredoutputsr   expected_elem_typeinferred_typer
   r   s              ]/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx/test/model_inference_test.py_checkTestModelInference._check   s    
 ''
3''44U;..''*-g*N&F"KKMOOM22=AB'33KOOK00=>#--IY; +O    c                
   [         R                  R                  U5      nU R                  [         R                  R
                  5         [         R                  R                  USS5        SSS5        g! , (       d  f       g= f)z8Check that the model inference raises an InferenceError.TN)r   r   r   assertRaisesr   InferenceErrorr   )r   r   r   s      r    _check_inference_error)TestModelInference._check_inference_error   sU    ''
3t33BBC  --eT4@ DCCs   	"A44
Bc                *    SnU R                  U5        g)zTest that model inference handles unknown ops.
This special treatment is to support custom ops.
See comments in shape inference code for details.
z
            <ir_version: 7, opset_import: [ "" : 17]>
            agraph (float[N] x) => (y)
            {
                y = SomeUnknownOp (x)
            }
        N)r!   r   r   s     r    test_unknown_op"TestModelInference.test_unknown_op%   s    
 	Er#   c                \    SnU R                  U[        R                  R                  5        g)z3Test that model inference infers model output type.z
            <
                ir_version: 7,
                opset_import: [ "" : 17]
            >
            agraph (float[N] x) => (y)
            {
                y = Cast<to=6> (x)
            }
        Nr!   r   TensorProtoINT32r*   s     r    test_mi_basic TestModelInference.test_mi_basic5   s%    	 	E4++112r#   c                \    SnU R                  U[        R                  R                  5        g)Test use of functions.a  
            <
                ir_version: 7,
                opset_import: [ "" : 17, "local" : 1]
            >
            agraph (float[N] x) => (y)
            {
                y = local.cast(x)
            }
            <
                opset_import: [ "" : 17 ],
                domain: "local"
            >
            cast (x) => (y)
            {
                y = Cast<to=6> (x)
            }
        Nr.   r*   s     r    test_mi_function#TestModelInference.test_mi_functionC   %    $ 	E4++112r#   c                \    SnU R                  U[        R                  R                  5        g)z0Test use of functions with attribute parameters.a  
            <
                ir_version: 7,
                opset_import: [ "" : 17, "local" : 1]
            >
            agraph (float[N] x) => (y)
            {
                y = local.cast<target=6>(x)
            }
            <
                opset_import: [ "" : 17 ],
                domain: "local"
            >
            cast<target>(x) => (y)
            {
                y = Cast<to:int = @target> (x)
            }
        Nr.   r*   s     r    test_mi_function_attr(TestModelInference.test_mi_function_attrY   r7   r#   c                \    SnU R                  U[        R                  R                  5        g)z1Test use of function attributes within subgraphs.a  
            <
                ir_version: 7,
                opset_import: [ "" : 17, "local" : 1]
            >
            agraph (float[N] x, bool flag) => (y)
            {
                y = local.cast<target=6>(x, flag)
            }
            <
                opset_import: [ "" : 17 ],
                domain: "local"
            >
            cast<target>(x, flag) => (y)
            {
                y = If (flag) <
                    then_branch = g1 () => (z_then) { z_then = Cast<to:int = @target> (x) },
                    else_branch = g2 () => (z_else) { z_else = Cast<to:int = @target> (x) }
                    >
            }
        Nr.   r*   s     r    test_mi_function_subgraph_attr1TestModelInference.test_mi_function_subgraph_attro   s%    * 	E4++112r#   c                    SnU R                  U[        R                  R                  [        R                  R                  5        g)z-Test use of multiple invocation of functions.a  
            <
                ir_version: 7,
                opset_import: [ "" : 17, "local" : 1]
            >
            agraph (float[N] x, bool flag) => (y, z)
            {
                y = local.cast<target=6>(x, flag)
                z = local.cast<target=7>(x, flag)
            }
            <
                opset_import: [ "" : 17 ],
                domain: "local"
            >
            cast<target>(x, flag) => (y)
            {
                y = If (flag) <
                    then_branch = g1 () => (z_then) { z_then = Cast<to:int = @target> (x) },
                    else_branch = g2 () => (z_else) { z_else = Cast<to:int = @target> (x) }
                    >
            }
        Nr!   r   r/   r0   INT64r*   s     r    test_mi_function_multiple_calls2TestModelInference.test_mi_function_multiple_calls   s3    , 	E4++1143C3C3I3IJr#   c                   [         R                  R                  U5      n[         R                  R	                  USSS5      nUR
                  R                  n[        XRSS9 H  u  pgUR                  nU R                  UR                  S5      5        UR                  n	U R                  U	R                  S5      5        U	R                  n
U R                  [        U
R                  5      [        U5      5        [        U
R                  USS9 HA  u  pU R                  UR                  S5      5        U R                  UR                   U5        MC     M     g)zCheck that the model inference infers the expected shapes for outputs.
Restricted to the simple case of tensor type outputs with completely
known shapes.
Tr   r
   shape	dim_valueN)r   r   r   r   r   r   r   r   r   r   r   r
   rD   r   lendimrE   )r   r   r   r   r   r   r   expected_shaper   r
   inferred_shapeinferred_dimexpected_dims                r    _check_shapeTestModelInference._check_shape   s   
 ''
3''44UD$M..''&)'D&I"F"KKMOOM22=AB'33KOOK009:(..NS!3!34c.6IJ.1""N4/*  5 5k BC  !7!7F	/ 'Jr#   c                0    SnU R                  U/ SQ5        g )Na  
            <
                ir_version: 7,
                opset_import: [ "" : 17]
            >
            mymodel (float[4, 8, 16] x) => (y) {
                shape = Constant<value_ints=[8,4,16]>()
                y = Reshape(x, shape)
            }
                     rL   r*   s     r    test_mi_constant#TestModelInference.test_mi_constant   s    	 	%,r#   c                0    SnU R                  U/ SQ5        g )Nae  
            <
                ir_version: 7,
                opset_import: [ "" : 17]
            >
            mymodel (float[4, 8, 16] x) => (y) {
                shape = Constant<value_ints=[4,2,8]>()
                two = Constant<value_int=2>()
                shape2 = Mul(shape, two)
                y = Reshape(x, shape2)
            }
            rO   rS   r*   s     r    test_mi_constant_2%TestModelInference.test_mi_constant_2   s     	%,r#   c                6    SnU R                  USS// SQ5        g )Na:  
            <
                ir_version: 7,
                opset_import: [ "" : 17, "local" : 1]
            >
            main (float x) => (y, z) {
                y, z = local.expand(x)
            }
            <
                opset_import: [ "" : 17 ],
                domain: "local"
            >
            expand (x) => (y, z) {
                shape1 = Constant<value = int64[2] {4,4}>()
                shape2 = Constant<value = int64[3] {8,8,8}>()
                z = Expand (x, shape2)
                y = Expand (x, shape1)
            }
            rQ   )rP   rP   rP   rS   r*   s     r    test_mi_constant_in_function/TestModelInference.test_mi_constant_in_function   s!    & 	%!Q3r#   c                    SnU R                  U[        R                  R                  [        R                  R                  5        g)z2Test use of default values of function attributes.a  
            <ir_version: 7, opset_import: [ "" : 17, "local" : 1]>
            agraph (float[N] x) => (y, z)
            {
                y = local.cast <target=6> (x) # casts to INT32 type (encoding value 6)
                z = local.cast (x)  # uses default-attribute value of 1 (FLOAT type)
            }

            <opset_import: [ "" : 17 ], domain: "local">
            cast <target: int = 1> (x) => (y)
            {
                y = Cast <to:int = @target> (x)
            }
        N)r!   r   r/   r0   FLOATr*   s     r    test_mi_function_default_attr0TestModelInference.test_mi_function_default_attr   s3     	E4++1143C3C3I3IJr#   c                    SnU R                  U[        R                  R                  [        R                  R                  5        g)r4   a?  
            <ir_version: 10, opset_import: [ "" : 17, "local" : 1]>
            agraph (float[N] x) => (y, z)
            {
                y = local.cast:to_int32 (x)
                z = local.cast:to_int64 (x)
            }
            <opset_import: [ "" : 17 ], domain: "local", overload: "to_int32">
            cast (x) => (y)
            {
                y = Cast<to=6> (x)
            }
            <opset_import: [ "" : 17 ], domain: "local", overload: "to_int64">
            cast (x) => (y)
            {
                y = Cast<to=7> (x)
            }
        Nr?   r*   s     r    test_mi_overloaded_function.TestModelInference.test_mi_overloaded_function   s3    $ 	E4++1143C3C3I3IJr#    N)r   strr   int)r   rd   )r   rd   r   ztyping.Sequence[int])__name__
__module____qualname____firstlineno__r!   r'   r+   r1   r5   r9   r<   rA   rL   rT   rW   rZ   r^   ra   __static_attributes__rc   r#   r    r   r      sM    < A 33,3,32K4G*--4,K$Kr#   r   __main__)
__future__r   typingunittestr   onnx.parseronnx.shape_inferenceTestCaser   rf   mainrc   r#   r    <module>rs      sH    #     AK** AKH zMMO r#   