import torch


def batch_to_time(x: torch.Tensor, block_size: int) -> torch.Tensor:
    """
    Inverse of time_to_batch. Concatenates a batched time-signal back to
    correct time-domain.

    Args:
        x: The batched input size [Batch * block_size × Channels × Length]
        block_size: size of the blocks used for encoding

    Returns:
        Tensor with size: [Batch × channels × Length * block_size]
    """
    if block_size == 1:
        return x

    assert x.ndimension() == 3
    batch_size, channels, k = x.shape
    y = torch.reshape(x, [batch_size // block_size, block_size, channels, k])
    y = y.permute(0, 2, 3, 1)
    y = torch.reshape(y, [batch_size // block_size, channels, k * block_size])
    return y.contiguous()