
    h                        S SK r S SKJrJrJrJrJr  S SKrS SK	J
r
JrJrJrJrJrJrJrJrJrJrJr  S\S\4S jrS\S\S\4S	 jrS
\S\\   4S jrS\S\4S jrSrSr " S S\ R<                  5      r\ S:X  a  \ RB                  " 5         gg)    N)CallableListOptionalSequenceTuple)FunctionProto
GraphProto
ModelProto	NodeProtoSparseTensorProtoTensorProtoValueInfoProtocheckercomposehelperparserversion_converterm_defreturnc                 ^    [         R                  " U 5      n[        R                  " U5        U$ )z[
Parses a model from a string representation, including checking the model for correctness
)r   parse_modelr   check_model)r   ms     P/var/www/fran/franai/venv/lib/python3.13/site-packages/onnx/test/compose_test.py_load_modelr      s'     	5!AH    prefixsc                 ,    [        U5      S:  a  X-   $ U$ )z"
Prefixes a string (if not empty)
r   )len)r   r   s     r   	_prefixedr!   #   s     Q!6:**r   
value_infoc                    [        [        U R                  R                  R                  R
                  5      5       Vs/ s H:  nU R                  R                  R                  R
                  U   R                  PM<     sn$ s  snf )zR
Returns a list of integers representing the shape of the provided ValueInfoProto
)ranger    typetensor_typeshapedim	dim_value)r"   ds     r   
_get_shaper+   *   sj     s:??66<<@@ABBA 	##))--a0::B  s   ABnamec                    SS/n/ SQn/ SQn[         R                  " U S-   [        R                  [	        U5      /[
        R                  " U5      R                  [
        R                  5      SS9n[         R                  " U S-   [        R                  [	        U5      /[
        R                  " U5      R                  [
        R                  5      SS9n[         R                  " XEU5      $ )N   )   r.      )g333333?g?g?_valuesF)r,   	data_typedimsvalsraw_idx)r   make_tensorr   FLOATr    nparrayastypefloat32INT64int64make_sparse_tensor)r,   dense_shapelinear_indicessparse_valuesvalues_tensorindices_tensors         r   _make_sparse_tensorrE   4   s    a&KN#M&&I##- !XXm$++BJJ7M ''F]##.!"XXn%,,RXX6N $$]KPPr   a)  
    <
        ir_version: 7,
        opset_import: [ "": 10, "com.microsoft": 1]
    >
    agraph (float[N, M] A0, float[N, M] A1, float[N, M] _A) => (float[N, M] B00, float[N, M] B10, float[N, M] B20)
    {
        B00 = Add(A0, A1)
        B10 = Sub(A0, A1)
        B20 = Mul(A0, A1)
    }
    a
  
    <
        ir_version: 7,
        opset_import: [ "": 10, "com.microsoft": 1]
    >
    agraph (float[N, M] B01, float[N, M] B11, float[N, M] B21) => (float[N, M] D0)
    {
        C0 = Add(B01, B11)
        C1 = Sub(B11, B21)
        M1 = Mul(C0, C1)
    }
    c                   \   \ rS rSr    S;S\S\S\\\\4      S\\\\/S4   S\	\\      S\	\\      S	\	\   S
\	\   SS4S j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<S jrS<S jrS<S jrS<S jrS<S jr       S=S\S\S\S\S\S\S\SS4S j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<S& jrS<S' jr          S>S(\ \   S)\ \   S*\ \   S+\ \   S,\ \   S-\ \   S.\ \   S/\ \   S0\ \   S1\ \   SS4S2 jjr!S<S3 jr"S<S4 jr#S<S5 jr$S<S6 jr%S<S7 jr&S<S8 jr'S<S9 jr(S:r)g)?TestComposeFunctionse   Nm1defm2defio_mapcheck_expectationsinputsoutputsprefix1prefix2r   c	           
         [        U5      [        U5      p[        R                  " U	R                  U
R                  UUUUUS9n[        R
                  " U5        U" U	R                  U
R                  U5        [        R                  " U	U
UUUUUS9n[        R                  " U5        U" U	R                  U
R                  UR                  5        g )N)rK   rM   rN   rO   rP   )r   r   merge_graphsgraphr   check_graphmerge_modelsr   )selfrI   rJ   rK   rL   rM   rN   rO   rP   m1m2g3m3s                r   _test_merge_models'TestComposeFunctions._test_merge_modelsf   s     U#[%7B!!HHHH
 	B288RXXr2!!
 	B288RXXrxx8r   c                 |   ^  S[         S[         S[         SS4U 4S jjn/ SQnT R                  [        [        X!5        g)z
Tests a simple scenario where two models without overlapping names are merged by
connecting all the outputs in the first models to all the inputs in the second model
g1g2rY   r   Nc                   > TR                  UR                  U R                  5        TR                  UR                  UR                  5        TR                  / SQUR                   Vs/ s H  o3R                  PM     sn5        g s  snf )NAddSubMulrb   rc   rd   )assertEqualinputoutputnodeop_type)r^   r_   rY   itemrV   s       r   rL   XTestComposeFunctions.test_case_connect_all_no_name_collision.<locals>.check_expectations   s_    RXXrxx0RYY		2:*,''2'$'22s   *B
B00B01B10B11B20B21r	   r[   M1_DEFM2_DEFrV   rL   rK   s   `  r   'test_case_connect_all_no_name_collision<TestComposeFunctions.test_case_connect_all_no_name_collision   s?    	: 	: 	: 	RV 	 BKr   c                 |   ^  S[         S[         S[         SS4U 4S jjn/ SQnT R                  [        [        X!5        g)z}
Tests a scenario where we merge two models by connecting a single output in the first model
to all the inputs in the second
r^   r_   rY   r   Nc                 H  > ATR                  UR                  U R                  5        TR                  / SQUR                   Vs/ s H  o3R                  PM     sn5        TR                  / SQUR                   Vs/ s H  oDR
                  PM     sn5        g s  snf s  snf )N)rq   rt   D0ra   re   rf   rg   r,   rh   ri   r^   r_   rY   elemrj   rV   s        r   rL   TTestComposeFunctions.test_case_connect_same_output_twice.<locals>.check_expectations   sx    RXXrxx01"))3T)$II)3TU:*,''2'$'2 4U 3s   B
=B
rm   )rn   rr   )rn   ru   rv   ry   s   `  r   #test_case_connect_same_output_twice8TestComposeFunctions.test_case_connect_same_output_twice   s?    	: 	: 	: 	RV 	 BKr   c                    ^  S[         S[         S[         SS4U 4S jjn/ SQnS/nT R                  [        [        X!US	9  g)
z
Tests a scenario where we merge two models by connecting a single output in the first model
to all the inputs in the second, while dropping the rest of the outputs in the first model
r^   r_   rY   r   Nc                 F  > ATR                  UR                  U R                  5        TR                  S/UR                   Vs/ s H  o3R                  PM     sn5        TR                  / SQUR                   Vs/ s H  oDR
                  PM     sn5        g s  snf s  snf )Nr~   )rb   rb   rc   rd   r   r   s        r   rL   [TestComposeFunctions.test_case_connect_same_output_drop_outputs.<locals>.check_expectations   sv    RXXrxx0dVBII%FIDiiI%FG,.P||.P &G.Ps   B
<B
r   r~   )rN   rv   )rV   rL   rK   rN   s   `   r   *test_case_connect_same_output_drop_outputs?TestComposeFunctions.test_case_connect_same_output_drop_outputs   sP    	: 	: 	: 	RV 	 B&FF 	  	
r   c                 p   ^  SnSnS/nS[         S[         S[         SS4U 4S	 jjnT R                  XX45        g)
zk
Tests a scenario where we merge two models, where the inputs/outputs connected
are named exactly the same
z
            <
                ir_version: 7,
                opset_import: [ "": 10]
            >
            agraph (float[N, M] A) => (float[N, M] B)
            {
                B = Add(A, A)
            }
            z
            <
                ir_version: 7,
                opset_import: [ "": 10]
            >
            agraph (float[N, M] B) => (float[N, M] C)
            {
                C = Add(B, B)
            }
            )Br   r^   r_   rY   r   Nc                    > A ATR                  S/UR                   Vs/ s H  o3R                  PM     sn5        TR                  S/UR                   Vs/ s H  o3R                  PM     sn5        g s  snf s  snf )NACre   rf   r,   rg   r^   r_   rY   r   rV   s       r   rL   YTestComposeFunctions.test_case_connect_same_input_output_name.<locals>.check_expectations   s_    BcU288$D84YY8$DEcU299$E94YY9$EF %E$Es   A3
A8
r	   r[   )rV   m1_defm2_defrK   rL   s   `    r   (test_case_connect_same_input_output_name=TestComposeFunctions.test_case_connect_same_input_output_name   sS    		 	G: 	G: 	G: 	GRV 	G 	Kr   c           	      z   ^  SnSnS/nS[         S[         S[         SS4U 4S	 jjnS
/nS/nT R                  XX4XVS9  g)zV
Tests a scenario where we merge two models, not including some of the inputs/outputs
a  
            <
                ir_version: 7,
                opset_import: [ "": 10]
            >
            agraph (float[N] A0, float[N] B0) => (float[N] A1, float[N] B1)
            {
                A1 = Add(A0, A0)
                B1 = Sub(B0, B0)
            }
            a  
            <
                ir_version: 7,
                opset_import: [ "": 10]
            >
            agraph (float[N] A2, float[N] B2) => (float[N] A3, float[N] B3)
            {
                A3 = Add(A2, A2)
                B3 = Sub(B2, B2)
            }
            )A1B2r^   r_   rY   r   Nc                 t  > A ATR                  S/UR                   Vs/ s H  o3R                  PM     sn5        TR                  S/UR                   Vs/ s H  o3R                  PM     sn5        TR                  SS/UR                   Vs/ s H  o3R
                  PM     sn5        g s  snf s  snf s  snf )NA0B3rb   rc   re   rf   r,   rg   rh   ri   r   s       r   rL   NTestComposeFunctions.test_case_drop_inputs_outputs.<locals>.check_expectations  s    BdVBHH%EHDiiH%EFdVBII%FIDiiI%FGeU^rww-Owtllw-OP &F%F-Os   B+
B0
B5
r   r   rM   rN   r   )rV   r   r   rK   rL   rM   rN   s   `      r   test_case_drop_inputs_outputs2TestComposeFunctions.test_case_drop_inputs_outputs   sk    


 	Q: 	Q: 	Q: 	QRV 	Q &Fv 	  	
r   c           	      l   ^  SnS/nS[         S[         S[         SS4U 4S jjnT R                  XX#S	S
S9  g)z{
Tests a scenario where we merge two models that have name collisions, but they
are avoided by prefixing the models model.
z
            <
                ir_version: 7,
                opset_import: [ "": 10]
            >
            agraph (float[N] A, float[N] B) => (float[N] C)
            {
                C = Add(A, B)
            }
            )r   r   r^   r_   rY   r   Nc                 v  > A ATR                  / SQUR                   Vs/ s H  o3R                  PM     sn5        TR                  S/UR                   Vs/ s H  o3R                  PM     sn5        TR                  SS/UR                   Vs/ s H  o3R
                  PM     sn5        g s  snf s  snf s  snf )N)zm1/Azm1/Bzm2/Bzm2/Crb   r   r   s       r   rL   PTestComposeFunctions.test_case_name_collision_prefix.<locals>.check_expectations   s    B5bhh7Whd		h7WXfXbii'Hid		i'HIeU^rww-Owtllw-OP 8X'H-Os   B,
B1
B6
m1/m2/)rO   rP   r   )rV   r   rK   rL   s   `   r   test_case_name_collision_prefix4TestComposeFunctions.test_case_name_collision_prefix  sX    	 	Q: 	Q: 	Q: 	QRV 	Q 	Fu 	  	
r   c                 |   ^  S[         S[         S[         SS4U 4S jjnSS/nT R                  [        [        X!5        g)	z
Tests a scenario where two models without overlapping names are merged by
connecting some outputs from the first model to some inputs in the second.
The remaining inputs/outputs should be present in the combined model
r^   r_   g4r   Nc                    > A ATR                  / SQUR                   Vs/ s H  o3R                  PM     sn5        TR                  SS/UR                   Vs/ s H  o3R                  PM     sn5        g s  snf s  snf )N)r   r   _Aru   rt   r~   r   )r^   r_   r   r   rV   s       r   rL   ^TestComposeFunctions.test_case_connect_partially_no_name_collision.<locals>.check_expectations2  sf    B )"((+K($II(+K eT]299,M94YY9,MN ,L,Ms   A5
A:
rm   rp   rv   ry   s   `  r   -test_case_connect_partially_no_name_collisionBTestComposeFunctions.test_case_connect_partially_no_name_collision+  sH    	O: 	O: 	O: 	ORV 	O !.1Kr   c                    [        [        5      n[        R                  " USSS.5        [        [        5      n[        R                  " USSS.5        S/n[
        R                  " XUS9n[        UR                  5      S	:X  d   e[        R                  " USSS
.5        [
        R                  " XUS9n[        UR                  5      S:X  d   e[        R                  " USSS
.5        U R                  [        [
        R                  XUS9  g )Nv1v2)p1p2v3v4)p3p4rm   rK      )r   r   r.   v5)r   rw   r   set_model_propsrx   r   rU   r    metadata_propsassertRaises
ValueErrorrV   rW   rX   rK   rZ   s        r   %test_merge_models_with_metadata_props:TestComposeFunctions.test_merge_models_with_metadata_props?  s     r$d#;< r$d#;< !!!"82$$%*** 	r$d#;<!!"82$$%*** 	r$d#;<*g&:&:B6Rr   c                     [        [        5      [        [        5      p!U R                  [        [
        R                  UU/ SQS9  U R                  [        [
        R                  UU/ SQS9  g)za
Tests that providing a non existing output/input name in the io_map argument produces an error.
))wrong_outnamero   rp   rs   r   ))rn   wrong_inputrp   rs   N)r   rw   rx   r   r   r   rU   rV   rW   rX   s      r   "test_error_wrong_input_output_name7TestComposeFunctions.test_error_wrong_input_output_nameS  sg     V$k&&9B  M 	 	
 	  K 	 	
r   c                 z    [        S5      n[        S5      nU R                  [        [        R                  XS/S9  g )Nz
    <
        ir_version: 7,
        opset_import: [ "": 13]
    >
    agraph (float[N, M] X0) => (float[N, M] Y0)
    {
        Y0 = Add(X0, X0)
    }
    z
    <
        ir_version: 6,
        opset_import: [ "": 13]
    >
    agraph (float[N, M] X1) => (float[N, M] Y1)
    {
        Y1 = Add(X1, X1)
    }
    )Y0X1r   )r   r   r   r   rU   r   s      r   test_error_ir_version_mismatch3TestComposeFunctions.test_error_ir_version_mismatchj  sH    	
 	
 	,,bl^ 	 	
r   c                    [        [        5      [        [        5      p![        R                  " UR
                  S[        R                  " SS5      /S9n[        R                  " UR
                  S[        R                  " SS5      /S9n/ SQnU R                  [        [        R                  XU5        [        R                  " US5      n[        R                  " XUS9n[        R                  " U5        g)	zSTests that providing models with different operator set imported produces an error.test 
   producer_nameopset_imports   rl   r   N)r   rw   rx   r   
make_modelrS   make_opsetidr   r   r   rU   r   convert_versionr   r   r   s        r    test_error_opset_import_mismatch5TestComposeFunctions.test_error_opset_import_mismatch  s    V$k&&9BHHF6;N;NrSU;V:W
 HHF6;N;NrSU;V:W
 B*g&:&:BFK ..r26!!"8Br   rename_nodesrename_edgesrename_inputsrename_outputsrename_initializersrename_value_infosinplacec                 Z   [        [        5      nSn	U(       a8  [        5       n
U
R                  U5        [        R
                  " U
U	UUUUUUSS9	  O[        R
                  " UU	UUUUUUS9n
UR                  nU
R                  nU(       d  U(       d  U(       d  U(       d  U(       Ga  0 nU(       aS  UR                   HC  nUR                   H  n[        X5      X'   M     UR                   H  n[        X5      X'   M     ME     U(       a6  UR                   H&  n[        U	UR                  5      UUR                  '   M(     U(       a6  UR                   H&  n[        U	UR                  5      UUR                  '   M(     U(       a  UR                   H&  n[        U	UR                  5      UUR                  '   M(     UR                   Hq  n[        U	UR                  R                  5      UUR                  R                  '   [        U	UR                  R                  5      UUR                  R                  '   Ms     U(       a6  UR                   H&  n[        U	UR                  5      UUR                  '   M(     [!        UR                  UR                  5       H  u  nn[!        UR                  UR                  5       H(  u  nnU R#                  UR%                  UU5      U5        M*     [!        UR                  UR                  5       H(  u  nnU R#                  UR%                  UU5      U5        M*     M     [!        UR                  UR                  5       HF  u  nnU R#                  UR%                  UR                  UR                  5      UR                  5        MH     [!        UR                  UR                  5       HF  u  nnU R#                  UR%                  UR                  UR                  5      UR                  5        MH     [!        UR                  UR                  5       HF  u  nnU R#                  UR%                  UR                  UR                  5      UR                  5        MH     [!        UR                  UR                  5       H  u  nnU R#                  UR%                  UR                  R                  UR                  R                  5      UR                  R                  5        U R#                  UR%                  UR                  R                  UR                  R                  5      UR                  R                  5        M     [!        UR&                  UR&                  5       HF  u  n n!U R#                  UR%                  U!R                  U!R                  5      U R                  5        MH     U(       a[  [!        UR                  UR                  5       H6  u  nnU R#                  [        U	UR                  5      UR                  5        M8     g g g )Nzpre/T)r   r   r   r   r   r   r   )r   r   r   r   r   r   )r   rw   r
   CopyFromr   
add_prefixrS   rh   rf   r!   rg   r,   initializersparse_initializervaluesindiceszipre   getr"   )"rV   r   r   r   r   r   r   r   rW   r   rX   g_ing_outname_mappingner   initsparse_initr"   n1n0e1e0i1i0o1o0init1init0sparse_init1sparse_init0vi1vi0s"                                     r   _test_add_prefix%TestComposeFunctions._test_add_prefix  s     BKKO))+-$7#5
 ##))+-$7#5	B xx "!L AWW*3F*> %XX*3F*> & #
  JJD.7		.JL+ ' KKD.7		.JL+ ( # ,,D.7		.JL+ -#'#:#:K<E 2 2 7 7=L!3!3!8!89 >G 3 3 8 8>L!4!4!9!9:	 $; ""&++J4=fjoo4VL1 #. ejj$))4B!"((BHH5FB$$\%5%5b"%=rB 6!"))RYY7FB$$\%5%5b"%=rB 8 5
 ekk4::6B  !1!1"''277!CRWWM 7ellDKK8B  !1!1"''277!CRWWM 9 !$E$5$5t7G7G Hu  !1!1%**ejj!I5::V !I /2(($*A*A/*l    $$$++00,2E2E2J2J !'',,	    $$$,,11<3G3G3L3L !((--	/    0 0$//BS  !1!1#((CHH!EsxxP C !%**dii8FB$$Yvrww%?I 9 C "r   c                 "    U R                  SS9  g)z
Tests renaming nodes only
T)r   Nr  rV   s    r   test_add_prefix_nodes*TestComposeFunctions.test_add_prefix_nodes       	40r   c                 "    U R                  SS9  g)z_
Tests prefixing nodes edges. This will also rename inputs/outputs, since the names are shared
T)r   Nr  r  s    r   test_add_prefix_edges*TestComposeFunctions.test_add_prefix_edges  r  r   c                 "    U R                  SS9  g)zR
Tests prefixing graph inputs only. Relevant node edges should be renamed as well
T)r   Nr  r  s    r   test_add_prefix_inputs+TestComposeFunctions.test_add_prefix_inputs  s     	D1r   c                 "    U R                  SS9  g)zS
Tests prefixing graph outputs only. Relevant node edges should be renamed as well
T)r   Nr  r  s    r   test_add_prefix_outputs,TestComposeFunctions.test_add_prefix_outputs"  s     	T2r   c                    [         R                  " S[        R                  S/5      n[         R                  " S[        R                  SS/5      n[         R                  " S[        R                  SS/5      n[         R                  " S[        R                  SS/5      n[         R                  " S[        R                  SS/5      n[         R
                  " SSS/S	/S
9n[         R
                  " SS	S/S/S
9n[         R
                  " SS	S/S/S
9n[         R
                  " SS/S/[         R                  " U/S/ U/S9[         R                  " U/S/ U/S9S9n	[         R                  " Xi/SXX4/U/S9n
Sn[        R                  " X5      n[        R                  " U5        [        UR                  U
R                  5       GH<  u  pU R                  [        XR                  5      UR                  5        [        UR                   UR                   5       H  u  nnUR"                  (       d  M  [        UR"                  R                  UR"                  R                  5       H  u  nn[        UR$                  UR$                  5       H"  u  nnU R                  [        UU5      U5        M$     [        UR&                  UR&                  5       H"  u  nnU R                  [        UU5      U5        M$     M     M     GM?     g)zS
Tests prefixing attribute's subgraph. Relevant subgraph should be renamed as well
r      XNYZOutrd   XYr   rb   rc   Ifthen)nodesr,   rM   rN   else)rM   rN   then_branchelse_branchrS   zprefix.)r   make_tensor_value_infor   BOOLr8   	make_node
make_graphr   add_prefix_graphr   rT   r   rh   re   r!   r,   	attributegrf   rg   )rV   r   r  r  r  r  r  addsubcondrS   r   prefixed_graphr   r   
attribute1
attribute0subgraph_n1subgraph_n0input_n1input_n0	output_n1	output_n0s                          r   "test_add_prefix_attribute_subgraph7TestComposeFunctions.test_add_prefix_attribute_subgraph(  s    ))#{/?/?!E))#{/@/@4)L))#{/@/@4)L))#{/@/@4)L++E;3D3DtQiPeS#JGudC[5'JudC[5'J5G))e&cU ))e&cU

 !!*7A!<#
  11%@N+.--uzz:FBYvww7A*-bllBLL*I&
J<<<47")):<<+<+<50[ 36'--{/@/@3.Hh !,,Yvx-H(S3 58'..0B0B50Iy !,,Yvy-I9U55 +J ;r   c                 0    U R                  SSSSSS5        g)z(
Tests prefixing all names in the graph
TNr  r  s    r   test_add_prefix_all(TestComposeFunctions.test_add_prefix_allW  s     	dD$dDAr   c                 "    U R                  SS9  g)z
Tests prefixing inplace
Tr   Nr  r  s    r   test_add_prefix_inplace,TestComposeFunctions.test_add_prefix_inplace]  s     	d+r   c                 "  ^  [        [        5      nS[        S[        S[        SS4U 4S jjnS H"  n[        R
                  " X5      nU" XU5        M$     [        5       nUR                  U5        Sn[        R
                  " XCS	S
9  U" XU5        g)z
Tests expanding output dimensions. The resulting graph should have the same output names,
but with one more dimension at the specified index.
rW   rX   dim_idxr   Nc                   > [        UR                  R                  U R                  R                  5       H  u  p4TR                  UR                  UR                  5        TR                  UR
                  R                  R                  UR
                  R                  R                  5        [        U5      nUR                  US5        TR                  [        U5      U5        M     g )Nr  )
r   rS   rg   re   r,   r%   r&   	elem_typer+   insert)rW   rX   r<  out_g2out_g1expected_out_shaperV   s         r   _check_model>TestComposeFunctions.test_expand_out_dim.<locals>._check_modelj  s    "%bhhoorxx"G  fkk:  KK++55v{{7N7N7X7X &0%7""))'15  F!35GH #Hr   )r   r/   r   Tr8  )r   rw   r
   intr   expand_out_dimr   )rV   rW   rC  r<  rX   s   `    r   test_expand_out_dim(TestComposeFunctions.test_expand_out_dimc  s    
  	IZ 	IZ 	I# 	I$ 	I &G''4B) &
 \
BrD9RW%r   inputs0inputs1outputs0outputs1value_info0value_info1initializer0initializer1sparse_initializer0sparse_initializer1c                    [        [        U5      5       Vs/ s H  n[        R                  " SX   /X;   /S9PM!     nn[        [        U5      5       Vs/ s H+  n[        R                  " X   [
        R                  / 5      PM-     nn[        [        U5      5       Vs/ s H+  n[        R                  " X;   [
        R                  / 5      PM-     nn[        [        U5      5       Vs/ s H+  n[        R                  " X[   [
        R                  / 5      PM-     nn[        [        U5      5       Vs/ s H+  n[        R                  " X{   [
        R                  SS/S9PM-     nn[        [        U	5      5       Vs/ s H  n[        X   5      PM     nn[        [        U5      5       Vs/ s H  n[        R                  " SX+   /XK   /S9PM!     nn[        [        U5      5       Vs/ s H+  n[        R                  " X+   [
        R                  / 5      PM-     nn[        [        U5      5       Vs/ s H+  n[        R                  " XK   [
        R                  / 5      PM-     nn[        [        U5      5       Vs/ s H+  n[        R                  " Xk   [
        R                  / 5      PM-     nn[        [        U5      5       Vs/ s H+  n[        R                  " X   [
        R                  SS/S9PM-     nn[        [        U
5      5       Vs/ s H  n[        X   5      PM     nn[        R                  " SS5      /n[        R                  " [        R                  " USUUUUUS	9S
US9n[        R                  " [        R                  " USUUUUUS	9S
US9n[        R                  " UR                  UR                  5      nSn[!        [#        U5      [#        U5      -  5      n[!        [#        U5      [#        U5      -  5      n[!        [#        UU-   5      5      nU(       a  U R%                  UU   SU45        US-  n[!        [#        U5      [#        U5      -  5      nU(       a  U R%                  UU   SU45        US-  n[!        [#        U5      [#        U5      -  5      n U (       a  U R%                  UU   SU 45        US-  n[!        [#        U	5      [#        U
5      -  5      n!U!(       aO  / n"U! H+  n#U"R'                  U#S-   5        U"R'                  U#S-   5        M-     U R%                  UU   SU"45        US-  n[        R(                  " USS9n$[        R                  " U$R                  UR                  5      nU R%                  S[        U5      5        g s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf )NIdentityr    r  r,   r2   r3   r4   r   r   g0)r  r,   rM   rN   r"   r   r   r   r   r^   r   edger"   r   r1   r6   r   zg0/)r   )r$   r    r   r!  r  r   r8   r7   r=   rE   r   r   r"  r   check_overlapping_namesrS   listsetre   appendr   )%rV   rK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  ir   r   r   r   r   r   r   r   r   r   r   r   opsm0rW   overlapoverlapping_inputsoverlapping_outputsoverlapping_edgesoverlapping_visoverlapping_initoverlapping_sparse_initexpected_overlapoverlapping_namem0_news%                                        r   _test_overlapping_names,TestComposeFunctions._test_overlapping_names  s    3w<(
( Zx{mT( 	 
 3w<(
( ))'*k6G6GL( 	 
 3x=)
) ))(+{7H7H"M) 	 
 3{+,
, ))+.+:K:KRP, 	 
 3|,-	
 . !_0A0ARSQT .	 	 
 3234
4   3 674 	 
 3w<(
( Zx{mT( 	 
 3w<(
( ))'*k6G6GL( 	 
 3x=)
) ))(+{7H7H"M) 	 
 3{+,
, ))+.+:K:KRP, 	 
 3|,-	
 . !_0A0ARSQT .	 	 
 3234
4   3 674 	 

 ""2r*+!#/ !
 !#/ !
 11"((BHHE!#g,W"=>"3x=3x=#@A %7:M%M!NOWQZ&2C)DEFAs;/#k2BBCWQZ,)HIFAL 1C4E EFWQZ-9I)JKFA"&#$s+>'??#
 #!$;  ''(89(DE ''(86(AB %< WQZ*>@P)QRFA##Bu511&,,ICL)i












sG   &V2V#2V()2V-32V2=V7,&V<*2W42W>2W2WWc                 ,    U R                  SS/SS/S9  g)z;
Tests error checking when the name of the inputs overlaps
r   r   i2)rK  rL  Nrl  r  s    r   test_overlapping_input_names1TestComposeFunctions.test_overlapping_input_names  s     	$$dD\D$<$Pr   c                 ,    U R                  SS/SS/S9  g)z;
Tests error checking when the name of the output overlaps
r   r   o2)rM  rN  Nrp  r  s    r   test_overlapping_output_names2TestComposeFunctions.test_overlapping_output_names  s     	$$tTldD\$Rr   c                 ,    U R                  SS/SS/S9  g)zC
Tests error checking when the name of value_info entries overlaps
r   r   vi2)rO  rP  Nrp  r  s    r   !test_overlapping_value_info_names6TestComposeFunctions.test_overlapping_value_info_names  s$     	$$UEN 	% 	
r   c                 ,    U R                  SS/SS/S9  g)zD
Tests error checking when the name of initializer entries overlaps
r   r   init2)rQ  rR  Nrp  r  s    r   "test_overlapping_initializer_names7TestComposeFunctions.test_overlapping_initializer_names  s&     	$$!7+7G:L 	% 	
r   c                 ,    U R                  SS/SS/S9  g)zK
Tests error checking when the name of sparse_initializer entries overlaps
r   r   sparse_init2)rS  rT  Nrp  r  s    r   )test_overlapping_sparse_initializer_names>TestComposeFunctions.test_overlapping_sparse_initializer_names  s'     	$$!/ @!/ @ 	% 	
r   c                 $  ^ [         R                  " SS5      [         R                  " SS5      /mS[        S[        S[        [           S[        [           S[        [           S	[
        4U4S
 jjn[         R                  " SS5      [         R                  " SS5      /m[        5       nUR                  R                  [         R                  " S[        R                  / 5      [         R                  " S[        R                  / 5      /5        UR                  R                  [         R                  " S[        R                  / 5      /5        UR                  R                  [         R                  " SSSS/S/S9/5        [        5       nUR                  U5        SUl        [         R"                  " USTS9nUR$                  R                  U" SSSS/S/[         R                  " SSS/S/S9/5      /5        [&        R(                  " U5        [        5       nUR                  U5        SUl        [         R"                  " USTS9nUR$                  R                  U" SSSS/S/[         R                  " SSS/S/S9/5      /5        [&        R(                  " U5        [*        R,                  " XFSS/SSS9n[&        R(                  " U5        UR.                  R                   Vs/ s H  oR0                  PM     n	nU R3                  SS/U	5        UR$                   V
s/ s H  oR                   PM     nn
U R3                  SS/U5        [        5       nUR                  U5        SUl        SUR                  S    l        [         R"                  " USTS9nUR$                  R                  U" SSSS/S/[         R                  " SSS/S!/S9[         R                  " SSS/S"/S9[         R                  " SS!S"/S/S9/5      U" SSSS/S/[         R                  " SSSS/S!/S9[         R                  " SSS/S"/S9[         R                  " SS!S"/S/S9/5      /5        [&        R(                  " U5        [*        R,                  " XMSS/SS#S9n[&        R(                  " U5        UR.                  R                   Vs/ s H  oR0                  PM     n	nU R3                  SS$/U	5        UR$                   V
s/ s H  oR                   PM     nn
U R3                  / S%QU5        U R3                  S/UR$                  S    R                   Vs/ s H  oR0                  PM     sn5        U R3                  / S&QUR$                  S'   R                   Vs/ s H  oR0                  PM     sn5        U R3                  / S(QUR$                  S)   R                   Vs/ s H  oR0                  PM     sn5        g*s  snf s  sn
f s  snf s  sn
f s  snf s  snf s  snf )+zG
Tests error checking when the name of local function entries overlaps
r   r   localdomainfnamerM   rN   r  r   c                   > [        5       nXl        Xl        UR                  R	                  U5        UR
                  R	                  U5        UR                  R	                  U5        UR                  R	                  T5        U$ )N)r   r  r,   rf   extendrg   rh   opset_import)r  r  rM   rN   r  fr`  s         r   _make_functionLTestComposeFunctions.test_overlapping_function_names.<locals>._make_function-  s]     AHFGGNN6"HHOOG$FFMM% NN!!#&Hr   x0x1yf1)r  rM   rN   r^   r   r   rb   r   r_   rd   )r  r  )r  r  r   r   )rK   rO   rP   m1/f1zm2/f1rY   f2r   y0y1zm3/m3/f2)r  m3/f1r  )rb   rd   rb   r  )r  rd   rb   r/   N)r   r   strr   r   r   r	   rf   r  r  r   r8   rg   rh   r!  r   r,   r   	functionsr   r   r   rU   rS   ri   re   )rV   r  r%  r^   rW   r_   rX   r   r   r  r  r  rY   rZ   r`  s                 @r   test_overlapping_function_names4TestComposeFunctions.test_overlapping_function_names'  sr    ""2r*F,?,?,LM			 I	 #Y		
 	?	 	  ""2r*F,?,?,LML	--dK4E4ErJ--dK4E4ErJ	
 	
--c;3D3DbI	

 	
d7D$<RUQVWX	
 \
ArsK
4LE%%eT4L3%PQ
	
 	B\
ArsK
4LE%%eT4L3%PQ
	
 	B  K5ue
 	A$%GGLL1LqL1'7+U3%&[[1[VV[	1'7+Y7\
A!
rsK
4LE((d|dVT((d|dVT((d|cUS
 4LE(( $PTv ((d|dVT((d|cUS	
8 	B  K5ue
 	A$%GGLL1LqL1'7+U3%&[[1[VV[	14i@%akk!n6I6I"J6I996I"JK!q{{1~7J7J#K7J!II7J#K	
 	#Q9L9L%M9LAii9L%M	
q 2 2V 2 2 #K#K &Ns*   'W/ W4<W95W>X
X
X
c           	      
   [         R                  " SS5      /n[        5       nUR                  R	                  [         R
                  " S[        R                  / 5      /5        UR                  R	                  [         R
                  " S[        R                  / 5      /5        UR                  R	                  [         R                  " SS/S/S9/5        [        5       nUR                  U5        SUl        [         R                  " USUS	9n[        R                  " U5        [        5       nUR                  U5        S
Ul        UR                   R	                  [         R"                  " S[        R                  SS/S9/5        [         R                  " USUS	9n[        R                  " U5        [        5       nUR                  U5        SUl        UR$                  R	                  ['        S5      /5        [         R                  " USUS	9n[        R                  " U5        [        5       n	U	R                  U5        SU	l        U	R(                  R	                  [         R
                  " S[        R                  / 5      /5        [         R                  " U	SUS	9n
[        R                  " U
5        [*        R,                  " XFSS/S9nU R/                  S[1        UR2                  R                   5      5        [*        R,                  " XHSS/S9nU R/                  S[1        UR2                  R                   5      5        [*        R,                  " XJSS/S9nU R/                  S[1        UR2                  R(                  5      5        g)z=
Tests automatic removal of initializers when merging graphs
r   r   xr  rV  r   r^   r   r   r_   rW  r   rX  rY   r   )r  r  )rO   rK   N)r   r   r	   rf   r  r  r   r8   rg   rh   r!  r   r,   r   r   r   r   r7   r   rE   r"   r   rU   re   r    rS   )rV   r`  r%  r^   rW   r_   rX   rY   rZ   r   m4out_m1out_m2out_m3s                 r   7test_merge_drop_unnecessary_initializers_and_value_infoLTestComposeFunctions.test_merge_drop_unnecessary_initializers_and_value_info  s    ""2r*+L	55c;;L;LbQRS	66sK<M<MrRST	v''
C53%PQR\
ArsKB\
A
""(9(9!	
 rsKB\
A
$$&9#&>%?@rsKB\
A
**30A0A2FG	
 rsKB %%beZLQC 8 89: %%beZLQC 8 89: %%beZLQC 7 789r   rW  )NNNN)r   N)FFFFFFF)
)r   r   )ro  i3)r   r   )rt  o3)v0r   )r   r   )r   r   )r|  init3)r   r   )r  sparse_init3)*__name__
__module____qualname____firstlineno__r  r   r   r   r	   r   r[   rz   r   r   r   r   r   r   r   r   r   r   boolr  r  r
  r  r  r2  r5  r9  rI  r   rl  rq  ru  ry  r}  r  r  r  __static_attributes__rW  r   r   rG   rG   e   sy    '+'+!%!%!9!9 !9 U38_%	!9
 %j*j%I4%OP!9 c#!9 $s)$!9 #!9 #!9 
!9FL"L$
("LH(
T
:L(S(
.
> * #"#$$)#(rJrJ rJ 	rJ
 rJ "rJ !rJ rJ 
rJh1123-V^B,&< ".!-".".%1%1&8&8-M-MA*#A* #A* 3-	A*
 3-A* c]A* c]A* smA* smA* &c]A* &c]A* 
A*FQS


I
V8:r   rG   __main__)"unittesttypingr   r   r   r   r   numpyr9   onnxr   r	   r
   r   r   r   r   r   r   r   r   r   r  r   r!   rG  r+   rE   rw   rx   TestCaserG   r  mainrW  r   r   <module>r     s   
  < <     s z +c +c +c +> d3i Qc Q&7 Q,

E:8,, E:P zMMO r   