parameters: (fn, elems, initializer=None, parallel_iterations=10, back_prop=True,
            swap_memory=False, name=None)
docstring: foldl on the list of tensors unpacked from `elems` on dimension 0.
  
    This foldl operator repeatedly applies the callable `fn` to a sequence
    of elements from first to last. The elements are made of the tensors
    unpacked from `elems` on dimension 0. The callable fn takes two tensors as
    arguments. The first argument is the accumulated value computed from the
    preceding invocation of fn. If `initializer` is None, `elems` must contain
    at least one element, and its first element is used as the initializer.
  
    Suppose that `elems` is unpacked into `values`, a list of tensors. The shape
    of the result tensor is fn(initializer, values[0]).shape`.
  
    Args:
      fn: The callable to be performed.
      elems: A tensor to be unpacked on dimension 0.
      initializer: (optional) The initial value for the accumulator.
      parallel_iterations: (optional) The number of iterations allowed to run
        in parallel.
      back_prop: (optional) True enables support for back propagation.
      swap_memory: (optional) True enables GPU-CPU memory swapping.
      name: (optional) Name prefix for the returned tensors.
  
    Returns:
      A tensor resulting from applying `fn` consecutively to the list of tensors
      unpacked from `elems`, from first to last.
  
    Raises:
      TypeError: if `fn` is not callable.
  
    Example:
      ```python
      elems = [1, 2, 3, 4, 5, 6]
      sum = foldl(lambda a, x: a + x, elems)
      # sum == 21
      ```
docstring_summary: foldl on the list of tensors unpacked from `elems` on dimension 0.
docstring_tokens: foldl on the list of tensors unpacked from elems on dimension 0 .
function: def foldl(fn, elems, initializer=None, parallel_iterations=10, back_prop=True,
            swap_memory=False, name=None):
    """foldl on the list of tensors unpacked from `elems` on dimension 0.
  
    This foldl operator repeatedly applies the callable `fn` to a sequence
    of elements from first to last. The elements are made of the tensors
    unpacked from `elems` on dimension 0. The callable fn takes two tensors as
    arguments. The first argument is the accumulated value computed from the
    preceding invocation of fn. If `initializer` is None, `elems` must contain
    at least one element, and its first element is used as the initializer.
  
    Suppose that `elems` is unpacked into `values`, a list of tensors. The shape
    of the result tensor is fn(initializer, values[0]).shape`.
  
    Args:
      fn: The callable to be performed.
      elems: A tensor to be unpacked on dimension 0.
      initializer: (optional) The initial value for the accumulator.
      parallel_iterations: (optional) The number of iterations allowed to run
        in parallel.
      back_prop: (optional) True enables support for back propagation.
      swap_memory: (optional) True enables GPU-CPU memory swapping.
      name: (optional) Name prefix for the returned tensors.
  
    Returns:
      A tensor resulting from applying `fn` consecutively to the list of tensors
      unpacked from `elems`, from first to last.
  
    Raises:
      TypeError: if `fn` is not callable.
  
    Example:
      ```python
      elems = [1, 2, 3, 4, 5, 6]
      sum = foldl(lambda a, x: a + x, elems)
      # sum == 21
      ```
    """
    if not callable(fn):
      raise TypeError("fn must be callable.")
  
    with ops.name_scope(name, "foldl", [elems]):
      # Any get_variable calls in fn will cache the first call locally
      # and not issue repeated network I/O requests for each iteration.
      varscope = vs.get_variable_scope()
      varscope_caching_device_was_none = False
      if varscope.caching_device is None:
        # TODO(ebrevdo): Change to using colocate_with here and in other methods.
        varscope.set_caching_device(lambda op: op.device)
        varscope_caching_device_was_none = True
  
      # Convert elems to tensor array.
      elems = ops.convert_to_tensor(elems, name="elems")
      n = array_ops.shape(elems)[0]
      elems_ta = tensor_array_ops.TensorArray(dtype=elems.dtype, size=n,
                                              dynamic_size=False,
                                              infer_shape=True)
      elems_ta = elems_ta.unstack(elems)
  
      if initializer is None:
        a = elems_ta.read(0)
        i = constant_op.constant(1)
      else:
        a = ops.convert_to_tensor(initializer)
        i = constant_op.constant(0)
  
      def compute(i, a):
        a = fn(a, elems_ta.read(i))
        return [i + 1, a]
      _, r_a = control_flow_ops.while_loop(
          lambda i, a: i < n, compute, [i, a],
          parallel_iterations=parallel_iterations,
          back_prop=back_prop,
          swap_memory=swap_memory)
  
      if varscope_caching_device_was_none:
        varscope.set_caching_device(None)
      return r_a
function_tokens: def foldl ( fn , elems , initializer = None , parallel_iterations = 10 , back_prop = True , swap_memory = False , name = None ) : if not callable ( fn ) : raise TypeError ( "fn must be callable." ) with ops . name_scope ( name , "foldl" , [ elems ] ) : # Any get_variable calls in fn will cache the first call locally # and not issue repeated network I/O requests for each iteration. varscope = vs . get_variable_scope ( ) varscope_caching_device_was_none = False if varscope . caching_device is None : # TODO(ebrevdo): Change to using colocate_with here and in other methods. varscope . set_caching_device ( lambda op : op . device ) varscope_caching_device_was_none = True # Convert elems to tensor array. elems = ops . convert_to_tensor ( elems , name = "elems" ) n = array_ops . shape ( elems ) [ 0 ] elems_ta = tensor_array_ops . TensorArray ( dtype = elems . dtype , size = n , dynamic_size = False , infer_shape = True ) elems_ta = elems_ta . unstack ( elems ) if initializer is None : a = elems_ta . read ( 0 ) i = constant_op . constant ( 1 ) else : a = ops . convert_to_tensor ( initializer ) i = constant_op . constant ( 0 ) def compute ( i , a ) : a = fn ( a , elems_ta . read ( i ) ) return [ i + 1 , a ] _ , r_a = control_flow_ops . while_loop ( lambda i , a : i < n , compute , [ i , a ] , parallel_iterations = parallel_iterations , back_prop = back_prop , swap_memory = swap_memory ) if varscope_caching_device_was_none : varscope . set_caching_device ( None ) return r_a