parameters: (input_context, input_sequences, num_unroll)
docstring: Moves `SparseTensor`s from `input_context` into `input_sequences` as seq.
  
    For `key, value` pairs in `input_context` with `SparseTensor` `value` removes
    them from `input_context` and transforms the `value` into a sequence and
    then adding `key`, transformed `value` into `input_seuqences`.
    The transformation is done by adding a new first dimension of `value_length`
    equal to that of the other values in input_sequences` and tiling the `value`
    every `num_unroll` steps.
  
    Args:
      input_context: dictionary with `Tensor` or `SparseTensor` values. To be
        modified to take out `SparseTensor` values.
      input_sequences: dictionary with `Tensor` or `SparseTensor` values. To be
        modified to add transformed `SparseTensor` values from `input_context`.
      num_unroll: int specifying to what multiple to pad sequences to.
docstring_summary: Moves `SparseTensor`s from `input_context` into `input_sequences` as seq.
docstring_tokens: Moves SparseTensor s from input_context into input_sequences as seq .
function: def _move_sparse_tensor_out_context(input_context, input_sequences, num_unroll):
    """Moves `SparseTensor`s from `input_context` into `input_sequences` as seq.
  
    For `key, value` pairs in `input_context` with `SparseTensor` `value` removes
    them from `input_context` and transforms the `value` into a sequence and
    then adding `key`, transformed `value` into `input_seuqences`.
    The transformation is done by adding a new first dimension of `value_length`
    equal to that of the other values in input_sequences` and tiling the `value`
    every `num_unroll` steps.
  
    Args:
      input_context: dictionary with `Tensor` or `SparseTensor` values. To be
        modified to take out `SparseTensor` values.
      input_sequences: dictionary with `Tensor` or `SparseTensor` values. To be
        modified to add transformed `SparseTensor` values from `input_context`.
      num_unroll: int specifying to what multiple to pad sequences to.
    """
    value_length = array_ops.constant(1)
    if input_sequences:
      seq = list(input_sequences.values())[0]
      if isinstance(seq, ops.Tensor):
        value_length = array_ops.shape(seq)[0]
      else:
        value_length = seq.dense_shape[0]
    value_length = math_ops.cast(value_length, dtype=dtypes.int64)
    def _copy_sparse_tensor(sp_tensor):
      """Operation to tile a sparse tensor along a newly added 0 dimension.
  
      Adding a new first dimension of `value_length` and tiling the `sp_tensor`
      every `num_unroll` steps.
  
      Args:
        sp_tensor: `SparseTensor`.
      Returns:
        `SparseTensor` sequence with `sp_tensor` tiled.
      """
      n = value_length // num_unroll
      n = math_ops.cast(n, dtype=dtypes.int32)
      values = array_ops.tile(sp_tensor.values, array_ops.expand_dims(n, 0))
      shape = array_ops.concat(
          [array_ops.expand_dims(value_length, 0), sp_tensor.dense_shape], 0)
  
      # Construct new indices by multiplying old ones and prepending [0, n).
      # First multiply indices n times along a newly created 0-dimension.
      multiplied_indices = array_ops.tile(
          array_ops.expand_dims(sp_tensor.indices, 0),
          array_ops.stack([n, 1, 1]))
  
      # Construct indicator for [0, n).
      # [ [ [0] [0] ... [0] ]
      #   [ [num_unroll] [num_unroll] ... [num_unroll] ]
      #     ...
      #   [ [num_unroll*(n-1)] [num_unroll*(n-1)] ... [num_unroll*(n-1)] ] ]
      # of shape [n, shape(sp_tensor.indices)[0], 1]
      # Get current dimensions of indices.
      dim0 = array_ops.shape(sp_tensor.indices)[0]
      dim1 = array_ops.shape(sp_tensor.indices)[1]
      ind = math_ops.range(start=0, limit=value_length, delta=num_unroll)
  
      # ind.set_shape([n])
      ind = array_ops.expand_dims(ind, 1)
      ind = array_ops.expand_dims(ind, 2)
      ind = array_ops.tile(ind, [1, dim0, 1])
  
      # Concatenate both and reshape.
      indices = array_ops.concat([ind, multiplied_indices], 2)
      indices = array_ops.reshape(indices, [dim0 * n, dim1 + 1])
  
      return sparse_tensor.SparseTensor(indices=indices,
                                        values=values,
                                        dense_shape=shape)
  
    sparse_tensor_keys = [
        k for k in sorted(input_context.keys())
        if (isinstance(input_context[k], sparse_tensor.SparseTensor) or
            isinstance(input_context[k], sparse_tensor.SparseTensorValue))]
    for key in sparse_tensor_keys:
      input_sequences[_SPARSE_CONTEXT_PREFIX_KEY + key] = _copy_sparse_tensor(
          input_context[key])
      del input_context[key]
function_tokens: def _move_sparse_tensor_out_context ( input_context , input_sequences , num_unroll ) : value_length = array_ops . constant ( 1 ) if input_sequences : seq = list ( input_sequences . values ( ) ) [ 0 ] if isinstance ( seq , ops . Tensor ) : value_length = array_ops . shape ( seq ) [ 0 ] else : value_length = seq . dense_shape [ 0 ] value_length = math_ops . cast ( value_length , dtype = dtypes . int64 ) def _copy_sparse_tensor ( sp_tensor ) : """Operation to tile a sparse tensor along a newly added 0 dimension.
  
      Adding a new first dimension of `value_length` and tiling the `sp_tensor`
      every `num_unroll` steps.
  
      Args:
        sp_tensor: `SparseTensor`.
      Returns:
        `SparseTensor` sequence with `sp_tensor` tiled.
      """ n = value_length // num_unroll n = math_ops . cast ( n , dtype = dtypes . int32 ) values = array_ops . tile ( sp_tensor . values , array_ops . expand_dims ( n , 0 ) ) shape = array_ops . concat ( [ array_ops . expand_dims ( value_length , 0 ) , sp_tensor . dense_shape ] , 0 ) # Construct new indices by multiplying old ones and prepending [0, n). # First multiply indices n times along a newly created 0-dimension. multiplied_indices = array_ops . tile ( array_ops . expand_dims ( sp_tensor . indices , 0 ) , array_ops . stack ( [ n , 1 , 1 ] ) ) # Construct indicator for [0, n). # [ [ [0] [0] ... [0] ] #   [ [num_unroll] [num_unroll] ... [num_unroll] ] #     ... #   [ [num_unroll*(n-1)] [num_unroll*(n-1)] ... [num_unroll*(n-1)] ] ] # of shape [n, shape(sp_tensor.indices)[0], 1] # Get current dimensions of indices. dim0 = array_ops . shape ( sp_tensor . indices ) [ 0 ] dim1 = array_ops . shape ( sp_tensor . indices ) [ 1 ] ind = math_ops . range ( start = 0 , limit = value_length , delta = num_unroll ) # ind.set_shape([n]) ind = array_ops . expand_dims ( ind , 1 ) ind = array_ops . expand_dims ( ind , 2 ) ind = array_ops . tile ( ind , [ 1 , dim0 , 1 ] ) # Concatenate both and reshape. indices = array_ops . concat ( [ ind , multiplied_indices ] , 2 ) indices = array_ops . reshape ( indices , [ dim0 * n , dim1 + 1 ] ) return sparse_tensor . SparseTensor ( indices = indices , values = values , dense_shape = shape ) sparse_tensor_keys = [ k for k in sorted ( input_context . keys ( ) ) if ( isinstance ( input_context [ k ] , sparse_tensor . SparseTensor ) or isinstance ( input_context [ k ] , sparse_tensor . SparseTensorValue ) ) ] for key in sparse_tensor_keys : input_sequences [ _SPARSE_CONTEXT_PREFIX_KEY + key ] = _copy_sparse_tensor ( input_context [ key ] ) del input_context [ key ]