dgl.graphbolt.unique_and_compact(nodes: List[Tensor] | Dict[str, List[Tensor]])[source]

Compact a list of nodes tensor.


nodes (List[torch.Tensor] or Dict[str, List[torch.Tensor]]) – List of nodes for compacting. the unique_and_compact will be done per type - If nodes is a list of tensor: All the tensors will do unique and compact together, usually it is used for homogeneous graph. - If nodes is a list of dictionary: The keys should be node type and the values should be corresponding nodes, the unique and compact will be done per type, usually it is used for heterogeneous graph.


The Unique nodes (per type) of all nodes in the input. And the compacted nodes list, where IDs inside are replaced with compacted node IDs. β€œCompacted node list” indicates that the node IDs in the input node list are replaced with mapped node IDs, where each type of node is mapped to a contiguous space of IDs ranging from 0 to N.

Return type:

Tuple[unique_nodes, compacted_node_list]