#NEWLINE# def add( self , graph ) : #NEWLINE# #INDENT# '\n        Add the edge weights of the input graph to the current one. Results in a\n        union of the edges.\n\n        :param graph: the input graph.\n        :type graph: :class:`apgl.graph.SparseGraph`\n\n        :returns: A new graph with same vertex list and addition of edge weights \n        ' #NEWLINE# Parameter . checkClass ( graph , SparseGraph ) #NEWLINE# if ( graph . getNumVertices ( ) != self . getNumVertices ( ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Can only add edges from graph with same number of vertices' ) #NEWLINE# #UNINDENT# if ( self . undirected != graph . undirected ) : #NEWLINE# #INDENT# raise ValueError ( 'Both graphs must be either undirected or directed' ) #NEWLINE# #UNINDENT# nonZeros = numpy . nonzero ( graph . W ) #NEWLINE# newGraph = SparseGraph ( self . vList , self . undirected ) #NEWLINE# newGraph . W = self . W . copy ( ) #NEWLINE# for i in range ( len ( nonZeros [ 0 ] ) ) : #NEWLINE# #INDENT# ind1 = nonZeros [ 0 ] [ i ] #NEWLINE# ind2 = nonZeros [ 1 ] [ i ] #NEWLINE# newGraph . W [ ( ind1 , ind2 ) ] = ( self . W [ ( ind1 , ind2 ) ] + graph . W [ ( ind1 , ind2 ) ] ) #NEWLINE# #UNINDENT# return newGraph