Decorator function to check the validity of an edge_index.
Source code in mlx_graphs/utils/validators.py
| def validate_edge_index(func):
"""Decorator function to check the validity of an edge_index."""
@functools.wraps(func)
def wrapper(edge_index, *args, **kwargs):
if edge_index.ndim != 2:
raise ValueError(
"edge_index must be 2-dimensional with shape [2, num_edges]",
f"(got {edge_index.ndim} dimensions)",
)
if edge_index.shape[0] != 2:
raise ValueError(
"edge_index must be 2-dimensional with shape [2, num_edges]",
f"(got {edge_index.shape} shape)",
)
return func(edge_index, *args, **kwargs)
return wrapper
|