import torch


def count_duplicates(cover_index: torch.LongTensor, normalize=False):
    """Count the number of node repetitions in the cover sets. 
    
    Args:
        cover_index (torch.LongTensor): Cover assignment matrix, in sparse
            coordinate form.
        normalize (bool, optional): Normalize the results with respect to the
            total nodes in the graph. Defaults to `False`.
    
    Returns:
        int or float: Node repetitions.
    """
    num_nodes = cover_index[0].max().item() + 1
    duplicates = cover_index.size(1) - num_nodes

    if normalize:
        duplicates /= num_nodes
    
    return duplicates