'Arguments:
t (int): time step
z_list (list of tensors) : fprop outputs for all beams'

def _beamsearch_step(self, t, z_list_t, init_state_lists):

    num_out = self.layers.out_shape[0]
    init_state_lists_in = []
    for isl in init_state_lists:
        init_state_lists_in.append([state.get() for state in isl])
    init_state_lists_out = [[np.zeros(tnsr.shape) for tnsr in init_state_lists[0]] for _ in range(len(init_state_lists_in))]
    z_list = [z_list_t[bb].get() for bb in range(self.num_live)]
    scores_list = [(np.log(z) + score) for (z, score) in zip(z_list, self.scores)]
    scores = np.vstack(scores_list)
    self.num_live = num_live = (self.num_beams - self.num_dead)
    ind = scores.argsort(axis=0)[(- num_live):]
    self.scores_list = scores_list
    hyp_num = (ind // num_out).astype(np.int32)
    word_num = (ind % num_out)
    old_candidates = [can.copy() for can in self.candidates]
    for bb in range(num_live):
        for hyp in range(len(scores_list)):
            ex_with_hyp = np.where((hyp_num[bb, :] == hyp))[0]
            self.candidates[bb][:, ex_with_hyp] = old_candidates[hyp][:, ex_with_hyp]
            wnum = word_num[(bb, ex_with_hyp)]
            self.scores[bb][ex_with_hyp] = scores_list[hyp][(wnum, ex_with_hyp)]
        self.candidates[bb][t, :] = word_num[bb, :]
    for bb in range(num_live):
        for hyp in range(len(scores_list)):
            ex_with_hyp = np.where((hyp_num[bb, :] == hyp))[0]
            for ii in range(len(self.layers.decoder._recurrent)):
                init_state_lists_out[bb][ii][:, ex_with_hyp] = init_state_lists_in[hyp][ii][:, ex_with_hyp]
    for bb in range(num_live):
        if self.hasLUT:
            inputs = self.be.array(self.candidates[bb][t, :].reshape(1, (-1)))
            self.z_list[bb][:] = inputs
        else:
            inputs = self.be.array(self.candidates[bb][t, :], dtype=np.int32)
            self.z_list[bb][:] = self.be.onehot(inputs, axis=0)
    for (ii, isl) in enumerate(init_state_lists_out):
        for (jj, state) in enumerate(isl):
            self.init_state_lists[ii][jj][:] = state
