mlx_graphs.data.data.GraphData#

class mlx_graphs.data.data.GraphData(edge_index: mlx.core.array, node_features: mlx.core.array | None = None, edge_features: mlx.core.array | None = None, graph_features: mlx.core.array | None = None, node_labels: mlx.core.array | None = None, edge_labels: mlx.core.array | None = None, graph_labels: mlx.core.array | None = None, **kwargs)[source]#

Represents a graph data object with optional features and labels.

Parameters:
  • edge_index (array) – edge index representing the topology of the graph, with shape [2, num_edges].

  • node_features (Optional[array]) – Array of shape [num_nodes, num_node_features] containing the features of each node.

  • edge_features (Optional[array]) – Array of shape [num_edges, num_edge_features] containing the features of each edge.

  • graph_features (Optional[array]) – Array of shape [num_graph_features] containing the global features of the graph.

  • node_labels (Optional[array]) – Array of shape [num_nodes, num_node_labels] containing the labels of each node.

  • edge_labels (Optional[array]) – Array of shape [num_edges, num_edge_labels] containing the labels of each edge.

  • graph_labels (Optional[array]) – Array of shape [1, num_graph_labels] containing the global labels of the graph.

  • **kwargs – Additional keyword arguments to store any other custom attributes.

Methods

__cat_dim__(key, *args, **kwargs)

This method can be overriden when batching is used with custom attributes.

__inc__(key, *args, **kwargs)

This method can be overriden when batching is used with custom attributes.

has_isolated_nodes()

Returns a boolean of whether the graph has isolated nodes or not (i.e., nodes that don't have a link to any other nodes)

has_self_loops()

Returns a boolean of whether the graph contains self loops.

is_directed()

Returns a boolean of whether the graph is directed or not.

is_undirected()

Returns a boolean of whether the graph is undirected or not.

to_dict()

Converts the Data object to a dictionary.

Attributes

num_edge_classes

Returns the number of edge classes in the current graph.

num_edge_features

Returns the number of edge features.

num_edges

Number of edges in the graph

num_graph_classes

Returns the number of graph classes in the current graph.

num_graph_features

Returns the number of graph features.

num_node_classes

Returns the number of node classes in the current graph.

num_node_features

Returns the number of node features.

num_nodes

Number of nodes in the graph.

__cat_dim__(key: str, *args, **kwargs) int[source]#

This method can be overriden when batching is used with custom attributes. Given the name of a custom attribute key, returns the dimension where the concatenation happens during batching.

By default, all attribute names containing “index” will be concatenated on axis 1, e.g. edge_index. Other attributes are concatenated on axis 0, e.g. node features.

Parameters:

key (str) – Name of the attribute on which change the default concatenation dimension while using batching.

Return type:

int

Returns:

The dimension where concatenation will happen when batching.

__inc__(key: str, *args, **kwargs) int | None[source]#

This method can be overriden when batching is used with custom attributes. Given the name of a custom attribute key, returns an integer indicating the incrementing value to apply to the elemnts of the attribute.

By default, all attribute names containing “index” will be incremented based on the number of nodes in previous batches to avoid duplicate nodes in the index, e.g. edge_index. Other attributes are cnot incremented and keep their original values, e.g. node features. If incrementation is not used, the return value should be set to None.

Parameters:

key (str) – Name of the attribute on which change the default incrementation behavior while using batching.

Return type:

Optional[int]

Returns:

Incrementing value for the given attribute or None.

has_isolated_nodes() bool[source]#

Returns a boolean of whether the graph has isolated nodes or not (i.e., nodes that don’t have a link to any other nodes)

Return type:

bool

has_self_loops() bool[source]#

Returns a boolean of whether the graph contains self loops.

Return type:

bool

is_directed() bool[source]#

Returns a boolean of whether the graph is directed or not.

Return type:

bool

is_undirected() bool[source]#

Returns a boolean of whether the graph is undirected or not.

Return type:

bool

property num_edge_classes: int#

Returns the number of edge classes in the current graph.

property num_edge_features: int#

Returns the number of edge features.

property num_edges: int#

Number of edges in the graph

property num_graph_classes: int#

Returns the number of graph classes in the current graph.

property num_graph_features: int#

Returns the number of graph features.

property num_node_classes: int#

Returns the number of node classes in the current graph.

property num_node_features: int#

Returns the number of node features.

property num_nodes: int#

Number of nodes in the graph.

to_dict() dict[source]#

Converts the Data object to a dictionary.

Return type:

dict

Returns:

A dictionary with all attributes of the GraphData object.