dgl.DGLGraph.adj_tensorsο
- DGLGraph.adj_tensors(fmt, etype=None)[source]ο
Return the adjacency matrix of edges of the given edge type as tensors of a sparse matrix representation. By default, a row of returned adjacency matrix represents the source of an edge and the column represents the destination. :param fmt: Either
coo
,csr
orcsc
. :type fmt: str :param etype: The type names of the edges. The allowed type name formats are:(str, str, str)
for source node type, edge type and destination node type.or one
str
edge type name if the name can uniquely identify a triplet format in the graph.
Can be omitted if the graph has only one type of edges.
- Returns:
If
fmt
iscoo
, returns a pair of source and destination node ID tensors. Iffmt
iscsr
orcsc
, return the CSR or CSC representation of the adjacency matrix as a triplet of tensors(indptr, indices, edge_ids)
. Namelyedge_ids
could be an empty tensor with 0 elements, in which case the edge IDs are consecutive integers starting from 0.- Return type:
tuple[Tensor]
Examples
>>> g = dgl.graph(([0, 1, 2], [1, 2, 3])) >>> g.adj_tensors('coo') (tensor([0, 1, 2]), tensor([1, 2, 3])) >>> g.adj_tensors('csr') (tensor([0, 1, 2, 3, 3]), tensor([1, 2, 3]), tensor([0, 1, 2]))