def get_rank(arr):
    """
    Given a one-dim gradient tensor, return the ranks of all gradients.

    NOTE: This function is similar to compute_rank but has no constraints on the idxs.
    """
    arr_idx = sorted(
        [(idx, grad) for idx, grad in enumerate(arr)], key=lambda t: t[1], reverse=True
    )
    arr_rank = [0 for _ in range(len(arr_idx))]
    for i, (idx, grad) in enumerate(arr_idx):
        arr_rank[idx] = i + 1

    return arr_rank, arr_idx