dgl.graphbolt.fused_csc_sampling_graph
- dgl.graphbolt.fused_csc_sampling_graph(csc_indptr: Tensor, indices: Tensor, node_type_offset: tensor | None = None, type_per_edge: tensor | None = None, node_type_to_id: Dict[str, int] | None = None, edge_type_to_id: Dict[str, int] | None = None, node_attributes: Dict[str, tensor] | None = None, edge_attributes: Dict[str, tensor] | None = None) FusedCSCSamplingGraph [source]
从 CSC 表示创建一个 FusedCSCSamplingGraph 对象。
- 参数:
csc_indptr (torch.Tensor) – 指向 indices 中每行起始位置的指针。一个整数张量,形状为 (total_num_nodes+1,)。
indices (torch.Tensor) – CSC 图中非零元素的列索引。一个整数张量,形状为 (total_num_edges,)。
node_type_offset (Optional[torch.tensor], optional) – 图中节点类型的偏移量,默认为 None。
type_per_edge (Optional[torch.tensor], optional) – 图中每条边的类型 ID,默认为 None。如果提供,要求每个顶点的邻域内的边类型是有序的。更确切地说,对于 [0, csc_indptr.size(0) - 1) 中的每个 i,type_per_edge[indptr[i]: indptr[i + 1]] 应该单调不减。
node_type_to_id (Optional[Dict[str, int]], optional) – 将节点类型映射到 ID,默认为 None。
edge_type_to_id (Optional[Dict[str, int]], optional) – 将边类型映射到 ID,默认为 None。
node_attributes (Optional[Dict[str, torch.tensor]], optional) – 图的节点属性,默认为 None。
edge_attributes (Optional[Dict[str, torch.tensor]], optional) – 图的边属性,默认为 None。
- 返回值:
创建的 FusedCSCSamplingGraph 对象。
- 返回类型:
示例
>>> ntypes = {'n1': 0, 'n2': 1, 'n3': 2} >>> etypes = {'n1:e1:n2': 0, 'n1:e2:n3': 1} >>> csc_indptr = torch.tensor([0, 2, 5, 7, 8]) >>> indices = torch.tensor([1, 3, 0, 1, 2, 0, 3, 2]) >>> node_type_offset = torch.tensor([0, 1, 2, 4]) >>> type_per_edge = torch.tensor([0, 1, 0, 1, 1, 0, 0, 0]) >>> graph = graphbolt.fused_csc_sampling_graph(csc_indptr, indices, ... node_type_offset=node_type_offset, ... type_per_edge=type_per_edge, ... node_type_to_id=ntypes, edge_type_to_id=etypes, ... node_attributes=None, edge_attributes=None,) >>> print(graph) FusedCSCSamplingGraph(csc_indptr=tensor([0, 2, 5, 7, 8]), indices=tensor([1, 3, 0, 1, 2, 0, 3, 2]), total_num_nodes=4, num_edges={'n1:e1:n2': 5, 'n1:e2:n3': 3}, node_type_offset=tensor([0, 1, 2, 4]), type_per_edge=tensor([0, 1, 0, 1, 1, 0, 0, 0]), node_type_to_id={'n1': 0, 'n2': 1, 'n3': 2}, edge_type_to_id={'n1:e1:n2': 0, 'n1:e2:n3': 1},)