class_docstr: Sequence layer stacking the current and previous inputs; can only be used as preprocessing
  layer (specification key: `sequence`).
  
  Args:
      length (int > 0): Number of inputs to concatenate
          (<span style="color:#C00000"><b>required</b></span>).
      axis (int >= 0): Concatenation axis, excluding batch axis
          (<span style="color:#00C000"><b>default</b></span>: last axis).
      concatenate (bool): Whether to concatenate inputs at given axis, otherwise introduce new
          sequence axis
          (<span style="color:#00C000"><b>default</b></span>: true).
      name (string): Layer name
          (<span style="color:#00C000"><b>default</b></span>: internally chosen).
      input_spec (specification): <span style="color:#00C000"><b>internal use</b></span>.
class_docstr_tok: ["Sequence","layer","stacking","the","current","and","previous","inputs",";","can","only","be","used","as","preprocessing","layer","(","specification","key",":","`","sequence","`",")",".","Args",":","length","(","int",">","0",")",":","Number","of","inputs","to","concatenate","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">",")",".","axis","(","int",">","=","0",")",":","Concatenation","axis",",","excluding","batch","axis","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","last","axis",")",".","concatenate","(","bool",")",":","Whether","to","concatenate","inputs","at","given","axis",",","otherwise","introduce","new","sequence","axis","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","true",")",".","name","(","string",")",":","Layer","name","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","internally","chosen",")",".","input_spec","(","specification",")",":","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","internal","use","<","\/b",">","<","\/span",">","."]
code: def apply(self, *, x):
      assertions = list()
      if self.config.create_tf_assertions:
          assertions.append(
              tf.debugging.assert_less_equal(
                  x=tf.shape(input=x)[0],
                  y=1,
                  message="Sequence preprocessor currently not compatible with batched Agent.act.",
              )
          )
  
      with tf.control_dependencies(control_inputs=assertions):
  
          def empty_batch():
              if self.concatenate:
                  current = x
              else:
                  current = tf.expand_dims(
                      input=x, axis=(self.axis + 1)
                  )
              multiples = tuple(
                  self.length if dims == self.axis + 1 else 1
                  for dims in range(self.output_spec().rank + 1)
              )
              return tf.tile(input=current, multiples=multiples)
  
          def not_empty_batch():
              def first_timestep():
                  assignment = self.has_previous.assign(
                      value=tf_util.constant(value=True, dtype="bool"),
                      read_value=False,
                  )
                  with tf.control_dependencies(
                      control_inputs=(assignment,)
                  ):
                      if self.concatenate:
                          current = x
                      else:
                          current = tf.expand_dims(
                              input=x, axis=(self.axis + 1)
                          )
                      multiples = tuple(
                          self.length if dims == self.axis + 1 else 1
                          for dims in range(self.output_spec().rank + 1)
                      )
                      return tf.tile(input=current, multiples=multiples)
  
              def other_timesteps():
                  if self.concatenate:
                      current = x
                  else:
                      current = tf.expand_dims(
                          input=x, axis=(self.axis + 1)
                      )
                  return tf.concat(
                      values=(self.previous, current),
                      axis=(self.axis + 1),
                  )
  
              xs = tf.cond(
                  pred=self.has_previous,
                  true_fn=other_timesteps,
                  false_fn=first_timestep,
              )
  
              if self.concatenate:
                  begin = tuple(
                      self.input_spec.shape[dims - 1]
                      if dims == self.axis + 1
                      else 0
                      for dims in range(self.output_spec().rank + 1)
                  )
              else:
                  begin = tuple(
                      1 if dims == self.axis + 1 else 0
                      for dims in range(self.output_spec().rank + 1)
                  )
              assignment = self.previous.assign(
                  value=tf.slice(
                      input_=xs, begin=begin, size=self.previous.shape
                  ),
                  read_value=False,
              )
  
              with tf.control_dependencies(
                  control_inputs=(assignment,)
              ):
                  return tf_util.identity(input=xs)
  
          is_empty_batch = tf.math.equal(x=tf.shape(input=x)[0], y=0)
          return tf.cond(
              pred=is_empty_batch,
              true_fn=empty_batch,
              false_fn=not_empty_batch,
          )
  
imports: import tensorflow
  from tensorforce.core import parameter_modules, SignatureDict, TensorSpec, tf_function, tf_util
  from tensorforce.core.layers import Layer
label_desc: Use image node_id 5 for calling the Sequence obj's underlying member method code with example usage: obj.apply() and returns: tf, tf, tf, tf_util, tf