def testTensorArrayPackNotAllValuesAvailableFails(self):
    with self.test_session():
      h = gen_data_flow_ops._tensor_array(
          dtype=tf.float32, tensor_array_name="foo", size=3)

      with self.assertRaisesOpError(
          "Could not read from TensorArray index 1 "
          "because it has not yet been written to."):
        with tf.control_dependencies([
            gen_data_flow_ops._tensor_array_write(h, 0, [[4.0, 5.0]])]):
          gen_data_flow_ops._tensor_array_pack(h, tf.float32).eval()
Beispiel #2
0
    def pack(self, name=None):
        """Return the values in the TensorArray as a packed `Tensor`.

    All of the values must have been written and their shapes must all match.

    Args:
      name: A name for the operation (optional).

    Returns:
      All the tensors in the TensorArray packed into one tensor.
    """
        with ops.colocate_with(self._handle):
            if self._elem_shape:
                element_shape = self._elem_shape[0]
            else:
                element_shape = tensor_shape.TensorShape(None)
            value = gen_data_flow_ops._tensor_array_pack(
                handle=self._handle,
                flow_in=self._flow,
                dtype=self._dtype,
                name=name,
                element_shape=element_shape)
            if self._elem_shape and self._elem_shape[0].dims is not None:
                value.set_shape([None] + self._elem_shape[0].dims)
            return value
Beispiel #3
0
  def pack(self, name=None):
    """Return the values in the TensorArray as a packed `Tensor`."""
    value = gen_data_flow_ops._tensor_array_pack(
        handle=self._handle, flow_in=self._flow, dtype=self._dtype,
        name=name)

    return value
  def _legacy_pack(self, name=None):
    """Return the values in the TensorArray as a packed `Tensor`.

    This is the legacy version of pack, kept for testing
    backwards compatibility.

    All of the values must have been written and their shapes must all match.

    Args:
      name: A name for the operation (optional).

    Returns:
      All the tensors in the TensorArray packed into one tensor.
    """
    with ops.colocate_with(self._handle):
      if self._elem_shape:
        element_shape = self._elem_shape[0]
      else:
        element_shape = tensor_shape.TensorShape(None)
      value = gen_data_flow_ops._tensor_array_pack(handle=self._handle,
                                                   flow_in=self._flow,
                                                   dtype=self._dtype,
                                                   name=name,
                                                   element_shape=element_shape)
      if self._elem_shape and self._elem_shape[0].dims is not None:
        value.set_shape([None] + self._elem_shape[0].dims)
      return value
Beispiel #5
0
  def pack(self, name=None):
    """Return the values in the TensorArray as a packed `Tensor`."""
    value = gen_data_flow_ops._tensor_array_pack(
        handle=self._handle, flow_in=self._flow, dtype=self._dtype,
        name=name)

    return value
Beispiel #6
0
    def pack(self, name=None):
        """Return the values in the TensorArray as a packed `Tensor`.

    All of the values must have been written and their shapes must all match.

    Args:
      name: A name for the operation (optional).

    Returns:
      All the tensors in the TensorArray packed into one tensor.
    """
        with ops.colocate_with(self._handle):
            value = gen_data_flow_ops._tensor_array_pack(
                handle=self._handle, flow_in=self._flow, dtype=self._dtype, name=name
            )

            return value
Beispiel #7
0
    def pack(self, name=None):
        """Return the values in the TensorArray as a packed `Tensor`.

    All of the values must have been written and their shapes must all match.

    Args:
      name: A name for the operation (optional).

    Returns:
      All the tensors in the TensorArray packed into one tensor.
    """
        with ops.colocate_with(self._handle):
            value = gen_data_flow_ops._tensor_array_pack(handle=self._handle,
                                                         flow_in=self._flow,
                                                         dtype=self._dtype,
                                                         name=name)

            return value
  def _testTensorArrayWritePack(self, tf_dtype, use_gpu):
    dtype = tf_dtype.as_numpy_dtype()
    with self.test_session(use_gpu=use_gpu):
      h = gen_data_flow_ops._tensor_array(
          dtype=tf_dtype, tensor_array_name="foo", size=3)

      if tf_dtype == tf.string:
        convert = lambda x: np.asarray(x).astype(np.str)
      else:
        convert = lambda x: np.asarray(x).astype(dtype)

      writes = [
          gen_data_flow_ops._tensor_array_write(h, 0, convert([[4.0, 5.0]])),
          gen_data_flow_ops._tensor_array_write(h, 1, convert([[6.0, 7.0]])),
          gen_data_flow_ops._tensor_array_write(h, 2, convert([[8.0, 9.0]]))]

      with tf.control_dependencies(writes):
        c0 = gen_data_flow_ops._tensor_array_pack(h, tf_dtype)

      self.assertAllEqual(
          convert([[[4.0, 5.0]], [[6.0, 7.0]], [[8.0, 9.0]]]), c0.eval())