def apply_sparse_self_affector(tensor, sparse_tensor):
    """
    >>> t1 = torch.ones((5,5))
    >>> s1 = torch.sparse_coo_tensor(torch.LongTensor([[0],[0],[1],[1]]),torch.FloatTensor([-0.5]),(5,5,5,5))
    >>> apply_sparse_self_affector(t1, s1)
    tensor([[1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
            [1.0000, 0.5000, 1.0000, 1.0000, 1.0000],
            [1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
            [1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
            [1.0000, 1.0000, 1.0000, 1.0000, 1.0000]])

    :param tensor: Tensor to have self links applied to.
    :param sparse_tensor: Sparse tensor representing links of points in tensor to other points in tensor.
        Rank should be 2x tensor's rank.
    :return: tensor modified by self links.
    """
    t_rank = int(len(tensor.shape))
    if sparse_tensor._values().shape[0] == 0:
        return tensor
    coo_indices = sparse_tensor._indices()
    tens = tensor.clone()
    tens[list(coo_indices[t_rank:])] += tens[list(coo_indices[:t_rank])
        ] * sparse_tensor._values()
    return tens
