(self, *args, **kwds)
__init__(n=0, edges=None, directed=False, graph_attrs=None,
        vertex_attrs=None, edge_attrs=None)

        Constructs a graph from scratch.

        @keyword n: the number of vertices. Can be omitted, the default is
          zero. Note that if the edge list contains vertices with indexes
          larger than or equal to M{m}, then the number of vertices will
          be adjusted accordingly.
        @keyword edges: the edge list where every list item is a pair of
          integers. If any of the integers is larger than M{n-1}, the number
          of vertices is adjusted accordingly. C{None} means no edges.
        @keyword directed: whether the graph should be directed
        @keyword graph_attrs: the attributes of the graph as a dictionary.
        @keyword vertex_attrs: the attributes of the vertices as a dictionary.
          Every dictionary value must be an iterable with exactly M{n} items.
        @keyword edge_attrs: the attributes of the edges as a dictionary. Every
          dictionary value must be an iterable with exactly M{m} items where
          M{m} is the number of edges.
__init__(n=0, edges=None, directed=False, graph_attrs=None,
        vertex_attrs=None, edge_attrs=None)
__init__ ( n = 0 edges = None directed = False graph_attrs = None vertex_attrs = None edge_attrs = None )
def __init__(self, *args, **kwds):
        """__init__(n=0, edges=None, directed=False, graph_attrs=None,
        vertex_attrs=None, edge_attrs=None)

        Constructs a graph from scratch.

        @keyword n: the number of vertices. Can be omitted, the default is
          zero. Note that if the edge list contains vertices with indexes
          larger than or equal to M{m}, then the number of vertices will
          be adjusted accordingly.
        @keyword edges: the edge list where every list item is a pair of
          integers. If any of the integers is larger than M{n-1}, the number
          of vertices is adjusted accordingly. C{None} means no edges.
        @keyword directed: whether the graph should be directed
        @keyword graph_attrs: the attributes of the graph as a dictionary.
        @keyword vertex_attrs: the attributes of the vertices as a dictionary.
          Every dictionary value must be an iterable with exactly M{n} items.
        @keyword edge_attrs: the attributes of the edges as a dictionary. Every
          dictionary value must be an iterable with exactly M{m} items where
          M{m} is the number of edges.
        """
        # Pop the special __ptr keyword argument
        ptr = kwds.pop("__ptr", None)

        # Set up default values for the parameters. This should match the order
        # in *args
        kwd_order = (
            "n",
            "edges",
            "directed",
            "graph_attrs",
            "vertex_attrs",
            "edge_attrs",
        )
        params = [0, [], False, {}, {}, {}]

        # Is there any keyword argument in kwds that we don't know? If so,
        # freak out.
        unknown_kwds = set(kwds.keys())
        unknown_kwds.difference_update(kwd_order)
        if unknown_kwds:
            raise TypeError(
                "{0}.__init__ got an unexpected keyword argument {1!r}".format(
                    self.__class__.__name__, unknown_kwds.pop()
                )
            )

        # If the first argument is a list or any other iterable, assume that
        # the number of vertices were omitted
        args = list(args)
        if len(args) > 0 and hasattr(args[0], "__iter__"):
            args.insert(0, params[0])

        # Override default parameters from args
        params[: len(args)] = args

        # Override default parameters from keywords
        for idx, k in enumerate(kwd_order):
            if k in kwds:
                params[idx] = kwds[k]

        # Now, translate the params list to argument names
        nverts, edges, directed, graph_attrs, vertex_attrs, edge_attrs = params

        # When the number of vertices is None, assume that the user meant zero
        if nverts is None:
            nverts = 0

        # When 'edges' is None, assume that the user meant an empty list
        if edges is None:
            edges = []

        # When 'edges' is a NumPy array or matrix, convert it into a memoryview
        # as the lower-level C API works with memoryviews only
        try:
            from numpy import ndarray, matrix

            if isinstance(edges, (ndarray, matrix)):
                edges = numpy_to_contiguous_memoryview(edges)
        except ImportError:
            pass

        # Initialize the graph
        if ptr:
            GraphBase.__init__(self, __ptr=ptr)
        else:
            GraphBase.__init__(self, nverts, edges, directed)

        # Set the graph attributes
        for key, value in graph_attrs.items():
            if isinstance(key, int):
                key = str(key)
            self[key] = value
        # Set the vertex attributes
        for key, value in vertex_attrs.items():
            if isinstance(key, int):
                key = str(key)
            self.vs[key] = value
        # Set the edge attributes
        for key, value in edge_attrs.items():
            if isinstance(key, int):
                key = str(key)
            self.es[key] = value
def __init__ ( self , * args , * * kwds ) : # Pop the special __ptr keyword argument ptr = kwds . pop ( "__ptr" , None ) # Set up default values for the parameters. This should match the order # in *args kwd_order = ( "n" , "edges" , "directed" , "graph_attrs" , "vertex_attrs" , "edge_attrs" , ) params = [ 0 , [ ] , False , { } , { } , { } ] # Is there any keyword argument in kwds that we don't know? If so, # freak out. unknown_kwds = set ( kwds . keys ( ) ) unknown_kwds . difference_update ( kwd_order ) if unknown_kwds : raise TypeError ( "{0}.__init__ got an unexpected keyword argument {1!r}" . format ( self . __class__ . __name__ , unknown_kwds . pop ( ) ) ) # If the first argument is a list or any other iterable, assume that # the number of vertices were omitted args = list ( args ) if len ( args ) > 0 and hasattr ( args [ 0 ] , "__iter__" ) : args . insert ( 0 , params [ 0 ] ) # Override default parameters from args params [ : len ( args ) ] = args # Override default parameters from keywords for idx , k in enumerate ( kwd_order ) : if k in kwds : params [ idx ] = kwds [ k ] # Now, translate the params list to argument names nverts , edges , directed , graph_attrs , vertex_attrs , edge_attrs = params # When the number of vertices is None, assume that the user meant zero if nverts is None : nverts = 0 # When 'edges' is None, assume that the user meant an empty list if edges is None : edges = [ ] # When 'edges' is a NumPy array or matrix, convert it into a memoryview # as the lower-level C API works with memoryviews only try : from numpy import ndarray , matrix if isinstance ( edges , ( ndarray , matrix ) ) : edges = numpy_to_contiguous_memoryview ( edges ) except ImportError : pass # Initialize the graph if ptr : GraphBase . __init__ ( self , __ptr = ptr ) else : GraphBase . __init__ ( self , nverts , edges , directed ) # Set the graph attributes for key , value in graph_attrs . items ( ) : if isinstance ( key , int ) : key = str ( key ) self [ key ] = value # Set the vertex attributes for key , value in vertex_attrs . items ( ) : if isinstance ( key , int ) : key = str ( key ) self . vs [ key ] = value # Set the edge attributes for key , value in edge_attrs . items ( ) : if isinstance ( key , int ) : key = str ( key ) self . es [ key ] = value