dgl.DGLGraph¶
-
class
dgl.
DGLGraph
¶ Class for storing graph structure and node/edge feature data.
There are a few ways to create a DGLGraph:
To create a homogeneous graph from Tensor data, use
dgl.graph()
.To create a heterogeneous graph from Tensor data, use
dgl.heterograph()
.To create a graph from other data sources, use
dgl.*
create ops. See Graph Create Ops.
Read the user guide chapter Chapter 1: Graph for an in-depth explanation about its usage.
Querying metagraph structure¶
Methods for getting information about the node and edge types. They are typically useful when the graph is heterogeneous.
Return all the node type names in the graph. |
|
Return all the edge type names in the graph. |
|
Return all the source node type names in this graph. |
|
Return all the destination node type names in this graph. |
|
Return all the canonical edge types in the graph. |
|
Return the metagraph of the heterograph. |
|
|
Convert an edge type to the corresponding canonical edge type in the graph. |
Querying graph structure¶
Methods for getting information about the graph structure such as capacity, connectivity, neighborhood, etc.
|
Return the number of nodes in the graph. |
|
Alias of |
|
Return the number of edges in the graph. |
|
Alias of |
|
Return the number of source nodes in the graph. |
|
Alias of |
|
Return the number of destination nodes in the graph. |
|
Alias of |
Return whether the graph is a uni-bipartite graph. |
|
Return whether the graph is a multigraph with parallel edges. |
|
Return whether the graph is a homogeneous graph. |
|
|
Return whether the graph contains the given nodes. |
|
Return whether the graph contains the given edges. |
|
Return the predecessor(s) of a particular node with the specified edge type. |
|
Return the successor(s) of a particular node with the specified edge type. |
|
Return the edge ID(s) given the two endpoints of the edge(s). |
|
Return the source and destination node ID(s) given the edge ID(s). |
|
Return the incoming edges of the given nodes. |
|
Return the outgoing edges of the given nodes. |
|
Return the in-degree(s) of the given nodes. |
|
Return the out-degree(s) of the given nodes. |
Querying and manipulating sparse format¶
Methods for getting or manipulating the internal storage formats of a DGLGraph
.
|
Get a cloned graph with the specified sparse format(s) or query for the usage status of sparse formats |
Create all sparse matrices allowed for the graph. |
Querying and manipulating node/edge ID type¶
Methods for getting or manipulating the data type for storing structure-related data such as node and edge IDs.
The data type for storing the structure-related graph information such as node and edge IDs. |
|
Cast the graph to one with idtype int64 |
|
Cast the graph to one with idtype int32 |
Using Node/edge features¶
Methods for getting or setting the data type for storing structure-related data such as node and edge IDs.
Return a node view |
|
Return a node data view for setting/getting node features |
|
Return an edge view |
|
Return an edge data view for setting/getting edge features. |
|
|
Return the node feature schemes for the specified type. |
|
Return the edge feature schemes for the specified type. |
Return a node view for source nodes |
|
Return a node view for destination nodes |
|
Return a node data view for setting/getting source node features. |
|
Return a node data view for setting/getting destination node features. |
Transforming graph¶
Methods for generating a new graph by transforming the current ones. Most of them
are alias of the Subgraph Extraction Ops and Graph Transform Ops
under the dgl
namespace.
|
Alias of |
|
Alias of |
|
Alias of |
|
Alias of |
|
Return the relation slice of this graph. |
|
Alias of |
|
Alias of |
|
Alias of |
|
Alias of |
|
Alias of |
Convert a DGL graph to a |
|
|
Alias of |
Adjacency and incidence matrix¶
Methods for getting the adjacency and the incidence matrix of the graph.
|
Return the adjacency matrix of edges of the given edge type. |
|
Return the adjacency matrix of edges of the given edge type as tensors of a sparse matrix representation. |
|
Alias of |
|
Return the incidence matrix representation of edges with the given edge type. |
|
Return the incidence matrix representation of edges with the given edge type. |
Computing with DGLGraph¶
Methods for performing message passing, applying functions on node/edge features, etc.
|
Update the features of the specified nodes by the provided function. |
|
Update the features of the specified edges by the provided function. |
|
Send messages along the specified edges and reduce them on the destination nodes to update their features. |
|
Pull messages from the specified node(s)’ predecessors along the specified edge type, aggregate them to update the node features. |
|
Send message from the specified node(s) to their successors along the specified edge type and update their node features. |
|
Send messages along all the edges of the specified type and update all the nodes of the corresponding destination type. |
|
Send messages along all the edges, reduce them by first type-wisely then across different types, and then update the node features of all the nodes. |
|
Propagate messages using graph traversal by sequentially triggering |
|
Propagate messages using graph traversal by sequentially triggering |
|
Return the IDs of the nodes with the given node type that satisfy the given predicate. |
|
Return the IDs of the edges with the given edge type that satisfy the given predicate. |
Querying and manipulating batch information¶
Methods for getting/setting the batching information if the current graph is a batched
graph generated from dgl.batch()
. They are also widely used in the
Batching and Reading Out Ops.
Return the number of graphs in the batched graph. |
|
|
Return the number of nodes for each graph in the batch with the specified node type. |
|
Return the number of edges for each graph in the batch with the specified edge type. |
Manually set the number of nodes for each graph in the batch with the specified node type. |
|
Manually set the number of edges for each graph in the batch with the specified edge type. |
Mutating topology¶
Methods for mutating the graph structure in-place.
|
Add new nodes of the same node type |
|
Add multiple new edges for the specified edge type |
|
Remove multiple nodes with the specified node type |
|
Remove multiple edges with the specified edge type |
Device Control¶
Methods for getting or changing the device on which the graph is hosted.
|
Move ndata, edata and graph structure to the targeted device (cpu/gpu). |
Get the device of the graph. |
|
Return a new copy of this graph on CPU. |
|
Pin the graph structure and node/edge data to the page-locked memory for GPU zero-copy access. |
|
Unpin the graph structure and node/edge data from the page-locked memory. |
|
Check if the graph structure is pinned to the page-locked memory. |