dgl.DGLGraph.incidence_matrix¶

DGLGraph.
incidence_matrix
(typestr, ctx=device(type='cpu'))[source]¶ Return the incidence matrix representation of this graph.
An incidence matrix is an n x m sparse matrix, where n is the number of nodes and m is the number of edges. Each nnz value indicating whether the edge is incident to the node or not.
There are three types of an incidence matrix \(I\):
in
: \(I[v, e] = 1\) if \(e\) is the inedge of \(v\) (or \(v\) is the dst node of \(e\));
 \(I[v, e] = 0\) otherwise.
out
: \(I[v, e] = 1\) if \(e\) is the outedge of \(v\) (or \(v\) is the src node of \(e\));
 \(I[v, e] = 0\) otherwise.
both
: \(I[v, e] = 1\) if \(e\) is the inedge of \(v\);
 \(I[v, e] = 1\) if \(e\) is the outedge of \(v\);
 \(I[v, e] = 0\) otherwise (including selfloop).
Parameters:  typestr (str) – Can be either
in
,out
orboth
 ctx (context, optional (default=cpu)) – The context of returned incidence matrix.
Returns: The incidence matrix.
Return type: SparseTensor