import torch


def byte_tensor_to_index(x):
    """
    Convert a torch.ByteTensor of size [batch_size, 1]
    to a torch.LongTensor containing only nonzero elements
    of x converted to the corresponding index values.
    """
    idx_tensor = []
    for i in range(x.size()[0]):
        if x.data[i][0] == 1:
            idx_tensor.append(i)
    return torch.LongTensor(idx_tensor)