gammagl.data.BaseGraph

class BaseGraph[source]

Bases: object

to_dict() Dict[str, Any][source]

Returns a dictionary of stored key/value pairs.

to_namedtuple() NamedTuple[source]

Returns a NamedTuple of stored key/value pairs.

__cat_dim__(key: str, value: Any, *args, **kwargs) Any[source]

Returns the dimension for which the value value of the attribute key will get concatenated when creating mini-batches using gammagl.loader.DataLoader.

Note

This method is for internal use only, and should only be overridden in case the mini-batch creation process is corrupted for a specific attribute.

__inc__(key: str, value: Any, *args, **kwargs) Any[source]

Returns the incremental count to cumulatively increase the value value of the attribute key when creating mini-batches using gammagl.loader.DataLoader.

Note

This method is for internal use only, and should only be overridden in case the mini-batch creation process is corrupted for a specific attribute.

property keys: List[str]

Returns a list of all graph attribute names.

property num_nodes: int | None

Returns the number of nodes in the graph.

Note

The number of nodes in the data object is automatically inferred in case node-level attributes are present, e.g., data.x. In some cases, however, a graph may only be given without any node-level attributes. GammaGL then guesses the number of nodes according to edge_index.max().item() + 1. However, in case there exists isolated nodes, this number does not have to be correct which can result in unexpected behaviour. Thus, we recommend to set the number of nodes in your data object explicitly via graph.num_nodes = .... You will be given a warning that requests you to do so.

size(dim: int | None = None) Tuple[int | None, int | None] | int | None[source]

Returns the size of the adjacency matrix induced by the graph.

property num_edges: int

Returns the number of edges in the graph. For undirected graphs, this will return the number of bi-directional edges, which is double the amount of unique edges.

is_coalesced() bool[source]

Returns True if the edge_index is sorted and does not contain duplicate entries.

coalesce()[source]

Sorts and removes duplicated entries from edge indices edge_index.

has_isolated_nodes() bool[source]

Returns True if the graph contains isolated nodes.

has_self_loops() bool[source]

Returns True if the graph contains self-loops.

is_undirected() bool[source]

Returns True if graph edges are undirected.

is_directed() bool[source]

Returns True if graph edges are directed.

apply_(func: Callable, *args: List[str])[source]

Applies the in-place function func, either to all attributes or only the ones given in *args.

apply(func: Callable, *args: List[str])[source]

Applies the function func, either to all attributes or only the ones given in *args.

clone(*args: List[str])[source]

Performs cloning of tensors, either for all attributes or only the ones given in *args. It can only be used in Torch.