
    hF                         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)    Nc                       \ rS rSrS\S\4S jrS rS rS r	S r
S	 rS\S\R                  \   4S
 jrS rS rS rS rSrg)TestModelInference   
model_textexpectedc                    [         R                  R                  U5      n[         R                  R	                  U5      nUR
                  R                  n[        XR5       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).
tensor_type	elem_typeN)onnxparserparse_modelshape_inferenceinfer_shapesgraphoutputziptype
assertTrueHasFieldr	   r
   assertEqual)selfr   r   modelinferredoutputsr   expected_elem_typeinferred_typer	   r
   s              X/var/www/fran/franai/venv/lib/python3.13/site-packages/onnx/test/model_inference_test.py_checkTestModelInference._check   s    
 ''
3''44U;..''*-g*@&F"KKMOOM22=AB'33KOOK00=>#--IY; +A    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INT32r   r   s     r   test_mi_basic TestModelInference.test_mi_basic   s%    	 	E4++112r    c                 \    SnU R                  U[        R                  R                  5        g)z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_function+   %    $ 	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_attrA   r+   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_attrW   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#   r$   INT64r%   s     r   test_mi_function_multiple_calls2TestModelInference.test_mi_function_multiple_callsp   s3    , 	E4++1143C3C3I3IJr    c                    [         R                  R                  U5      n[         R                  R	                  USSS5      nUR
                  R                  n[        XR5       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5       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	   shape	dim_valueN)r   r   r   r   r   r   r   r   r   r   r   r	   r7   r   lendimr8   )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..''&)'&<"F"KKMOOM22=AB'33KOOK009:(..NS!3!34c.6IJ.1.2D2Dn.U* 5 5k BC  !7!7F /V '=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)
            }
                     r?   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)
            }
            rB   rF   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)
            }
            rD   )rC   rC   rC   rF   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#   r$   FLOATr%   s     r   test_mi_function_default_attr0TestModelInference.test_mi_function_default_attr   s3     	E4++1143C3C3I3IJr     N)__name__
__module____qualname____firstlineno__strintr   r&   r)   r-   r0   r4   typingSequencer?   rG   rJ   rM   rQ   __static_attributes__rS   r    r   r   r      sc    < < < 33,3,32K4Gs Gvs7K G&--4,Kr    r   __main__)	rZ   unittestr   onnx.parseronnx.shape_inferenceTestCaser   rT   mainrS   r    r   <module>rc      sE        SK** SKl zMMO r    