
    h(                         S SK r \ R                  " S5      r\ R                  " S5      rS SKrS SKJrJrJ	r	  S SK
Jr   " S S5      r\ R                  R                  SS	5      S
 5       rg)    Nnumpyscipy)barbell_graphcycle_graph
path_graph)graphs_equalc                       \ 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                    [        SS5      U l        [        S[        R                  S9U l        U R                  [        R                  " 5       5      U l        U R                  [        R                  " 5       5      U l	        g )N
      create_using)
r   G1r   nxDiGraphG2create_weightedGraphG3G4selfs    S/var/www/html/env/lib/python3.13/site-packages/networkx/tests/test_convert_scipy.pysetup_methodTestConvertScipy.setup_method   sR    A&brzz:&&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                 *   [        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   listedgeszipadd_weighted_edges_from)r   r*   geuvsourcedestsweightexs              r   r    TestConvertScipy.create_weighted   s    N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   )r2         N)spsparse	lil_arrayr+   r,   r   r-   rB   r   rK   s     r   
test_shapeTestConvertScipy.test_shapeA   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   rT   r   r^   s     r   test_identity_graph_matrix+TestConvertScipy.test_identity_graph_matrixF   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   rb   r   rT   r   r^   s     r   test_identity_digraph_matrix-TestConvertScipy.test_identity_digraph_matrixK   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   rb   r   rT   r   r^   s     r   #test_identity_weighted_graph_matrix4TestConvertScipy.test_identity_weighted_graph_matrixP   re   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   rb   r   rT   r   r^   s     r   %test_identity_weighted_digraph_matrix6TestConvertScipy.test_identity_weighted_digraph_matrixU   ri   r   c                 2   [        S5      n[        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.r2   r   nodelistr   )r   rW   rX   N)
r   r3   nodesr   rb   r   rC   r+   r,   r-   )r   P4P3rr   rK   GAlong_nlnon_nls           r   test_nodelistTestConvertScipy.test_nodelistZ   s    ]]
#$$R;XXa[''''b&&(@(@"rRaS.b&&(@(@"W b&&(@(@"Vr   c                    [         R                  " 5       nUR                  S [        S5       5       5        [	        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rW         ?333333?)r>   otherNr#   .0ns     r   	<genexpr>7TestConvertScipy.test_weight_keyword.<locals>.<genexpr>n        Whq1us&CDh   r   r2   r>   r   r   r   
r   r   add_edges_fromranger   rb   nptestingassert_equalrI   r   WP4ru   rK   s       r   test_weight_keyword$TestConvertScipy.test_weight_keywordl   s    hhjWeTUhWW]$$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        [	        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   r2   csrr(   r   csccoobsrlildiadokr   r   s       r   test_format_keyword$TestConvertScipy.test_format_keyword{   s   hhjWeTUhWW]$$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                 ,   [         R                  " [        R                  5         [        R                  " 5       nUR                  S [        S5       5       5        [        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   r2   	any_otherr   )	r+   r,   r   r-   r   r   r   r   rb   )r   r   ru   s      r   test_format_keyword_raise*TestConvertScipy.test_format_keyword_raise   se    ]]2++,((*C CH8  A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-   rb   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 )NrW   r   )	r   r   add_noderb   r   r   r   rJ   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 )	NrW   rX   r   )r   rX   rW   rq   r   r   rW   )rW   r   r   r   rW   r   )	r   r   add_edgerb   r   r   r   rJ   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rW   rW   rW   rX   r   r   r2   rX   r   r2   rq   r   )rW   r   rW   )	r   r   rb   r   r   r   rJ   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   rW   r   r   r   rq   r   r   )r   r   r   )	r   r   rb   r   r   r   rJ   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.

rW   rX   )r   r   r   rW   rW   r   r   T)parallel_edgesr   F)r   r   r   r   r   r   r>   N)r[   r\   	csr_arrayr   r   r6   r   rB   r   MultiDiGraphr   set)r   rK   expectedr4   r9   r:   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   rW   r   r   N)r[   r\   r   r   rB   
MultiGraphr   r   )r   rK   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   rT   r_   rc   rg   rk   rn   rz   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   rW   r>   r   rX   )r   r   rX   )r   r   rW   )rX   rW   r   N)	r   r   r   r[   r\   	coo_arrayasformatr   rB   )r   r   rK   s      r   $test_from_scipy_sparse_array_formatsr   
  s     xxzHHa=!Ha=!Ha=!Ha=!Ha=!Ha=!	
	 			Y	9=>GGVA""<"<Q"?@@@@r   )r+   importorskipr   r[   networkxr   networkx.generators.classicr   r   r   networkx.utilsr   r
   markparametrizer   r#   r   r   <module>r      sj    !!  N N '|) |)~ *?@A AAr   