import torch


def preprocess_features(features):
    """Row-normalize feature matrix and convert to tuple representation"""
    rowsum = features.sum(1).clamp(min=1)
    r_inv = (rowsum ** -1).flatten()
    r_inv[torch.isinf(r_inv)] = 0.
    # print(r_inv.shape)
    features = r_inv.unsqueeze(1) * features
    return features