torch_geometric.data.LargeGraphIndexer
- class LargeGraphIndexer(nodes: Iterable[Hashable], edges: Iterable[Tuple[Hashable, Hashable, Hashable]], node_attr: Optional[Dict[str, List[Any]]] = None, edge_attr: Optional[Dict[str, List[Any]]] = None)[source]
Bases:
object
For a dataset that consists of mulitiple subgraphs that are assumed to be part of a much larger graph, collate the values into a large graph store to save resources.
- classmethod from_triplets(triplets: Iterable[Tuple[Hashable, Hashable, Hashable]], pre_transform: Optional[Callable[[Tuple[Hashable, Hashable, Hashable]], Tuple[Hashable, Hashable, Hashable]]] = None) LargeGraphIndexer [source]
Generate a new index from a series of triplets that represent edge relations between nodes. Formatted like (source_node, edge, dest_node).
- Parameters:
triplets (KnowledgeGraphLike) – Series of triplets representing knowledge graph relations.
pre_transform (Optional[Callable[[TripletLike], TripletLike]]) – Optional preprocessing function to apply to triplets. Defaults to None.
- Returns:
Index of unique nodes and edges.
- Return type:
- classmethod collate(graphs: Iterable[LargeGraphIndexer]) LargeGraphIndexer [source]
Combines a series of large graph indexes into a single large graph index.
- Parameters:
graphs (Iterable["LargeGraphIndexer"]) – Indices to be combined.
- Returns:
- Singular unique index for all nodes and edges
in input indices.
- Return type:
- get_unique_node_features(feature_name: str = 'pid') List[Hashable] [source]
Get all the unique values for a specific node attribute.
- Parameters:
feature_name (str, optional) – Name of feature to get. Defaults to NODE_PID.
- Returns:
List of unique values for the specified feature.
- Return type:
List[Hashable]
- add_node_feature(new_feature_name: str, new_feature_vals: Union[Sequence[Any], Tensor], map_from_feature: str = 'pid') None [source]
- Adds a new feature that corresponds to each unique node in
the graph.
- get_node_features(feature_name: str = 'pid', pids: Optional[Iterable[Hashable]] = None) List[Any] [source]
- Get node feature values for a given set of unique node ids.
Returned values are not necessarily unique.
- Parameters:
feature_name (str, optional) – Name of feature to fetch. Defaults to NODE_PID.
pids (Optional[Iterable[Hashable]], optional) – Node ids to fetch for. Defaults to None, which fetches all nodes.
- Returns:
Node features corresponding to the specified ids.
- Return type:
List[Any]
- get_node_features_iter(feature_name: str = 'pid', pids: Optional[Iterable[Hashable]] = None, index_only: bool = False) Iterator[Any] [source]
Iterator version of get_node_features. If index_only is True, yields indices instead of values.
- get_unique_edge_features(feature_name: str = 'e_pid') List[Hashable] [source]
Get all the unique values for a specific edge attribute.
- Parameters:
feature_name (str, optional) – Name of feature to get. Defaults to EDGE_PID.
- Returns:
List of unique values for the specified feature.
- Return type:
List[Hashable]
- add_edge_feature(new_feature_name: str, new_feature_vals: Union[Sequence[Any], Tensor], map_from_feature: str = 'e_pid') None [source]
Adds a new feature that corresponds to each unique edge in the graph.
- get_edge_features(feature_name: str = 'e_pid', pids: Optional[Iterable[Hashable]] = None) List[Any] [source]
- Get edge feature values for a given set of unique edge ids.
Returned values are not necessarily unique.
- Parameters:
feature_name (str, optional) – Name of feature to fetch. Defaults to EDGE_PID.
pids (Optional[Iterable[Hashable]], optional) – Edge ids to fetch for. Defaults to None, which fetches all edges.
- Returns:
Node features corresponding to the specified ids.
- Return type:
List[Any]
- get_edge_features_iter(feature_name: str = 'e_pid', pids: Optional[Iterable[Tuple[Hashable, Hashable, Hashable]]] = None, index_only: bool = False) Iterator[Any] [source]
Iterator version of get_edge_features. If index_only is True, yields indices instead of values.