gammagl.data.BatchGraph

class BatchGraph(*args, **kwargs)[source]

Bases: object

A data object describing a batch of graphs as one big (disconnected) graph. Inherits from gammagl.data.Graph or gammagl.data.HeteroGraph. In addition, single graphs can be identified via the assignment vector batch, which maps each node to its respective graph identifier.

classmethod from_data_list(data_list: List[Graph], follow_batch: List[str] | None = None, exclude_keys: List[str] | None = None)[source]

Constructs a BatchGraph object from a Python list of Graph or HeteroGraph objects. The assignment vector batch is created on the fly. In addition, creates assignment vectors for each key in follow_batch. Will exclude any keys given in exclude_keys.

get_example(idx: int) Graph[source]

Gets the Graph or HeteroGraph object at index idx. The BatchGraph object must have been created via from_data_list() in order to be able to reconstruct the initial object.

index_select(idx: slice | ndarray | Sequence) List[Graph][source]

Creates a subset of Graph or HeteroGraph objects from specified indices idx. Indices idx can be a slicing object, e.g., [2:5], a list, a tuple, or a torch.Tensor or np.ndarray of type long or bool. The BatchGraph object must have been created via from_data_list() in order to be able to reconstruct the initial objects.

to_data_list() List[Graph][source]

Reconstructs the list of Graph or HeteroGraph objects from the BatchGraph object. The BatchGraph object must have been created via from_data_list() in order to be able to reconstruct the initial objects.

property num_graphs: int

Returns the number of graphs in the batch.