
    \Mh(                         d dl Z d dlZd dlmZ  e j        d          Z e j        d          Z G d d          Ze j	        
                    dd          d	             ZdS )
    N)graphs_equalnumpyscipyc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TestConvertScipyc                 0   t          j        dd          | _        t          j        dt           j                  | _        |                     t          j                              | _        |                     t          j                              | _	        d S )N
      create_using)
nxbarbell_graphG1cycle_graphDiGraphG2create_weightedGraphG3G4selfs    a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/networkx/tests/test_convert_scipy.pysetup_methodzTestConvertScipy.setup_method   sh    "2q))."*===&&rxzz22&&rz||44    c                 t     G d d          }t          j        t          j        t          j        |           d S )Nc                       e Zd ZdZdS )+TestConvertScipy.test_exceptions.<locals>.GN)__name__
__module____qualname__format r   r   Gr      s        FFFr   r$   )pytestraisesr   NetworkXErrorto_networkx_graph)r   r$   s     r   test_exceptionsz TestConvertScipy.test_exceptions   sL    	 	 	 	 	 	 	 	 	b&(<a@@@@@r   c                    t          j        d          }t          |                                          }d |D             }d |D             }d |D             }t	          |||          }|                    |           |S )N   c                     g | ]\  }}|S r#   r#   .0uvs      r   
<listcomp>z4TestConvertScipy.create_weighted.<locals>.<listcomp>   s    """1!"""r   c                     g | ]\  }}|S r#   r#   r-   s      r   r1   z4TestConvertScipy.create_weighted.<locals>.<listcomp>   s       da   r   c                     g | ]}|d z   S )r	   r#   )r.   ss     r   r1   z4TestConvertScipy.create_weighted.<locals>.<listcomp>   s    )))Q!b&)))r   )r   r   listedgeszipadd_weighted_edges_from)r   r$   gesourcedestweightexs           r   r   z TestConvertScipy.create_weighted   s    N1OO"""""  a   ))&)))v&&	!!"%%%r   c                 v   t          j        ||          }t          j        ||          sJ t          j        ||          }t          j        ||          sJ t          j        d|                              |          }t          j        ||          sJ |                                }t          j        d|                              |          }t          j        ||          sJ |                                }t          j        d|                              |          }t          j        ||          sJ |                                }	t          j        d|                              |	          }t          j        ||          sJ |	                                }
t          j        d|                              |
          }t          j        ||          sJ |
                                }t          j        d|                              |          }t          j        ||          sJ d S )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_conversionz$TestConvertScipy.identity_conversion"   s   'EEE2&&&&&!!,???2&&&&&^A|,,66q992&&&&&wwyy^A|,,66t<<2&&&&&wwyy^A|,,66t<<2&&&&&wwyy^A|,,66t<<2&&&&&YY[[^A|,,66r::2&&&&&YY[[^A|,,66r::2&&&&&&&r   c                     t           j                            g dg dg          }t          j        t
          j        t
          j        |           dS )z(Conversion from non-square sparse array.)      r
   )r+         N)spsparse	lil_arrayr%   r&   r   r'   r@   r   rI   s     r   
test_shapezTestConvertScipy.test_shape@   sD    IIII 677b&(BAFFFFFr   c                     t          j        | j                  }|                     | j        |t          j                               dS )z0Conversion from graph to sparse matrix to graph.N)r   to_scipy_sparse_arrayr   rR   r   r[   s     r   test_identity_graph_matrixz+TestConvertScipy.test_identity_graph_matrixE   :    $TW--  !RXZZ88888r   c                     t          j        | j                  }|                     | j        |t          j                               dS )z4Conversion from digraph to sparse matrix to digraph.N)r   r^   r   rR   r   r[   s     r   test_identity_digraph_matrixz-TestConvertScipy.test_identity_digraph_matrixJ   :    $TW--  !RZ\\:::::r   c                     t          j        | j                  }|                     | j        |t          j                               dS )zBConversion from weighted graph to sparse matrix to weighted graph.N)r   r^   r   rR   r   r[   s     r   #test_identity_weighted_graph_matrixz4TestConvertScipy.test_identity_weighted_graph_matrixO   r`   r   c                     t          j        | j                  }|                     | j        |t          j                               dS )zFConversion from weighted digraph to sparse matrix to weighted digraph.N)r   r^   r   rR   r   r[   s     r   %test_identity_weighted_digraph_matrixz6TestConvertScipy.test_identity_weighted_digraph_matrixT   rc   r   c                 6   t          j        d          }t          j        d          }t          |                                          }t          j        ||          }t          j        |          }t          j        ||          sJ t          j        t           j	        t           j        |g            |dgz   }t          j        t           j	        t           j        ||           g d}t          j        t           j	        t           j        ||           dS )z>Conversion from graph to sparse matrix to graph with nodelist.r+   r
   nodelistr   )r   rT   rU   N)
r   
path_graphr5   nodesr^   r   rA   r%   r&   r'   )r   P4P3rj   rI   GAlong_nlnon_nls           r   test_nodelistzTestConvertScipy.test_nodelistY   s    ]1]1

##$R(;;;Xa[[B'''''b&(@"rRRRRaS.b&(@"wWWWW b&(@"vVVVVVVr   c                    t          j                    }|                    d t          d          D                        t          j        d          }t          j        |          }t          j                            |	                                t          j        |d           	                                           t          j                            d|	                                z  t          j        |          	                                           t          j                            d|	                                z  t          j        |d          	                                           d S )Nc              3   ,   K   | ]}||d z   dddfV  dS rT         ?333333?)r=   otherNr#   r.   ns     r   	<genexpr>z7TestConvertScipy.test_weight_keyword.<locals>.<genexpr>m   5      WWAq1us&C&CDWWWWWWr   r
   r+   r=   rw   rx   ry   
r   r   add_edges_fromrangerl   r^   nptestingassert_equalrG   r   WP4rn   rI   s       r   test_weight_keywordz$TestConvertScipy.test_weight_keywordk   s2   hjjWWeTUhhWWWWWW]1$R((

IIKK1#dCCCKKMM	
 	
 	
 	
!))++r7<<DDFF	
 	
 	
 	
!))++r7GLLLTTVV	
 	
 	
 	
 	
r   c                    t          j                    }|                    d t          d          D                        t          j        d          }t          j        |d          }t          j                            |	                                t          j        |d           	                                           t          j        |d          }t          j                            |	                                t          j        |d           	                                           t          j        |d          }t          j                            |	                                t          j        |d           	                                           t          j        |d	          }t          j                            |	                                t          j        |d           	                                           t          j        |d
          }t          j                            |	                                t          j        |d           	                                           t          j        |d          }t          j                            |	                                t          j        |d           	                                           t          j        |d          }t          j                            |	                                t          j        |d           	                                           d S )Nc              3   ,   K   | ]}||d z   dddfV  dS rv   r#   rz   s     r   r|   z7TestConvertScipy.test_format_keyword.<locals>.<genexpr>|   r}   r   r
   r+   csrr"   r~   csccoobsrlildiadokr   r   s       r   test_format_keywordz$TestConvertScipy.test_format_keywordz   s   hjjWWeTUhhWWWWWW]1$R666

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

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

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

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

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

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

IIKK1#dCCCKKMM	
 	
 	
 	
 	
r   c                 F   t          j        t          j                  5  t          j                    }|                    d t          d          D                        t          j        d          }t          j        |d           d d d            d S # 1 swxY w Y   d S )Nc              3   ,   K   | ]}||d z   dddfV  dS rv   r#   rz   s     r   r|   z=TestConvertScipy.test_format_keyword_raise.<locals>.<genexpr>   sF        >?AEcC889     r   r
   r+   	any_otherr   )	r%   r&   r   r'   r   r   r   rl   r^   )r   r   rn   s      r   test_format_keyword_raisez*TestConvertScipy.test_format_keyword_raise   s    ]2+,, 	= 	=(**C  CH88      q!!B$R<<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s   A*BBBc                     t          j        t          j                  5  t          j        t          j                               d d d            d S # 1 swxY w Y   d S )N)r%   r&   r   r'   r^   r   r   s    r   test_null_raisez TestConvertScipy.test_null_raise   s    ]2+,, 	1 	1$RXZZ000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   &AAAc                    t          j                    }|                    d           t          j        |          }t          j                            |                                t                              dgg                     d S )NrT   r   )	r   r   add_noder^   r   r   r   rH   arrayr   r$   Ms      r   
test_emptyzTestConvertScipy.test_empty   s`    HJJ	

1$Q''

		RXXse__=====r   c           	         t          j                    }|                    dd           |                    dd           |                    dd           t          j        |g d          }t          j                            |                                t                              g dg dg dg                     d S )	NrT   rU   r
   )r
   rU   rT   ri   r   r   rT   )rT   r   r   r   rT   r   )	r   r   add_edger^   r   r   r   rH   r   r   s      r   test_orderingzTestConvertScipy.test_ordering   s    JLL	

1a	

1a	

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

IIKK999iii"CDD	
 	
 	
 	
 	
r   c           	         t          j        dg          }t          j        |          }t          j                            |                                t                              dgg                     |                    ddg           t          j        |g d          }t          j                            |                                t                              g dg dg dg                     d S )	NrT   rT   rT   rU   r
   r
   r+   rU   r
   r+   ri   r   )rT   r   rT   )	r   r   r^   r   r   r   rH   r   r   r   s      r   test_selfloop_graphz$TestConvertScipy.test_selfloop_graph   s    HfX$Q''

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

IIKK999iii"CDD	
 	
 	
 	
 	
r   c           	         t          j        dg          }t          j        |          }t          j                            |                                t                              dgg                     |                    ddg           t          j        |g d          }t          j                            |                                t                              g dg dg d	g                     d S )
Nr   rT   r   r   r   ri   r   r   )r   r   r   )	r   r   r^   r   r   r   rH   r   r   r   s      r   test_selfloop_digraphz&TestConvertScipy.test_selfloop_digraph   s    Jx  $Q''

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

IIKK999iii"CDD	
 	
 	
 	
 	
r   c                    t           j                            ddgddgg          }t          j                    }g d}|                    d |D                        |                    ddd           t          j        |dt          j                  }t          ||          sJ t          j        |dt          j                  }t          ||          sJ g d	}t          j	                    }|                    d
 |D                        t          j        |dt          j	                  }t          ||          sJ t          j	                    }|
                    t          |          d           d|d         d         d         d<   t          j        |dt          j	                  }t          ||          sJ dS )zTests that the :func:`networkx.from_scipy_sparse_array` function
        interprets integer weights as the number of parallel edges when
        creating a multigraph.

        rT   rU   )r   r   r   rT   rT   r   c                     g | ]
\  }}||d fS rT   r#   r-   s      r   r1   zPTestConvertScipy.test_from_scipy_sparse_array_parallel_edges.<locals>.<listcomp>   "    )H)H)HA1a))H)H)Hr   r~   T)parallel_edgesr   F)r   r   r   r   r   c                     g | ]
\  }}||d fS r   r#   r-   s      r   r1   zPTestConvertScipy.test_from_scipy_sparse_array_parallel_edges.<locals>.<listcomp>   r   r   r   r=   N)rX   rY   	csr_arrayr   r   r8   r   r@   r   MultiDiGraphr   set)r   rI   expectedr6   actuals        r   +test_from_scipy_sparse_array_parallel_edgesz<TestConvertScipy.test_from_scipy_sparse_array_parallel_edges   s    I!Q!Q 011 :<<((((()H)H%)H)H)HIII!Qq)))+d
 
 
 FH-----+e"*
 
 
 FH----- 988?$$(()H)H%)H)H)HIII+d
 
 
 FH-----?$$E

1555&'Aq(#+e"/
 
 
 FH-------r   c                 
   t           j                            ddgddgg          }t          j        |t          j                  }t          j                    }|                    ddd           t          ||          sJ dS )zTests that a symmetric matrix has edges added only once to an
        undirected multigraph when using
        :func:`networkx.from_scipy_sparse_array`.

        r   rT   r   r~   N)rX   rY   r   r   r@   
MultiGraphr   r   )r   rI   r$   r   s       r   test_symmetriczTestConvertScipy.test_symmetric   s     I!Q!Q 011&qr}EEE=??!Qq)))Ax(((((((r   N)r   r    r!   r   r)   r   rR   r\   r_   rb   re   rg   rs   r   r   r   r   r   r   r   r   r   r   r#   r   r   r   r   
   sK       5 5 5A A A  ' ' '<G G G
9 9 9
; ; ;
9 9 9
; ; ;
W W W$
 
 
%
 %
 %
N= = =1 1 1> > >
 
 
	
 	
 	
	
 	
 	
&. &. &.P
) 
) 
) 
) 
)r   r   sparse_format)r   r   r   c                 \   t          j                    }|                    ddddifddddifddddifddddifddddifddddifg           t          j                            g dg dg dg                              |           }t          |t          j        |                    sJ d	S )
z7Test all formats supported by _generate_weighted_edges.r   rT   r=   r
   rU   )r   r
   rU   )r
   r   rT   )rU   rT   r   N)	r   r   r   rX   rY   	coo_arrayasformatr   r@   )r   r   rI   s      r   $test_from_scipy_sparse_array_formatsr   	  s     xzzHHa=!Ha=!Ha=!Ha=!Ha=!Ha=!	
	 	 	 		YYY			999=>>GGVVA""<Q"?"?@@@@@@@r   )r%   networkxr   networkx.utilsr   importorskipr   rX   r   markparametrizer   r#   r   r   <module>r      s         ' ' ' ' ' 'V!!V!!|) |) |) |) |) |) |) |)~ *?@@A A A@A A Ar   