import torch


def mean_neighbors(features, adjacency):
    """
    Compute the average features of all neighbors of each node in a graph.
    The features must have the same number of rows as the adjacency matrix.
    :param features: The features of each node, in the same order as the adjacency matrix rows.
    :param adjacency: The adjacency matrix of the graph
    :return: A tensor with the same shape as features, but each row is the mean of all neighbors of that node.
             Nodes without neighbors are set to 0.
    """
    bool_adj = (adjacency != 0.).float()
    counts = bool_adj.sum(dim=1, keepdim=True)

    neighbor_means = (bool_adj @ features) / torch.clamp(counts, min=1.)
    return neighbor_means