def _convert_to_sampled_subgraph(
        self,
        C_sampled_subgraph: torch.ScriptObject,
        seed_offsets: Optional[list] = None,
        fetching_original_edge_ids_is_optional: bool = False,
    ) -> SampledSubgraphImpl:
        """An internal function used to convert a fused homogeneous sampled
        subgraph to general struct 'SampledSubgraphImpl'."""
        indptr = C_sampled_subgraph.indptr
        indices = C_sampled_subgraph.indices
        type_per_edge = C_sampled_subgraph.type_per_edge
        column = C_sampled_subgraph.original_column_node_ids
        edge_ids_in_fused_csc_sampling_graph = (
            C_sampled_subgraph.original_edge_ids
        )
        etype_offsets = C_sampled_subgraph.etype_offsets
        if etype_offsets is not None:
            etype_offsets = etype_offsets.tolist()

        has_original_eids = (
            self.edge_attributes is not None
            and ORIGINAL_EDGE_ID in self.edge_attributes
        )
        original_edge_ids = (
            (
                torch.ops.graphbolt.index_select(
                    self.edge_attributes[ORIGINAL_EDGE_ID],
                    edge_ids_in_fused_csc_sampling_graph,
                )
                if not fetching_original_edge_ids_is_optional
                or not edge_ids_in_fused_csc_sampling_graph.is_cuda
                or not self.edge_attributes[ORIGINAL_EDGE_ID].is_pinned()
                else None
            )
            if has_original_eids
            else edge_ids_in_fused_csc_sampling_graph
        )
        if type_per_edge is None and etype_offsets is None:
            # The sampled graph is already a homogeneous graph.
            sampled_csc = CSCFormatBase(indptr=indptr, indices=indices)
            if indices is not None and original_edge_ids is not None:
                # Only needed to fetch indices or original_edge_ids.
                edge_ids_in_fused_csc_sampling_graph = None
        else:
            offset = self._node_type_offset_list

            original_hetero_edge_ids = {}
            sub_indices = {}
            sub_indptr = {}
            if etype_offsets is None:
                # UVA sampling requires us to move node_type_offset to GPU.
                self.node_type_offset = self.node_type_offset.to(column.device)
                # 1. Find node types for each nodes in column.
                node_types = (
                    torch.searchsorted(
                        self.node_type_offset, column, right=True
                    )
                    - 1
                )
                for ntype, ntype_id in self.node_type_to_id.items():
                    # Get all nodes of a specific node type in column.
                    nids = torch.nonzero(node_types == ntype_id).view(-1)
                    nids_original_indptr = indptr[nids + 1]
                    for etype, etype_id in self.edge_type_to_id.items():
                        src_ntype, _, dst_ntype = etype_str_to_tuple(etype)
                        if dst_ntype != ntype:
                            continue
                        # Get all edge ids of a specific edge type.
                        eids = torch.nonzero(type_per_edge == etype_id).view(-1)
                        src_ntype_id = self.node_type_to_id[src_ntype]
                        sub_indices[etype] = (
                            indices[eids] - offset[src_ntype_id]
                        )
                        cum_edges = torch.searchsorted(
                            eids, nids_original_indptr, right=False
                        )
                        sub_indptr[etype] = torch.cat(
                            (torch.tensor([0], device=indptr.device), cum_edges)
                        )
                        original_hetero_edge_ids[etype] = original_edge_ids[
                            eids
                        ]
                sampled_hetero_edge_ids_in_fused_csc_sampling_graph = None
            else:
                sampled_hetero_edge_ids_in_fused_csc_sampling_graph = {}
                edge_offsets = [0]
                for etype, etype_id in self.edge_type_to_id.items():
                    src_ntype, _, dst_ntype = etype_str_to_tuple(etype)
                    ntype_id = self.node_type_to_id[dst_ntype]
                    edge_offsets.append(
                        edge_offsets[-1]
                        + seed_offsets[ntype_id + 1]
                        - seed_offsets[ntype_id]
                        + 1
                    )
                for etype, etype_id in self.edge_type_to_id.items():
                    src_ntype, _, dst_ntype = etype_str_to_tuple(etype)
                    ntype_id = self.node_type_to_id[dst_ntype]
                    sub_indptr[etype] = indptr[
                        edge_offsets[etype_id] : edge_offsets[etype_id + 1]
                    ]
                    sub_indices[etype] = (
                        None
                        if indices is None
                        else indices[
                            etype_offsets[etype_id] : etype_offsets[
                                etype_id + 1
                            ]
                        ]
                    )
                    original_hetero_edge_ids[etype] = (
                        None
                        if original_edge_ids is None
                        else original_edge_ids[
                            etype_offsets[etype_id] : etype_offsets[
                                etype_id + 1
                            ]
                        ]
                    )
                    if indices is None or original_edge_ids is None:
                        # Only needed to fetch indices or original edge ids.
                        sampled_hetero_edge_ids_in_fused_csc_sampling_graph[
                            etype
                        ] = edge_ids_in_fused_csc_sampling_graph[
                            etype_offsets[etype_id] : etype_offsets[
                                etype_id + 1
                            ]
                        ]

            original_edge_ids = original_hetero_edge_ids
            edge_ids_in_fused_csc_sampling_graph = (
                sampled_hetero_edge_ids_in_fused_csc_sampling_graph
            )
            sampled_csc = {
                etype: CSCFormatBase(
                    indptr=sub_indptr[etype],
                    indices=sub_indices[etype],
                )
                for etype in self.edge_type_to_id.keys()
            }
        return SampledSubgraphImpl(
            sampled_csc=sampled_csc,
            original_edge_ids=original_edge_ids,
            _edge_ids_in_fused_csc_sampling_graph=edge_ids_in_fused_csc_sampling_graph,
        )
An internal function used to convert a fused homogeneous sampled
        subgraph to general struct 'SampledSubgraphImpl'.
python/dgl/graphbolt/impl/fused_csc_sampling_graph.py