#NEWLINE# def __init__( self , vertices , undirected = True , W = None , dtype = numpy . float , frmt = 'csr' ) : #NEWLINE# #INDENT# '\n        Create a SparseGraph with a given AbstractVertexList or number of \n        vertices, and specify whether it is directed. One can optionally pass \n        in a sparse matrix W which is used as the weight matrix of the \n        graph. Different kinds of sparse matrix can impact the speed of various\n        operations. The currently supported sparse matrix types are: lil_matrix, \n        csr_matrix, csc_matrix and dok_matrix. The default sparse matrix is \n        csr_matrix. \n\n        :param vertices: the initial set of vertices as a AbstractVertexList object, or an int to specify the number of vertices in which case vertices are stored in a GeneralVertexList.  \n        \n        :param undirected: a boolean variable to indicate if the graph is undirected.\n        :type undirected: :class:`boolean`\n\n        :param W: a square sparse matrix of the same size as the number of vertices, or None to create the default one.\n        \n        :param dtype: the data type of the sparse matrix if W is not specified. \n        \n        :param frmt: the format of the sparse matrix: lil, csr or csc if W is not specified \n        ' #NEWLINE# Parameter . checkBoolean ( undirected ) #NEWLINE# if isinstance ( vertices , AbstractVertexList ) : #NEWLINE# #INDENT# self . vList = vertices #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( vertices , int ) : #NEWLINE# #INDENT# self . vList = GeneralVertexList ( vertices ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Invalid vList parameter: ' + str ( vertices ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( W != None ) and ( not ( sparse . issparse ( W ) and ( W . shape == ( self . vList . getNumVertices ( ) , self . vList . getNumVertices ( ) ) ) ) ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Input argument W must be None or sparse matrix of size ' + str ( self . vList . getNumVertices ( ) ) ) ) #NEWLINE# #UNINDENT# self . undirected = undirected #NEWLINE# if ( frmt == 'lil' ) : #NEWLINE# #INDENT# matrix = sparse . lil_matrix #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( frmt == 'csr' ) : #NEWLINE# #INDENT# matrix = sparse . csr_matrix #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( frmt == 'csc' ) : #NEWLINE# #INDENT# matrix = sparse . csc_matrix #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Invalid sparse matrix format: ' + frmt ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( self . vList . getNumVertices ( ) == 0 ) and ( W == None ) ) : #NEWLINE# #INDENT# self . W = matrix ( ( 1 , 1 ) , dtype = dtype ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( W == None ) : #NEWLINE# #INDENT# self . W = matrix ( ( self . vList . getNumVertices ( ) , self . vList . getNumVertices ( ) ) , dtype = dtype ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . W = W #NEWLINE# self . setWeightMatrix ( W )