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.
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)
Returns a boolean of whether the graph contains self loops.
Returns a boolean of whether the graph is directed or not.
Returns a boolean of whether the graph is undirected or not.
to_dict
()Converts the Data object to a dictionary.
Attributes
Returns the number of edge classes in the current graph.
Returns the number of edge features.
Number of edges in the graph
Returns the number of graph classes in the current graph.
Returns the number of graph features.
Returns the number of node classes in the current graph.
Returns the number of node features.
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.
- __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.
- 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:
- has_self_loops() bool [source]#
Returns a boolean of whether the graph contains self loops.
- Return type:
- is_directed() bool [source]#
Returns a boolean of whether the graph is directed or not.
- Return type: