Skip to content

GraphData

GraphData(
    edge_index: array,
    node_features: Optional[array] = None,
    edge_features: Optional[array] = None,
    graph_features: Optional[array] = None,
    node_labels: Optional[array] = None,
    edge_labels: Optional[array] = None,
    graph_labels: Optional[array] = None,
    **kwargs,
)

Represents a graph data object with optional features and labels.

PyG-style aliases are available for convenience: x for node_features, edge_attr for edge_features and y for the labels (see y). They can be read, assigned and passed to the constructor (e.g. GraphData(edge_index, x=x, y=y)), but they are not stored separately: only the mlx-graphs names appear in to_dict(), keys() and in batches.

Parameters:

Name Type Description Default
edge_index array

edge index representing the topology of the graph, with shape [2, num_edges].

required
node_features Optional[array]

Array of shape [num_nodes, num_node_features] containing the features of each node.

None
edge_features Optional[array]

Array of shape [num_edges, num_edge_features] containing the features of each edge.

None
graph_features Optional[array]

Array of shape [num_graph_features] containing the global features of the graph.

None
node_labels Optional[array]

Array of shape [num_nodes, num_node_labels] containing the labels of each node.

None
edge_labels Optional[array]

Array of shape [num_edges, num_edge_labels] containing the labels of each edge.

None
graph_labels Optional[array]

Array of shape [1, num_graph_labels] containing the global labels of the graph.

None
**kwargs

Additional keyword arguments to store any other custom attributes.

{}

Methods:

Name Description
to_dict

Converts the Data object to a dictionary.

keys

Names of the attributes that are set (not None).

clone

Returns a deep copy of the graph, with copies of all the arrays.

is_node_attr

Whether the attribute key holds one entry per node.

is_edge_attr

Whether the attribute key holds one entry per edge (excluding

subgraph

Returns the subgraph induced by the nodes subset.

edge_subgraph

Returns the subgraph made of the edges subset.

validate

Checks the consistency of the graph.

is_coalesced

Whether edge_index is sorted by source then destination node and

coalesce

Sorts edge_index by source then destination node and merges

__cat_dim__

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

__inc__

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

has_self_loops

Returns a boolean of whether the graph contains self loops.

is_undirected

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

is_directed

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

Attributes:

Name Type Description
num_nodes int

Number of nodes in the graph.

num_edges int

Number of edges in the graph

num_node_classes int

Returns the number of node classes in the current graph.

num_edge_classes int

Returns the number of edge classes in the current graph.

num_graph_classes int

Returns the number of graph classes in the current graph.

num_node_features int

Returns the number of node features.

num_edge_features int

Returns the number of edge features.

num_graph_features int

Returns the number of graph features.

x Optional[array]

PyG-style alias of node_features (readable and assignable).

edge_attr Optional[array]

PyG-style alias of edge_features (readable and assignable).

y Optional[array]

PyG-style alias of the labels of the graph.

num_features int

PyG-style alias of num_node_features.

Source code in mlx_graphs/data/data.py
def __init__(
    self,
    edge_index: mx.array,
    node_features: Optional[mx.array] = None,
    edge_features: Optional[mx.array] = None,
    graph_features: Optional[mx.array] = None,
    node_labels: Optional[mx.array] = None,
    edge_labels: Optional[mx.array] = None,
    graph_labels: Optional[mx.array] = None,
    **kwargs,
):
    self.edge_index = edge_index
    self.node_features = node_features
    self.edge_features = edge_features
    self.graph_features = graph_features
    self.node_labels = node_labels
    self.edge_labels = edge_labels
    self.graph_labels = graph_labels
    # `y` is resolved last: whether it holds node or graph labels depends
    # on the number of nodes, which other arguments (`x`, `num_nodes`) set.
    y_given = "y" in kwargs
    y = kwargs.pop("y", None)
    for key, value in kwargs.items():
        setattr(self, key, value)
    if y_given:
        self.y = y

num_nodes property writable

num_nodes: int

Number of nodes in the graph.

The first available source is used:

  1. an explicit count, e.g. GraphData(edge_index, num_nodes=4);
  2. the number of rows of node_features;
  3. the number of rows of pos (node positions, e.g. point clouds);
  4. the number of unique node ids in edge_index.

The last fallback cannot see isolated nodes (nodes without any edge), so graphs without node features that may contain isolated nodes should set num_nodes explicitly. Otherwise batching offsets will be wrong.

num_edges property

num_edges: int

Number of edges in the graph

num_node_classes property

num_node_classes: int

Returns the number of node classes in the current graph.

num_edge_classes property

num_edge_classes: int

Returns the number of edge classes in the current graph.

num_graph_classes property

num_graph_classes: int

Returns the number of graph classes in the current graph.

num_node_features property

num_node_features: int

Returns the number of node features.

num_edge_features property

num_edge_features: int

Returns the number of edge features.

num_graph_features property

num_graph_features: int

Returns the number of graph features.

x property writable

x: Optional[array]

PyG-style alias of node_features (readable and assignable).

edge_attr property writable

edge_attr: Optional[array]

PyG-style alias of edge_features (readable and assignable).

y property writable

y: Optional[array]

PyG-style alias of the labels of the graph.

Reading y returns node_labels if they are set, and graph_labels otherwise (None if neither is set). Edge labels are never returned.

Assigning y replaces the labels that reading y returns. If the graph has no labels yet, the value becomes node_labels if it has one entry per node and graph_labels otherwise, which is the rule used by from_pyg(). On a single-node graph, a one-entry y is ambiguous and becomes graph_labels, so that graph classification datasets with single-node graphs keep the same attributes in every graph (and can be batched): set node_labels directly for the node labels of a single-node graph. Assigning None clears the labels that reading y returned.

num_features property

num_features: int

PyG-style alias of num_node_features.

to_dict

to_dict() -> dict

Converts the Data object to a dictionary.

Returns:

Type Description
dict

A dictionary with all attributes of the GraphData object.

Source code in mlx_graphs/data/data.py
def to_dict(self) -> dict:
    """Converts the Data object to a dictionary.

    Returns:
        A dictionary with all attributes of the `GraphData` object.
    """
    return {k: v for k, v in self.__dict__.items() if v is not None}

keys

keys() -> list[str]

Names of the attributes that are set (not None).

Private attributes are omitted, and "num_nodes" is included when the number of nodes was set explicitly. PyG-style aliases (x, edge_attr, y) are not listed, only the attributes they refer to.

Returns:

Type Description
list[str]

The list of attribute names.

Source code in mlx_graphs/data/data.py
def keys(self) -> list[str]:
    """Names of the attributes that are set (not ``None``).

    Private attributes are omitted, and ``"num_nodes"`` is included when
    the number of nodes was set explicitly. PyG-style aliases (``x``,
    ``edge_attr``, ``y``) are not listed, only the attributes they refer
    to.

    Returns:
        The list of attribute names.
    """
    keys = [
        key
        for key, value in vars(self).items()
        if value is not None and not key.startswith("_")
    ]
    if getattr(self, "_num_nodes", None) is not None:
        keys.append("num_nodes")
    return keys

clone

clone() -> GraphData

Returns a deep copy of the graph, with copies of all the arrays.

Source code in mlx_graphs/data/data.py
def clone(self) -> "GraphData":
    """Returns a deep copy of the graph, with copies of all the arrays."""
    return copy.deepcopy(self)

is_node_attr

is_node_attr(key: str) -> bool

Whether the attribute key holds one entry per node.

An array attribute is per-node if its first dimension is the number of nodes. If the graph has as many nodes as edges, attributes with "edge" in their name are considered per-edge instead.

Parameters:

Name Type Description Default
key str

Name of the attribute (PyG-style aliases are accepted).

required

Returns:

Type Description
bool

True if the attribute is node-level.

Source code in mlx_graphs/data/data.py
def is_node_attr(self, key: str) -> bool:
    """Whether the attribute ``key`` holds one entry per node.

    An array attribute is per-node if its first dimension is the number of
    nodes. If the graph has as many nodes as edges, attributes with
    "edge" in their name are considered per-edge instead.

    Args:
        key: Name of the attribute (PyG-style aliases are accepted).

    Returns:
        ``True`` if the attribute is node-level.
    """
    key = _ALIASES.get(key, key)
    return key in self._node_and_edge_keys()[0]

is_edge_attr

is_edge_attr(key: str) -> bool

Whether the attribute key holds one entry per edge (excluding edge_index itself).

Parameters:

Name Type Description Default
key str

Name of the attribute (PyG-style aliases are accepted).

required

Returns:

Type Description
bool

True if the attribute is edge-level.

Source code in mlx_graphs/data/data.py
def is_edge_attr(self, key: str) -> bool:
    """Whether the attribute ``key`` holds one entry per edge (excluding
    ``edge_index`` itself).

    Args:
        key: Name of the attribute (PyG-style aliases are accepted).

    Returns:
        ``True`` if the attribute is edge-level.
    """
    key = _ALIASES.get(key, key)
    return key in self._node_and_edge_keys()[1]

subgraph

subgraph(subset: IndexLike) -> GraphData

Returns the subgraph induced by the nodes subset.

The edges between nodes of subset are kept and relabeled, and every node-level and edge-level attribute (see is_node_attr() and is_edge_attr()) is sliced accordingly. Other attributes are shared with the original graph.

Parameters:

Name Type Description Default
subset IndexLike

The nodes to keep, as an array (or list) of node indices or as a boolean mask of shape [num_nodes]. With indices, the nodes of the subgraph follow the order of subset.

required

Returns:

Type Description
GraphData

A new graph with len(subset) nodes (or subset.sum() nodes

GraphData

for a mask).

Example:

graph = GraphData(
    edge_index=mx.array([[0, 1, 2], [1, 2, 3]]),
    node_features=mx.array([[0.0], [1.0], [2.0], [3.0]]),
)
sub = graph.subgraph(mx.array([1, 2, 3]))
sub.edge_index
# mx.array([[0, 1], [1, 2]])
sub.node_features
# mx.array([[1.0], [2.0], [3.0]])
Source code in mlx_graphs/data/data.py
def subgraph(self, subset: IndexLike) -> "GraphData":
    """Returns the subgraph induced by the nodes ``subset``.

    The edges between nodes of ``subset`` are kept and relabeled, and every
    node-level and edge-level attribute (see :meth:`is_node_attr` and
    :meth:`is_edge_attr`) is sliced accordingly. Other attributes are
    shared with the original graph.

    Args:
        subset: The nodes to keep, as an array (or list) of node indices or
            as a boolean mask of shape ``[num_nodes]``. With indices, the
            nodes of the subgraph follow the order of ``subset``.

    Returns:
        A new graph with ``len(subset)`` nodes (or ``subset.sum()`` nodes
        for a mask).

    Example:

    .. code-block:: python

        graph = GraphData(
            edge_index=mx.array([[0, 1, 2], [1, 2, 3]]),
            node_features=mx.array([[0.0], [1.0], [2.0], [3.0]]),
        )
        sub = graph.subgraph(mx.array([1, 2, 3]))
        sub.edge_index
        # mx.array([[0, 1], [1, 2]])
        sub.node_features
        # mx.array([[1.0], [2.0], [3.0]])
    """
    num_nodes = self._full_num_nodes()
    node_keys, edge_keys = self._node_and_edge_keys()
    keep_nodes = _to_host_index(subset, num_nodes, "subset")

    data = copy.copy(self)
    if self.edge_index is not None:
        edge_index, _, edge_mask = _node_subgraph(
            keep_nodes,
            self.edge_index,
            relabel_nodes=True,
            num_nodes=num_nodes,
            return_edge_mask=True,
        )
        keep_edges = np.nonzero(np.asarray(edge_mask))[0]
        for key in edge_keys:
            setattr(data, key, _take(getattr(self, key), keep_edges))
        data.edge_index = edge_index
    for key in node_keys:
        setattr(data, key, _take(getattr(self, key), keep_nodes))
    if self._needs_explicit_num_nodes():
        data.num_nodes = keep_nodes.size
    return data

edge_subgraph

edge_subgraph(subset: IndexLike) -> GraphData

Returns the subgraph made of the edges subset.

Every node is kept, even if it becomes isolated, and every edge-level attribute (see is_edge_attr()) is sliced accordingly.

Parameters:

Name Type Description Default
subset IndexLike

The edges to keep, as an array (or list) of edge indices or as a boolean mask of shape [num_edges].

required

Returns:

Type Description
GraphData

A new graph with the selected edges.

Example:

graph = GraphData(
    edge_index=mx.array([[0, 1, 2], [1, 2, 3]]),
    edge_features=mx.array([[0.0], [1.0], [2.0]]),
)
sub = graph.edge_subgraph(mx.array([0, 2]))
sub.edge_index
# mx.array([[0, 2], [1, 3]])
sub.num_nodes
# 4
Source code in mlx_graphs/data/data.py
def edge_subgraph(self, subset: IndexLike) -> "GraphData":
    """Returns the subgraph made of the edges ``subset``.

    Every node is kept, even if it becomes isolated, and every edge-level
    attribute (see :meth:`is_edge_attr`) is sliced accordingly.

    Args:
        subset: The edges to keep, as an array (or list) of edge indices
            or as a boolean mask of shape ``[num_edges]``.

    Returns:
        A new graph with the selected edges.

    Example:

    .. code-block:: python

        graph = GraphData(
            edge_index=mx.array([[0, 1, 2], [1, 2, 3]]),
            edge_features=mx.array([[0.0], [1.0], [2.0]]),
        )
        sub = graph.edge_subgraph(mx.array([0, 2]))
        sub.edge_index
        # mx.array([[0, 2], [1, 3]])
        sub.num_nodes
        # 4
    """
    num_nodes = self._full_num_nodes()
    _, edge_keys = self._node_and_edge_keys()
    keep = _to_host_index(subset, self.num_edges, "subset")
    data = copy.copy(self)
    for key in edge_keys:
        setattr(data, key, _take(getattr(self, key), keep))
    data.edge_index = _take(self.edge_index, keep, axis=1)
    if self._needs_explicit_num_nodes():
        data.num_nodes = num_nodes
    return data

validate

validate(raise_on_error: bool = True) -> bool

Checks the consistency of the graph.

The following properties are checked:

  • edge_index has shape [2, num_edges] and an integer dtype;
  • edge_index has no negative node id, and no node id greater than or equal to the number of nodes when it is known (set explicitly or given by node_features);
  • node-level default attributes (node_features, node_labels) have one entry per node, if the number of nodes is set explicitly;
  • edge_features and edge_labels have one entry per edge.

Parameters:

Name Type Description Default
raise_on_error bool

If True, raises a ValueError on the first failed check. Otherwise, emits a warning for every failed check. Default: True

True

Returns:

Type Description
bool

True if every check passed, False otherwise.

Source code in mlx_graphs/data/data.py
def validate(self, raise_on_error: bool = True) -> bool:
    """Checks the consistency of the graph.

    The following properties are checked:

    - ``edge_index`` has shape ``[2, num_edges]`` and an integer dtype;
    - ``edge_index`` has no negative node id, and no node id greater than
      or equal to the number of nodes when it is known (set explicitly or
      given by ``node_features``);
    - node-level default attributes (``node_features``, ``node_labels``)
      have one entry per node, if the number of nodes is set explicitly;
    - ``edge_features`` and ``edge_labels`` have one entry per edge.

    Args:
        raise_on_error: If ``True``, raises a ``ValueError`` on the first
            failed check. Otherwise, emits a warning for every failed check.
            Default: ``True``

    Returns:
        ``True`` if every check passed, ``False`` otherwise.
    """
    name = type(self).__name__
    errors = []
    edge_index = self.edge_index
    known_num_nodes = getattr(self, "_num_nodes", None)
    if known_num_nodes is None and self.node_features is not None:
        known_num_nodes = self.node_features.shape[0]

    if edge_index is None:
        errors.append(f"'edge_index' is undefined in '{name}'")
    elif edge_index.ndim != 2 or edge_index.shape[0] != 2:
        errors.append(
            f"'edge_index' needs to be of shape [2, num_edges] in '{name}' "
            f"(found {tuple(edge_index.shape)})"
        )
    else:
        if not mx.issubdtype(edge_index.dtype, mx.integer):
            errors.append(
                f"'edge_index' needs an integer dtype in '{name}' "
                f"(found {edge_index.dtype})"
            )
        if edge_index.size > 0:
            min_id = int(mx.min(edge_index).item())
            max_id = int(mx.max(edge_index).item())
            if min_id < 0:
                errors.append(
                    f"'edge_index' contains negative indices in '{name}' "
                    f"(found {min_id})"
                )
            if known_num_nodes is not None and max_id >= known_num_nodes:
                errors.append(
                    "'edge_index' contains larger indices than the number "
                    f"of nodes ({known_num_nodes}) in '{name}' "
                    f"(found {max_id})"
                )
        for key in ("edge_features", "edge_labels"):
            value = getattr(self, key)
            if value is not None and (
                value.ndim == 0 or value.shape[0] != edge_index.shape[1]
            ):
                errors.append(
                    f"'{key}' needs one entry per edge ({edge_index.shape[1]}) "
                    f"in '{name}' (found shape {tuple(value.shape)})"
                )

    explicit = getattr(self, "_num_nodes", None)
    if explicit is not None:
        for key in ("node_features", "node_labels"):
            value = getattr(self, key)
            if value is not None and (
                value.ndim == 0 or value.shape[0] != explicit
            ):
                errors.append(
                    f"'{key}' needs one entry per node ({explicit}) in "
                    f"'{name}' (found shape {tuple(value.shape)})"
                )

    for error in errors:
        if raise_on_error:
            raise ValueError(error)
        warnings.warn(error, stacklevel=2)
    return len(errors) == 0

is_coalesced

is_coalesced() -> bool

Whether edge_index is sorted by source then destination node and contains no duplicate edge.

Source code in mlx_graphs/data/data.py
def is_coalesced(self) -> bool:
    """Whether ``edge_index`` is sorted by source then destination node and
    contains no duplicate edge."""
    if self.edge_index.shape[1] < 2:
        return True
    edges = np.asarray(self.edge_index).astype(np.int64)
    src, dst = edges[0], edges[1]
    return bool(
        np.all(
            (src[1:] > src[:-1]) | ((src[1:] == src[:-1]) & (dst[1:] > dst[:-1]))
        )
    )

coalesce

coalesce(reduce: str = 'add') -> GraphData

Sorts edge_index by source then destination node and merges duplicate edges.

Every edge-level attribute (see is_edge_attr(), e.g. edge_features, edge_weights) follows the edges, and the values of merged edges are combined with reduce. The original graph is left unchanged.

Parameters:

Name Type Description Default
reduce str

How the attributes of merged edges are combined: "add", "mean", "max" or "min". Default: "add"

'add'

Returns:

Type Description
GraphData

A coalesced copy of the graph (the graph itself if it is already

GraphData

coalesced).

Example:

graph = GraphData(
    edge_index=mx.array([[1, 0, 1], [0, 1, 0]]),
    edge_features=mx.array([[1.0], [2.0], [3.0]]),
)
graph = graph.coalesce()
graph.edge_index
# mx.array([[0, 1], [1, 0]])
graph.edge_features
# mx.array([[2.0], [4.0]])
Source code in mlx_graphs/data/data.py
def coalesce(self, reduce: str = "add") -> "GraphData":
    """Sorts ``edge_index`` by source then destination node and merges
    duplicate edges.

    Every edge-level attribute (see :meth:`is_edge_attr`, e.g.
    ``edge_features``, ``edge_weights``) follows the edges, and the values
    of merged edges are combined with ``reduce``. The original graph is
    left unchanged.

    Args:
        reduce: How the attributes of merged edges are combined: ``"add"``,
            ``"mean"``, ``"max"`` or ``"min"``. Default: ``"add"``

    Returns:
        A coalesced copy of the graph (the graph itself if it is already
        coalesced).

    Example:

    .. code-block:: python

        graph = GraphData(
            edge_index=mx.array([[1, 0, 1], [0, 1, 0]]),
            edge_features=mx.array([[1.0], [2.0], [3.0]]),
        )
        graph = graph.coalesce()
        graph.edge_index
        # mx.array([[0, 1], [1, 0]])
        graph.edge_features
        # mx.array([[2.0], [4.0]])
    """
    if self.is_coalesced():
        return self
    num_nodes = self._full_num_nodes()
    _, edge_keys = self._node_and_edge_keys()
    data = copy.copy(self)
    for key in edge_keys:
        _, values = _coalesce_edges(
            self.edge_index, getattr(self, key), num_nodes, reduce
        )
        setattr(data, key, values)
    data.edge_index = _coalesce_edges(self.edge_index, num_nodes=num_nodes)
    if self._needs_explicit_num_nodes():
        data.num_nodes = num_nodes
    return data

__cat_dim__

__cat_dim__(key: str, *args, **kwargs) -> int

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" (and the mesh triangles face) will be concatenated on axis 1, e.g. edge_index. Other attributes are concatenated on axis 0, e.g. node features.

Parameters:

Name Type Description Default
key str

Name of the attribute on which change the default concatenation dimension while using batching.

required

Returns:

Type Description
int

The dimension where concatenation will happen when batching.

Source code in mlx_graphs/data/data.py
def __cat_dim__(self, key: str, *args, **kwargs) -> int:
    """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" (and the mesh
    triangles ``face``) will be concatenated on axis 1, e.g. `edge_index`.
    Other attributes are concatenated on axis 0,
    e.g. node features.

    Args:
        key: Name of the attribute on which change the default concatenation
            dimension while using batching.

    Returns:
        The dimension where concatenation will happen when batching.
    """
    if "index" in key or key == "face":
        return 1
    return 0

__inc__

__inc__(key: str, *args, **kwargs) -> Union[int, None]

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" (and face) 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:

Name Type Description Default
key str

Name of the attribute on which change the default incrementation behavior while using batching.

required

Returns:

Type Description
Union[int, None]

Incrementing value for the given attribute or None.

Source code in mlx_graphs/data/data.py
def __inc__(self, key: str, *args, **kwargs) -> Union[int, None]:
    """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" (and ``face``) 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`.

    Args:
        key: Name of the attribute on which change the default incrementation
            behavior while using batching.

    Returns:
        Incrementing value for the given attribute or None.
    """
    if "index" in key or key == "face":
        return self.num_nodes
    if key in ("batch", "batch_indices"):
        # A graph's own assignment of nodes to sub-batches (e.g. ShaDow
        # subgraphs): offset by its number of groups, as PyG does.
        value = self.to_dict().get(key)
        if isinstance(value, mx.array):
            return int(value.max().item()) + 1 if value.size > 0 else 0
    return None

has_isolated_nodes

has_isolated_nodes() -> bool

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)

Source code in mlx_graphs/data/data.py
def has_isolated_nodes(self) -> bool:
    """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 has_isolated_nodes(self.edge_index, self.num_nodes)

has_self_loops

has_self_loops() -> bool

Returns a boolean of whether the graph contains self loops.

Source code in mlx_graphs/data/data.py
def has_self_loops(self) -> bool:
    """Returns a boolean of whether the graph contains self loops."""
    return has_self_loops(self.edge_index)

is_undirected

is_undirected() -> bool

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

Source code in mlx_graphs/data/data.py
def is_undirected(self) -> bool:
    """Returns a boolean of whether the graph is undirected or not."""
    return is_undirected(self.edge_index, self.edge_features)

is_directed

is_directed() -> bool

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

Source code in mlx_graphs/data/data.py
def is_directed(self) -> bool:
    """Returns a boolean of whether the graph is directed or not."""
    return not self.is_undirected()

from mlx_graphs.data.data import GraphData · mlx_graphs/data/data.py