
    9i(                         S SK r S SKrS SKJr  \ R
                  " S5      r\ R
                  " S5      r " S S5      r\ R                  R                  SS5      S	 5       rg)
    N)graphs_equalnumpyscipyc                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rSrg)TestConvertScipy
   c                 0   [         R                  " SS5      U l        [         R                  " S[         R                  S9U l        U R                  [         R                  " 5       5      U l        U R                  [         R                  " 5       5      U l	        g )Nr      create_using)
nxbarbell_graphG1cycle_graphDiGraphG2create_weightedGraphG3G4selfs    a/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/networkx/tests/test_convert_scipy.pysetup_methodTestConvertScipy.setup_method   s\    ""2q).."**=&&rxxz2&&rzz|4    c                      " S S5      n[         R                  " [        R                  [        R                  U5        g )Nc                       \ rS rSrSrSrg)+TestConvertScipy.test_exceptions.<locals>.G   N )__name__
__module____qualname____firstlineno__format__static_attributes__r!   r   r   Gr      s    Fr   r(   )pytestraisesr   NetworkXErrorto_networkx_graph)r   r(   s     r   test_exceptions TestConvertScipy.test_exceptions   s*    	 	 	b&&(<(<a@r   c                 @   [         R                  " S5      n[        UR                  5       5      nU VVs/ s H  u  pEUPM	     nnnU VVs/ s H  u  pEUPM	     nnnU Vs/ s H  oS-   PM	     n	n[	        XgU	5      n
UR                  U
5        U$ s  snnf s  snnf s  snf )N   r   )r   r   listedgeszipadd_weighted_edges_from)r   r(   geuvsourcedestsweightexs              r   r    TestConvertScipy.create_weighted   s    NN1O !"!" adaa "()&Qb&&)v&	!!"% # )s   BB Bc                    [         R                  " X#S9n[         R                  " X5      (       d   e[         R                  " X#S9n[         R                  " X5      (       d   e[         R                  " SU5      R                  U5      n[         R                  " X5      (       d   eUR                  5       n[         R                  " SU5      R                  U5      n[         R                  " X5      (       d   eUR                  5       n[         R                  " SU5      R                  U5      n[         R                  " X5      (       d   eUR                  5       n	[         R                  " SU5      R                  U	5      n[         R                  " X5      (       d   eUR                  5       n
[         R                  " SU5      R                  U
5      n[         R                  " X5      (       d   eUR                  5       n[         R                  " SU5      R                  U5      n[         R                  " X5      (       d   eg )Nr   r   )r   from_scipy_sparse_arrayis_isomorphicr,   empty_graph	__class__tocsrtocootocsctodensetoarray)r   r(   Ar   GGGWGIACSRACOOACSCADAAs               r   identity_conversion$TestConvertScipy.identity_conversion"   s   ''E&&&&!!!?&&&&^^A|,66q9&&&&wwy^^A|,66t<&&&&wwy^^A|,66t<&&&&wwy^^A|,66t<&&&&YY[^^A|,66r:&&&&YY[^^A|,66r:&&&&r   c                     [         R                  R                  / SQ/ SQ/5      n[        R                  " [
        R                  [
        R                  U5        g)z(Conversion from non-square sparse array.)      r
   )r0         N)spsparse	lil_arrayr)   r*   r   r+   r@   r   rI   s     r   
test_shapeTestConvertScipy.test_shape@   s7    III 67b&&(B(BAFr   c                     [         R                  " U R                  5      nU R                  U R                  U[         R                  " 5       5        g)z0Conversion from graph to sparse matrix to graph.N)r   to_scipy_sparse_arrayr   rR   r   r\   s     r   test_identity_graph_matrix+TestConvertScipy.test_identity_graph_matrixE   2    $$TWW-  !RXXZ8r   c                     [         R                  " U R                  5      nU R                  U R                  U[         R                  " 5       5        g)z4Conversion from digraph to sparse matrix to digraph.N)r   r`   r   rR   r   r\   s     r   test_identity_digraph_matrix-TestConvertScipy.test_identity_digraph_matrixJ   2    $$TWW-  !RZZ\:r   c                     [         R                  " U R                  5      nU R                  U R                  U[         R                  " 5       5        g)zBConversion from weighted graph to sparse matrix to weighted graph.N)r   r`   r   rR   r   r\   s     r   #test_identity_weighted_graph_matrix4TestConvertScipy.test_identity_weighted_graph_matrixO   rc   r   c                     [         R                  " U R                  5      nU R                  U R                  U[         R                  " 5       5        g)zFConversion from weighted digraph to sparse matrix to weighted digraph.N)r   r`   r   rR   r   r\   s     r   %test_identity_weighted_digraph_matrix6TestConvertScipy.test_identity_weighted_digraph_matrixT   rg   r   c                 ^   [         R                  " S5      n[         R                  " S5      n[        UR                  5       5      n[         R                  " XS9n[         R
                  " U5      n[         R                  " XR5      (       d   e[        R                  " [         R                  [         R                  U/ S9  US/-   n[        R                  " [         R                  [         R                  X&S9  / SQn[        R                  " [         R                  [         R                  X'S9  g)z>Conversion from graph to sparse matrix to graph with nodelist.r0   r
   nodelistr   )r   rU   rV   N)
r   
path_graphr1   nodesr`   r   rA   r)   r*   r+   )r   P4P3rp   rI   GAlong_nlnon_nls           r   test_nodelistTestConvertScipy.test_nodelistY   s    ]]1]]1
#$$R;XXa[''''b&&(@(@"rRaS.b&&(@(@"W b&&(@(@"Vr   c                    [         R                  " 5       nUR                  S [        S5       5       5        [         R                  " S5      n[         R
                  " U5      n[        R                  R                  UR                  5       [         R
                  " US S9R                  5       5        [        R                  R                  SUR                  5       -  [         R
                  " U5      R                  5       5        [        R                  R                  SUR                  5       -  [         R
                  " USS9R                  5       5        g )Nc              3   6   #    U  H  oUS -   SSS.4v   M     g7frU         ?333333?)r<   otherNr!   .0ns     r   	<genexpr>7TestConvertScipy.test_weight_keyword.<locals>.<genexpr>m        Whq1us&CDh   r
   r0   r<   r~   r   r   
r   r   add_edges_fromrangerr   r`   nptestingassert_equalrG   r   WP4rt   rI   s       r   test_weight_keyword$TestConvertScipy.test_weight_keywordk   s    hhjWeTUhWW]]1$$R(


IIK11#dCKKM	
 	

!))+r77<DDF	
 	

!))+r77GLTTV	
r   c                    [         R                  " 5       nUR                  S [        S5       5       5        [         R                  " S5      n[         R
                  " USS9n[        R                  R                  UR                  5       [         R
                  " US S9R                  5       5        [         R
                  " USS9n[        R                  R                  UR                  5       [         R
                  " US S9R                  5       5        [         R
                  " USS9n[        R                  R                  UR                  5       [         R
                  " US S9R                  5       5        [         R
                  " US	S9n[        R                  R                  UR                  5       [         R
                  " US S9R                  5       5        [         R
                  " US
S9n[        R                  R                  UR                  5       [         R
                  " US S9R                  5       5        [         R
                  " USS9n[        R                  R                  UR                  5       [         R
                  " US S9R                  5       5        [         R
                  " USS9n[        R                  R                  UR                  5       [         R
                  " US S9R                  5       5        g )Nc              3   6   #    U  H  oUS -   SSS.4v   M     g7fr}   r!   r   s     r   r   7TestConvertScipy.test_format_keyword.<locals>.<genexpr>|   r   r   r
   r0   csrr&   r   csccoobsrlildiadokr   r   s       r   test_format_keyword$TestConvertScipy.test_format_keywordz   s#   hhjWeTUhWW]]1$$R6


IIK11#dCKKM	
 $$R6


IIK11#dCKKM	
 $$R6


IIK11#dCKKM	
 $$R6


IIK11#dCKKM	
 $$R6


IIK11#dCKKM	
 $$R6


IIK11#dCKKM	
 $$R6


IIK11#dCKKM	
r   c                 B   [         R                  " [        R                  5         [        R                  " 5       nUR                  S [        S5       5       5        [        R                  " S5      n[        R                  " USS9  S S S 5        g ! , (       d  f       g = f)Nc              3   6   #    U  H  oUS -   SSS.4v   M     g7fr}   r!   r   s     r   r   =TestConvertScipy.test_format_keyword_raise.<locals>.<genexpr>   s!      CKaAEcC898r   r
   r0   	any_otherr   )	r)   r*   r   r+   r   r   r   rr   r`   )r   r   rt   s      r   test_format_keyword_raise*TestConvertScipy.test_format_keyword_raise   sj    ]]2++,((*C CH8  q!B$$R< -,,s   A"B
Bc                     [         R                  " [        R                  5         [        R                  " [        R
                  " 5       5        S S S 5        g ! , (       d  f       g = f)N)r)   r*   r   r+   r`   r   r   s    r   test_null_raise TestConvertScipy.test_null_raise   s4    ]]2++,$$RXXZ0 -,,s   *A
A&c                    [         R                  " 5       nUR                  S5        [         R                  " U5      n[        R
                  R                  UR                  5       [        R                  S//5      5        g )NrU   r   )	r   r   add_noder`   r   r   r   rH   arrayr   r(   Ms      r   
test_emptyTestConvertScipy.test_empty   sN    HHJ	

1$$Q'


		RXXse_=r   c           	      \   [         R                  " 5       nUR                  SS5        UR                  SS5        UR                  SS5        [         R                  " U/ SQS9n[        R
                  R                  UR                  5       [        R                  / SQ/ SQ/ SQ/5      5        g )	NrU   rV   r
   )r
   rV   rU   ro   r   r   rU   )rU   r   r   r   rU   r   )	r   r   add_edger`   r   r   r   rH   r   r   s      r   test_orderingTestConvertScipy.test_ordering   sv    JJL	

1a	

1a	

1a$$Q;


IIK9i"CD	
r   c           	         [         R                  " S/5      n[         R                  " U5      n[        R                  R                  UR                  5       [        R                  S//5      5        UR                  SS/5        [         R                  " U/ SQS9n[        R                  R                  UR                  5       [        R                  / SQ/ SQ/ SQ/5      5        g )	NrU   rU   rU   rV   r
   r
   r0   rV   r
   r0   ro   r   )rU   r   rU   )	r   r   r`   r   r   r   rH   r   r   r   s      r   test_selfloop_graph$TestConvertScipy.test_selfloop_graph   s    HHfX$$Q'


		RXXse_=	&&)*$$Q;


IIK9i"CD	
r   c           	         [         R                  " S/5      n[         R                  " U5      n[        R                  R                  UR                  5       [        R                  S//5      5        UR                  SS/5        [         R                  " U/ SQS9n[        R                  R                  UR                  5       [        R                  / SQ/ SQ/ S	Q/5      5        g )
Nr   rU   r   r   r   ro   r   r   )r   r   r   )	r   r   r`   r   r   r   rH   r   r   r   s      r   test_selfloop_digraph&TestConvertScipy.test_selfloop_digraph   s    JJx $$Q'


		RXXse_=	&&)*$$Q;


IIK9i"CD	
r   c           	         [         R                  R                  SS/SS//5      n[        R                  " 5       n/ SQnUR                  U VVs/ s H	  u  pEXES4PM     snn5        UR                  SSSS9  [        R                  " US[        R                  S9n[        Xb5      (       d   e[        R                  " US[        R                  S9n[        Xb5      (       d   e/ SQn[        R                  " 5       nUR                  U VVs/ s H	  u  pEXES4PM     snn5        [        R                  " US[        R                  S9n[        Xb5      (       d   e[        R                  " 5       nUR                  [        U5      SS9  SUS   S   S	   S
'   [        R                  " US[        R                  S9n[        Xb5      (       d   egs  snnf s  snnf )zTests that the :func:`networkx.from_scipy_sparse_array` function
interprets integer weights as the number of parallel edges when
creating a multigraph.

rU   rV   )r   r   r   rU   rU   r   r   T)parallel_edgesr   F)r   r   r   r   r   r   r<   N)rY   rZ   	csr_arrayr   r   r4   r   r@   r   MultiDiGraphr   set)r   rI   expectedr2   r7   r8   actuals          r   +test_from_scipy_sparse_array_parallel_edges<TestConvertScipy.test_from_scipy_sparse_array_parallel_edges   s    II!Q!Q 01 ::<(((%)H%1)%)HI!Qq)++d
 F----++e"**
 F---- 9??$((%)H%1)%)HI++d
 F----??$E
15&'Aq(#++e"//
 F----7 *I *Is   G
G
c                    [         R                  R                  SS/SS//5      n[        R                  " U[        R
                  S9n[        R
                  " 5       nUR                  SSSS9  [        X#5      (       d   eg)zTests that a symmetric matrix has edges added only once to an
undirected multigraph when using
:func:`networkx.from_scipy_sparse_array`.

r   rU   r   r   N)rY   rZ   r   r   r@   
MultiGraphr   r   )r   rI   r(   r   s       r   test_symmetricTestConvertScipy.test_symmetric   sl     II!Q!Q 01&&qr}}E==?!Qq)A((((r   )r   r   r   r   N)r"   r#   r$   r%   r   r-   r   rR   r]   ra   re   ri   rl   ry   r   r   r   r   r   r   r   r   r   r   r'   r!   r   r   r   r   
   sk    5A'<G
9
;
9
;
W$
%
N=1>
	
	
&.P
)r   r   sparse_format)r   r   r   c                 T   [         R                  " 5       nUR                  SSSS04SSSS04SSSS04SSSS04SSSS04SSSS04/5        [        R                  R                  / SQ/ SQ/ SQ/5      R                  U 5      n[        U[         R                  " U5      5      (       d   eg	)
z7Test all formats supported by _generate_weighted_edges.r   rU   r<   r
   rV   )r   r
   rV   )r
   r   rU   )rV   rU   r   N)	r   r   r   rY   rZ   	coo_arrayasformatr   r@   )r   r   rI   s      r   $test_from_scipy_sparse_array_formatsr   	  s     xxzHHa=!Ha=!Ha=!Ha=!Ha=!Ha=!	
	 			Y	9=>GGVA""<"<Q"?@@@@r   )r)   networkxr   networkx.utilsr   importorskipr   rY   r   markparametrizer   r!   r   r   <module>r      sd      '!!|) |)~ *?@A AAr   