Skip to content

get_src_dst_features

get_src_dst_features(
    edge_index: array, node_features: Union[array, tuple[array, array]]
) -> tuple[array, array]

Extracts source and destination node features based on the given edge indices.

Parameters:

Name Type Description Default
edge_index array

a [2, num_edges] array representing the source and target nodes of each edge

required
node_features Union[array, tuple[array, array]]

The input array of node features.

required

Returns:

Type Description
tuple[array, array]

A tuple containing source and destination features.

Source code in mlx_graphs/utils/transformations.py
@validate_edge_index
def get_src_dst_features(
    edge_index: mx.array,
    node_features: Union[mx.array, tuple[mx.array, mx.array]],
) -> tuple[mx.array, mx.array]:
    """
    Extracts source and destination node features based on the given edge indices.

    Args:
        edge_index: a [2, num_edges] array representing the source and target nodes
            of each edge
        node_features: The input array of node features.

    Returns:
        A tuple containing source and destination features.
    """
    src_idx, dst_idx = edge_index

    if isinstance(node_features, tuple):
        src_val, dst_val = node_features
        src_val = src_val[src_idx]
        dst_val = dst_val[dst_idx]

    elif isinstance(node_features, mx.array):
        src_val = node_features[src_idx]
        dst_val = node_features[dst_idx]

    else:
        raise ValueError(
            "Invalid type for argument `array`, should be a `mx.array` or a `tuple`."
        )

    return src_val, dst_val

from mlx_graphs.utils.transformations import get_src_dst_features · mlx_graphs/utils/transformations.py