import torch


def vector_to_index(vector, all_zeros=-1):
    """
    Converts a binary vector to a list of indices corresponding to the locations where the vector was one.
    """
    l = len(vector)
    integers = torch.Tensor([i+1 for i in range(l)]) # i+1 so that the zeroth element and the zeros vector below don't conflict
    zeros = torch.zeros(l)
    indices = torch.where(vector==1, integers, zeros) # replace an element with its index+1, otherwise zero
    flattenned_indices = indices.nonzero() - 1 # Remove all zero elements, and then correct for the i+1 from before
    if len(flattenned_indices) == 0:
        return torch.Tensor([[all_zeros]])
    else:
        return flattenned_indices