def create():
   return gen_data_flow_ops._tensor_array_v3(
       dtype=dtype,
       size=size,
       element_shape=element_shape,
       dynamic_size=dynamic_size,
       clear_after_read=clear_after_read,
       tensor_array_name=tensor_array_name,
       name=scope)
Esempio n. 2
0
 def create():
     return gen_data_flow_ops._tensor_array_v3(
         dtype=dtype,
         size=size,
         element_shape=element_shape,
         dynamic_size=dynamic_size,
         clear_after_read=clear_after_read,
         tensor_array_name=tensor_array_name,
         name=scope)
 def create():
   """Create the TensorArray op."""
   return gen_data_flow_ops._tensor_array_v3(
       dtype=dtype,
       size=size,
       element_shape=element_shape,
       identical_element_shapes=infer_shape,
       dynamic_size=dynamic_size,
       clear_after_read=clear_after_read,
       tensor_array_name=tensor_array_name,
       name=scope)
 def create():
     """Create the TensorArray op."""
     return gen_data_flow_ops._tensor_array_v3(
         dtype=dtype,
         size=size,
         element_shape=element_shape,
         identical_element_shapes=infer_shape,
         dynamic_size=dynamic_size,
         clear_after_read=clear_after_read,
         tensor_array_name=tensor_array_name,
         name=scope)
Esempio n. 5
0
 def create():
   """Create the TensorArray op."""
   ta_kwargs = {}
   if _ENABLE_IDENTICAL_ELEMENT_SHAPES:
     ta_kwargs["identical_element_shapes"] = infer_shape
   return gen_data_flow_ops._tensor_array_v3(
       dtype=dtype,
       size=size,
       element_shape=element_shape,
       dynamic_size=dynamic_size,
       clear_after_read=clear_after_read,
       tensor_array_name=tensor_array_name,
       name=scope,
       **ta_kwargs)
 def create():
     """Create the TensorArray op."""
     ta_kwargs = {}
     if _ENABLE_IDENTICAL_ELEMENT_SHAPES:
         ta_kwargs["identical_element_shapes"] = infer_shape
     return gen_data_flow_ops._tensor_array_v3(
         dtype=dtype,
         size=size,
         element_shape=element_shape,
         dynamic_size=dynamic_size,
         clear_after_read=clear_after_read,
         tensor_array_name=tensor_array_name,
         name=scope,
         **ta_kwargs)
Esempio n. 7
0
  def __init__(self,
               dtype,
               size=None,
               dynamic_size=None,
               clear_after_read=None,
               tensor_array_name=None,
               handle=None,
               flow=None,
               infer_shape=True,
               element_shape=None,
               name=None):
    """Construct a new TensorArray or wrap an existing TensorArray handle.

    A note about the parameter `name`:

    The name of the `TensorArray` (even if passed in) is uniquified: each time
    a new `TensorArray` is created at runtime it is assigned its own name for
    the duration of the run.  This avoids name collisions if a `TensorArray`
    is created within a `while_loop`.

    Args:
      dtype: (required) data type of the TensorArray.
      size: (optional) int32 scalar `Tensor`: the size of the TensorArray.
        Required if handle is not provided.
      dynamic_size: (optional) Python bool: If true, writes to the TensorArray
        can grow the TensorArray past its initial size.  Default: False.
      clear_after_read: Boolean (optional, default: True).  If True, clear
        TensorArray values after reading them.  This disables read-many
        semantics, but allows early release of memory.
      tensor_array_name: (optional) Python string: the name of the TensorArray.
        This is used when creating the TensorArray handle.  If this value is
        set, handle should be None.
      handle: (optional) A `Tensor` handle to an existing TensorArray.  If this
        is set, tensor_array_name should be None.
      flow: (optional) A float `Tensor` scalar coming from an existing
        `TensorArray.flow`.
      infer_shape: (optional, default: True) If True, shape inference
        is enabled.  In this case, all elements must have the same shape.
      element_shape: (optional, default: None) A `TensorShape` object specifying
        the shape constraints of each of the elements of the TensorArray.
        Need not be fully defined.
      name: A name for the operation (optional).

    Raises:
      ValueError: if both handle and tensor_array_name are provided.
      TypeError: if handle is provided but is not a Tensor.
    """
    if handle is not None and tensor_array_name:
      raise ValueError(
          "Cannot construct with both handle and tensor_array_name")
    if handle is not None and not isinstance(handle, ops.Tensor):
      raise TypeError("Handle must be a Tensor")
    if handle is None and size is None:
      raise ValueError("Size must be provided if handle is not provided")
    if handle is not None and size is not None:
      raise ValueError("Cannot provide both a handle and size "
                       "at the same time")
    if handle is not None and element_shape is not None:
      raise ValueError("Cannot provide both a handle and element_shape "
                       "at the same time")
    if handle is not None and dynamic_size is not None:
      raise ValueError("Cannot provide both a handle and dynamic_size "
                       "at the same time")
    if handle is not None and clear_after_read is not None:
      raise ValueError("Cannot provide both a handle and clear_after_read "
                       "at the same time")

    if clear_after_read is None:
      clear_after_read = True
    dynamic_size = dynamic_size or False

    self._dtype = dtype
    # Record the current static shape for the array elements. The element
    # shape is defined either by `element_shape` or the shape of the tensor
    # of the first write. If `infer_shape` is true, all writes checks for
    # shape equality.
    if element_shape is None:
      self._infer_shape = infer_shape
      self._element_shape = []
    else:
      self._infer_shape = True
      self._element_shape = [tensor_shape.TensorShape(element_shape)]
    with ops.name_scope(name, "TensorArray", [handle, size, flow]) as scope:
      if handle is not None:
        self._handle = handle
        if flow is None:
          raise ValueError("flow must not be None if handle is not None.")
        self._flow = flow
      else:
        # Construct the TensorArray with an empty device.  The first
        # write into the TensorArray from a Tensor with a set device
        # will retroactively set the device value of this op.
        with ops.device(None), ops.colocate_with(None, ignore_existing=True):
          self._handle, self._flow = gen_data_flow_ops._tensor_array_v3(
              dtype=dtype,
              size=size,
              element_shape=element_shape,
              dynamic_size=dynamic_size,
              clear_after_read=clear_after_read,
              tensor_array_name=tensor_array_name,
              name=scope)
Esempio n. 8
0
    def __init__(self,
                 dtype,
                 size=None,
                 dynamic_size=None,
                 clear_after_read=None,
                 tensor_array_name=None,
                 handle=None,
                 flow=None,
                 infer_shape=True,
                 element_shape=None,
                 name=None):
        """Construct a new TensorArray or wrap an existing TensorArray handle.

    A note about the parameter `name`:

    The name of the `TensorArray` (even if passed in) is uniquified: each time
    a new `TensorArray` is created at runtime it is assigned its own name for
    the duration of the run.  This avoids name collisions if a `TensorArray`
    is created within a `while_loop`.

    Args:
      dtype: (required) data type of the TensorArray.
      size: (optional) int32 scalar `Tensor`: the size of the TensorArray.
        Required if handle is not provided.
      dynamic_size: (optional) Python bool: If true, writes to the TensorArray
        can grow the TensorArray past its initial size.  Default: False.
      clear_after_read: Boolean (optional, default: True).  If True, clear
        TensorArray values after reading them.  This disables read-many
        semantics, but allows early release of memory.
      tensor_array_name: (optional) Python string: the name of the TensorArray.
        This is used when creating the TensorArray handle.  If this value is
        set, handle should be None.
      handle: (optional) A `Tensor` handle to an existing TensorArray.  If this
        is set, tensor_array_name should be None.
      flow: (optional) A float `Tensor` scalar coming from an existing
        `TensorArray.flow`.
      infer_shape: (optional, default: True) If True, shape inference
        is enabled.  In this case, all elements must have the same shape.
      element_shape: (optional, default: None) A `TensorShape` object specifying
        the shape constraints of each of the elements of the TensorArray.
        Need not be fully defined.
      name: A name for the operation (optional).

    Raises:
      ValueError: if both handle and tensor_array_name are provided.
      TypeError: if handle is provided but is not a Tensor.
    """
        if handle is not None and tensor_array_name:
            raise ValueError(
                "Cannot construct with both handle and tensor_array_name")
        if handle is not None and not isinstance(handle, ops.Tensor):
            raise TypeError("Handle must be a Tensor")
        if handle is None and size is None:
            raise ValueError("Size must be provided if handle is not provided")
        if handle is not None and size is not None:
            raise ValueError("Cannot provide both a handle and size "
                             "at the same time")
        if handle is not None and element_shape is not None:
            raise ValueError("Cannot provide both a handle and element_shape "
                             "at the same time")
        if handle is not None and dynamic_size is not None:
            raise ValueError("Cannot provide both a handle and dynamic_size "
                             "at the same time")
        if handle is not None and clear_after_read is not None:
            raise ValueError(
                "Cannot provide both a handle and clear_after_read "
                "at the same time")

        if clear_after_read is None:
            clear_after_read = True
        dynamic_size = dynamic_size or False

        self._dtype = dtype
        # Record the current static shape for the array elements. The element
        # shape is defined either by `element_shape` or the shape of the tensor
        # of the first write. If `infer_shape` is true, all writes checks for
        # shape equality.
        if element_shape is None:
            self._infer_shape = infer_shape
            self._element_shape = []
        else:
            self._infer_shape = True
            self._element_shape = [tensor_shape.TensorShape(element_shape)]
        with ops.name_scope(name, "TensorArray",
                            [handle, size, flow]) as scope:
            if handle is not None:
                self._handle = handle
                if flow is None:
                    raise ValueError(
                        "flow must not be None if handle is not None.")
                self._flow = flow
            else:
                # Construct the TensorArray with an empty device.  The first
                # write into the TensorArray from a Tensor with a set device
                # will retroactively set the device value of this op.
                with ops.device(None), ops.colocate_with(None,
                                                         ignore_existing=True):
                    self._handle, self._flow = gen_data_flow_ops._tensor_array_v3(
                        dtype=dtype,
                        size=size,
                        element_shape=element_shape,
                        dynamic_size=dynamic_size,
                        clear_after_read=clear_after_read,
                        tensor_array_name=tensor_array_name,
                        name=scope)