<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def apply_network(network, x, chunksize=None):
 """ Apply a pytorch network, potentially in chunks """

    network_is_cuda = next(network.parameters()).is_cuda

    x = torch.from_numpy(x)

    with torch.no_grad():
        if network_is_cuda:
            x = x.cuda()

        if chunksize is None:
            return from_var(network(x))

        return np.concatenate(
            [from_var(network(x[i: i + chunksize]))
             for i in range(0, len(x), chunksize)])