#NEWLINE# def compose( G , H , name = None ) : #NEWLINE# #INDENT# 'Return a new graph of G composed with H.\n\n    Composition is the simple union of the node sets and edge sets.\n    The node sets of G and H need not be disjoint.\n\n    Parameters\n    ----------\n    G,H : graph\n       A NetworkX graph\n\n    name : string\n       Specify name for new graph\n\n    Returns\n    -------\n    C: A new graph  with the same type as G\n\n    Notes\n    -----\n    It is recommended that G and H be either both directed or both undirected.\n    Attributes from H take precedent over attributes from G.\n    ' #NEWLINE# if ( name is None ) : #NEWLINE# #INDENT# name = ( 'compose( %s, %s )' % ( G . name , H . name ) ) #NEWLINE# #UNINDENT# R = G . __class__ ( ) #NEWLINE# R . name = name #NEWLINE# R . add_nodes_from ( H . nodes ( ) ) #NEWLINE# R . add_nodes_from ( G . nodes ( ) ) #NEWLINE# if H . is_multigraph ( ) : #NEWLINE# #INDENT# R . add_edges_from ( H . edges_iter ( keys = True , data = True ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# R . add_edges_from ( H . edges_iter ( data = True ) ) #NEWLINE# #UNINDENT# if G . is_multigraph ( ) : #NEWLINE# #INDENT# R . add_edges_from ( G . edges_iter ( keys = True , data = True ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# R . add_edges_from ( G . edges_iter ( data = True ) ) #NEWLINE# #UNINDENT# R . node . update ( G . node ) #NEWLINE# R . node . update ( H . node ) #NEWLINE# R . graph . update ( G . graph ) #NEWLINE# R . graph . update ( H . graph ) #NEWLINE# return R