#NEWLINE# def setWeightMatrixSparse( self , W ) : #NEWLINE# #INDENT# '\n        Set the weight matrix of this graph. Requires as input a scipy sparse matrix with the\n        same dimensions as the current weight matrix. Edges are represented by\n        non-zero edges.\n\n        :param W:  The weight matrix to use. \n        ' #NEWLINE# if ( ( not isinstance ( W , spmatrix . LLMatType ) ) and ( not sparse . issparse ( W ) ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Input must be a sparse matrix, not ' + str ( type ( W ) ) ) ) #NEWLINE# #UNINDENT# if ( W . shape != ( self . vList . getNumVertices ( ) , self . vList . getNumVertices ( ) ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Weight matrix has wrong shape : ' + str ( W . shape ) ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . W = spmatrix . ll_mat ( W . shape [ 0 ] , W . shape [ 0 ] , W . getnnz ( ) ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# self . W = spmatrix . ll_mat ( W . shape [ 0 ] , W . shape [ 0 ] , W . nnz ) #NEWLINE# #UNINDENT# if isinstance ( W , spmatrix . LLMatType ) : #NEWLINE# #INDENT# items = W . items ( ) #NEWLINE# for ( inds , val ) in items : #NEWLINE# #INDENT# self . W [ ( inds [ 0 ] , inds [ 1 ] ) ] = val #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . undirected and ( W - W . transpose ( ) ) . nonzero ( ) [ 0 ] . shape [ 0 ] ) : #NEWLINE# #INDENT# raise ValueError ( 'Weight matrix of undirected graph must be symmetric' ) #NEWLINE# #UNINDENT# ( rowInds , colInds ) = W . nonzero ( ) #NEWLINE# for i in range ( rowInds . shape [ 0 ] ) : #NEWLINE# #INDENT# self . W [ ( int ( rowInds [ i ] ) , int ( colInds [ i ] ) ) ] = W [ ( int ( rowInds [ i ] ) , int ( colInds [ i ] ) ) ]