def compute_tensor(self, input_var, mask=None, additional_inputs=None, steps=None, backward=False):
        # prepare parameters
        backward = backward if backward else self._go_backwards
        steps = steps if steps else self._steps
        mask = mask if mask else self._mask
        if mask and self._input_type == "one":
            raise Exception("Mask only works with sequence input")
        # get initial states
        init_state_map = self.get_initial_states(input_var)
        # get input sequence map
        if self._input_type == "sequence":
            # Move middle dimension to left-most position
            # (sequence, batch, value)
            input_var = input_var.dimshuffle((1,0,2))
            seq_map = self.get_step_inputs(input_var, mask=mask, additional_inputs=additional_inputs)
        else:
            init_state_map[self.main_state] = input_var
            seq_map = self.get_step_inputs(None, mask=mask, additional_inputs=additional_inputs)
        # scan
        retval_map, _ = Scanner(
            self.step,
            sequences=seq_map,
            outputs_info=init_state_map,
            n_steps=steps,
            go_backwards=backward
        ).compute()
        # return main states
        main_states = retval_map[self.main_state]
        if self._output_type == "one":
            return main_states[-1]
        elif self._output_type == "sequence":
            main_states = main_states.dimshuffle((1,0,2)) # ~ batch, time, size
            if mask: # ~ batch, time
                main_states *= mask.dimshuffle((0, 1, 'x'))
            return main_states
dataset/ETHPy150Open zomux/deepy/deepy/layers/recurrent.py/RecurrentLayer.compute_tensor/original