§
    ú¸¸j·$  ã                  óŽ   — d dl mZ d dlZd dlZd dlZd dlZd dlZ G d„ dej        ¦  «        Ze	dk    r ej
        ¦   «          dS dS )é    )ÚannotationsNc                  óh   — e Zd Zdd„Zdd„Zd„ Zd„ Zd	„ Zd
„ Zd„ Z	d„ Z
dd„Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚTestModelInferenceÚ
model_textÚstrÚexpectedÚintc                ó¼  — t           j                             |¦  «        }t           j                             |¦  «        }|j        j        }t          ||¦  «        D ]€\  }}|j        }|  	                    | 
                    d¦  «        ¦  «         |j        }	|  	                    |	 
                    d¦  «        ¦  «         |	j        }
|                      |
|¦  «         Œ�dS )zðCheck 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              ún/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/onnx/test/model_inference_test.pyÚ_checkzTestModelInference._check   sÓ   € õ
 ”×'Ò'¨
Ñ3Ô3ˆÝÔ'×4Ò4°UÑ;Ô;ˆØ”.Ô'ˆÝ*-¨g°xÑ*@Ô*@ð 	<ð 	<Ñ&ˆFÐ&Ø"œKˆMØ�OŠO˜M×2Ò2°=ÑAÔAÑBÔBÐBØ'Ô3ˆKØ�OŠO˜K×0Ò0°Ñ=Ô=Ñ>Ô>Ð>Ø#Ô-ˆIØ×Ò˜YÐ(:Ñ;Ô;Ð;Ð;ð	<ð 	<ó    c                ó   — t           j                             |¦  «        }|                      t           j        j        ¦  «        5  t           j                             |dd¦  «         ddd¦  «         dS # 1 swxY w Y   dS )z8Check that the model inference raises an InferenceError.TN)r   r   r   ÚassertRaisesr   ÚInferenceErrorr   )r   r   r   s      r   Ú_check_inference_errorz)TestModelInference._check_inference_error   sÄ   € å”×'Ò'¨
Ñ3Ô3ˆØ×Ò�tÔ3ÔBÑCÔCð 	Að 	AÝÔ ×-Ò-¨e°T¸4Ñ@Ô@Ð@ð	Að 	Að 	Añ 	Aô 	Að 	Að 	Að 	Að 	Að 	Að 	Að 	Aøøøð 	Að 	Að 	Að 	Að 	Að 	As   Á"A3Á3A7Á:A7c                ó4   — d}|                       |¦  «         dS )zªTest 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_opz"TestModelInference.test_unknown_op%   s#   € ð
ˆð 	�Š�EÑÔÐÐÐr!   c                óT   — d}|                       |t          j        j        ¦  «         dS )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_basicz TestModelInference.test_mi_basic5   s+   € ð	ˆð 	�Š�E�4Ô+Ô1Ñ2Ô2Ð2Ð2Ð2r!   c                óT   — d}|                       |t          j        j        ¦  «         dS )ú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_functionz#TestModelInference.test_mi_functionC   ó+   € ðˆð$ 	�Š�E�4Ô+Ô1Ñ2Ô2Ð2Ð2Ð2r!   c                óT   — d}|                       |t          j        j        ¦  «         dS )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_attrz(TestModelInference.test_mi_function_attrY   r1   r!   c                óT   — d}|                       |t          j        j        ¦  «         dS )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_attrz1TestModelInference.test_mi_function_subgraph_attro   s+   € ðˆð* 	�Š�E�4Ô+Ô1Ñ2Ô2Ð2Ð2Ð2r!   c                ót   — d}|                       |t          j        j        t          j        j        ¦  «         dS )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_callsz2TestModelInference.test_mi_function_multiple_callsˆ   s3   € ðˆð, 	�Š�E�4Ô+Ô1µ4Ô3CÔ3IÑJÔJÐJÐJÐJr!   útyping.Sequence[int]c                ó¼  — t           j                             |¦  «        }t           j                             |ddd¦  «        }|j        j        }t          ||¦  «        D ]ý\  }}|j        }|  	                    | 
                    d¦  «        ¦  «         |j        }	|  	                    |	 
                    d¦  «        ¦  «         |	j        }
|                      t          |
j        ¦  «        t          |¦  «        ¦  «         t          |
j        |¦  «        D ]H\  }}|  	                    | 
                    d¦  «        ¦  «         |                      |j        |¦  «         ŒIŒþdS )z²Check 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   r<   r   ÚlenÚdimr=   )r   r   r   r   r   r   r   Úexpected_shaper   r   Úinferred_shapeÚinferred_dimÚexpected_dims                r   Ú_check_shapezTestModelInference._check_shape¢   sP  € õ
 ”×'Ò'¨
Ñ3Ô3ˆÝÔ'×4Ò4°U¸DÀ$ÈÑMÔMˆØ”.Ô'ˆÝ&)¨'°8Ñ&<Ô&<ð 		Gð 		GÑ"ˆF�NØ"œKˆMØ�OŠO˜M×2Ò2°=ÑAÔAÑBÔBÐBØ'Ô3ˆKØ�OŠO˜K×0Ò0°Ñ9Ô9Ñ:Ô:Ð:Ø(Ô.ˆNØ×Ò�S Ô!3Ñ4Ô4µc¸.Ñ6IÔ6IÑJÔJÐJÝ.1°.Ô2DÀnÑ.UÔ.Uð Gð GÑ*�˜lØ—’ × 5Ò 5°kÑ BÔ BÑCÔCÐCØ× Ò  Ô!7¸ÑFÔFÐFÐFðGð		Gð 		Gr!   c                ó:   — d}|                       |g d¢¦  «         d S )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)
            }
            ©é   é   é   ©rD   r'   s     r   Útest_mi_constantz#TestModelInference.test_mi_constantµ   s+   € ð	ˆð 	×Ò˜%   Ñ,Ô,Ð,Ð,Ð,r!   c                ó:   — d}|                       |g d¢¦  «         d S )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)
            }
            rF   rJ   r'   s     r   Útest_mi_constant_2z%TestModelInference.test_mi_constant_2Â   s+   € ðˆð 	×Ò˜%   Ñ,Ô,Ð,Ð,Ð,r!   c                ó@   — d}|                       |ddgg d¢¦  «         d S )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)
            }
            rH   )rG   rG   rG   rJ   r'   s     r   Útest_mi_constant_in_functionz/TestModelInference.test_mi_constant_in_functionÑ   s1   € ðˆð& 	×Ò˜% ! Q ¨¨¨Ñ3Ô3Ð3Ð3Ð3r!   c                ót   — d}|                       |t          j        j        t          j        j        ¦  «         dS )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_attrz0TestModelInference.test_mi_function_default_attrç   s3   € ðˆð 	�Š�E�4Ô+Ô1µ4Ô3CÔ3IÑJÔJÐJÐJÐJr!   c                ót   — d}|                       |t          j        j        t          j        j        ¦  «         dS )r/   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)
            }
        Nr7   r'   s     r   Útest_mi_overloaded_functionz.TestModelInference.test_mi_overloaded_functionù   s3   € ðˆð$ 	�Š�E�4Ô+Ô1µ4Ô3CÔ3IÑJÔJÐJÐJÐJr!   N)r   r   r   r	   )r   r   )r   r   r   r:   )Ú__name__Ú
__module__Ú__qualname__r    r%   r(   r-   r0   r3   r5   r9   rD   rK   rM   rO   rR   rT   © r!   r   r   r      s  € € € € € ð<ð <ð <ð <ð Að Að Að Aðð ð ð 3ð 3ð 3ð3ð 3ð 3ð,3ð 3ð 3ð,3ð 3ð 3ð2Kð Kð Kð4Gð Gð Gð Gð&-ð -ð -ð-ð -ð -ð4ð 4ð 4ð,Kð Kð Kð$Kð Kð Kð Kð Kr!   r   Ú__main__)Ú
__future__r   ÚtypingÚunittestr   Úonnx.parserÚonnx.shape_inferenceÚTestCaser   rU   ÚmainrX   r!   r   ú<module>ra      s°   ðð #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€à €€€Ø Ð Ð Ð Ø Ð Ð Ð ðKð Kð Kð Kð K˜Ô*ñ Kô Kð KðD ˆzÒÐØ€H„M�O„O€O€O€Oð Ðr!   