<s> """<STR_LIT>""" <EOL> import networkx as nx <EOL> __author__ = "<STR_LIT:\n>" . join ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> __all__ = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> def incidence_matrix ( G , nodelist = None , edgelist = None , <EOL> oriented = False , weight = None ) : <EOL> """<STR_LIT>""" <EOL> import scipy . sparse <EOL> if nodelist is None : <EOL> nodelist = list ( G ) <EOL> if edgelist is None : <EOL> if G . is_multigraph ( ) : <EOL> edgelist = list ( G . edges ( keys = True ) ) <EOL> else : <EOL> edgelist = list ( G . edges ( ) ) <EOL> A = scipy . sparse . lil_matrix ( ( len ( nodelist ) , len ( edgelist ) ) ) <EOL> node_index = dict ( ( node , i ) for i , node in enumerate ( nodelist ) ) <EOL> for ei , e in enumerate ( edgelist ) : <EOL> ( u , v ) = e [ : <NUM_LIT:2> ] <EOL> if u == v : continue <EOL> try : <EOL> ui = node_index [ u ] <EOL> vi = node_index [ v ] <EOL> except KeyError : <EOL> raise NetworkXError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if weight is None : <EOL> wt = <NUM_LIT:1> <EOL> else : <EOL> if G . is_multigraph ( ) : <EOL> ekey = e [ <NUM_LIT:2> ] <EOL> wt = G [ u ] [ v ] [ ekey ] . get ( weight , <NUM_LIT:1> ) <EOL> else : <EOL> wt = G [ u ] [ v ] . get ( weight , <NUM_LIT:1> ) <EOL> if oriented : <EOL> A [ ui , ei ] = - wt <EOL> A [ vi , ei ] = wt <EOL> else : <EOL> A [ ui , ei ] = wt <EOL> A [ vi , ei ] = wt <EOL> return A . asformat ( '<STR_LIT>' ) <EOL> def adjacency_matrix ( G , nodelist = None , weight = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return nx . to_scipy_sparse_matrix ( G , nodelist = nodelist , weight = weight ) <EOL> adj_matrix = adjacency_matrix <EOL> def setup_module ( module ) : <EOL> from nose import SkipTest <EOL> try : <EOL> import scipy <EOL> except : <EOL> raise SkipTest ( "<STR_LIT>" ) </s>
