コード例 #1
0
 def body(list_, m):
     list_ = control_flow_ops.cond(
         math_ops.equal(list_ops.tensor_list_length(list_), 0),
         lambda: list_ops.empty_tensor_list(m.shape, m.dtype),
         lambda: list_)
     list_ = list_ops.tensor_list_push_back(list_, m)
     return list_, m
コード例 #2
0
ファイル: list_ops_test.py プロジェクト: aeverall/tensorflow
      def body(i, m, t1):
        t1 = control_flow_ops.cond(
            math_ops.equal(list_ops.tensor_list_length(t1), 0),
            lambda: list_ops.empty_tensor_list(m.shape, m.dtype), lambda: t1)

        t1 = list_ops.tensor_list_push_back(t1, m * i)
        i += 1.0
        return i, m, t1
コード例 #3
0
ファイル: list_ops_test.py プロジェクト: aeverall/tensorflow
 def testTensorListFromTensor(self):
   t = constant_op.constant([1.0, 2.0])
   l = list_ops.tensor_list_from_tensor(t, element_shape=[])
   l, e = list_ops.tensor_list_pop_back(l, element_dtype=dtypes.float32)
   self.assertAllEqual(self.evaluate(e), 2.0)
   l, e = list_ops.tensor_list_pop_back(l, element_dtype=dtypes.float32)
   self.assertAllEqual(self.evaluate(e), 1.0)
   self.assertAllEqual(self.evaluate(list_ops.tensor_list_length(l)), 0)
コード例 #4
0
      def body(i, m, t1):
        t1 = control_flow_ops.cond(
            math_ops.equal(list_ops.tensor_list_length(t1), 0),
            lambda: list_ops.empty_tensor_list(m.shape, m.dtype), lambda: t1)

        t1 = list_ops.tensor_list_push_back(t1, m * i)
        i += 1.0
        return i, m, t1
コード例 #5
0
 def testTensorListFromTensor(self):
     t = constant_op.constant([1.0, 2.0])
     l = list_ops.tensor_list_from_tensor(t, element_shape=scalar_shape())
     l, e = list_ops.tensor_list_pop_back(l, element_dtype=dtypes.float32)
     self.assertAllEqual(self.evaluate(e), 2.0)
     l, e = list_ops.tensor_list_pop_back(l, element_dtype=dtypes.float32)
     self.assertAllEqual(self.evaluate(e), 1.0)
     self.assertAllEqual(self.evaluate(list_ops.tensor_list_length(l)), 0)
コード例 #6
0
 def build_graph(parameters):
     """Build the TensorListLength op testing graph."""
     data = tf.placeholder(dtype=parameters["element_dtype"],
                           shape=[parameters["num_elements"]] +
                           parameters["element_shape"])
     tensor_list = list_ops.tensor_list_from_tensor(
         data, parameters["element_shape"])
     out = list_ops.tensor_list_length(tensor_list)
     return [data], [out]
コード例 #7
0
 def testListFromTensor(self):
   with self.cached_session(), self.test_scope():
     t = constant_op.constant([1.0, 2.0])
     l = list_ops.tensor_list_from_tensor(t, element_shape=[])
     e = list_ops.tensor_list_get_item(l, 0, element_dtype=dtypes.float32)
     self.assertAllEqual(e, 1.0)
     l, e0 = list_ops.tensor_list_pop_back(l, element_dtype=dtypes.float32)
     self.assertAllEqual(e0, 2.0)
     l, e1 = list_ops.tensor_list_pop_back(l, element_dtype=dtypes.float32)
     self.assertAllEqual(e1, 1.0)
     self.assertAllEqual(list_ops.tensor_list_length(l), 0)
コード例 #8
0
 def testListFromTensor(self):
   with self.cached_session(), self.test_scope():
     t = constant_op.constant([1.0, 2.0])
     l = list_ops.tensor_list_from_tensor(t, element_shape=[])
     e = list_ops.tensor_list_get_item(l, 0, element_dtype=dtypes.float32)
     self.assertAllEqual(e, 1.0)
     l, e0 = list_ops.tensor_list_pop_back(l, element_dtype=dtypes.float32)
     self.assertAllEqual(e0, 2.0)
     l, e1 = list_ops.tensor_list_pop_back(l, element_dtype=dtypes.float32)
     self.assertAllEqual(e1, 1.0)
     self.assertAllEqual(list_ops.tensor_list_length(l), 0)
コード例 #9
0
def dynamic_len(list_or_tensor):
  """Implementation of len using dynamic dispatch."""
  if _is_tensor_list(list_or_tensor):
    return list_ops.tensor_list_length(list_or_tensor)
  elif tensor_util.is_tensor(list_or_tensor):
    shape = list_or_tensor.shape
    if not shape.ndims:
      raise ValueError(
          'len requires non-zero rank for tensor "%s"' % list_or_tensor)
    return array_ops.shape(list_or_tensor)[0]
  return len(list_or_tensor)
コード例 #10
0
ファイル: list_ops_test.py プロジェクト: aeverall/tensorflow
 def testUnevenSplit(self):
   l = list_ops.tensor_list_split([1., 2., 3., 4., 5],
                                  element_shape=None,
                                  lengths=[3, 2])
   self.assertAllEqual(list_ops.tensor_list_length(l), 2)
   self.assertAllEqual(
       list_ops.tensor_list_get_item(l, 0, element_dtype=dtypes.float32),
       [1., 2., 3.])
   self.assertAllEqual(
       list_ops.tensor_list_get_item(l, 1, element_dtype=dtypes.float32),
       [4., 5.])
コード例 #11
0
ファイル: data_structures.py プロジェクト: PavelToropynya/my
def _tf_tensor_list_append(list_, x):
  """Overload of list_append that stages a Tensor list write."""
  def empty_list_of_elements_like_x():
    tensor_x = ops.convert_to_tensor(x)
    return list_ops.empty_tensor_list(
        element_shape=array_ops.shape(tensor_x),
        element_dtype=tensor_x.dtype)

  list_ = control_flow_ops.cond(
      list_ops.tensor_list_length(list_) > 0,
      lambda: list_,
      empty_list_of_elements_like_x,
  )
  return list_ops.tensor_list_push_back(list_, x)
コード例 #12
0
ファイル: list_ops_test.py プロジェクト: aeverall/tensorflow
 def body(list_, m):
   list_ = control_flow_ops.cond(
       math_ops.equal(list_ops.tensor_list_length(list_), 0),
       lambda: list_ops.empty_tensor_list(m.shape, m.dtype), lambda: list_)
   list_ = list_ops.tensor_list_push_back(list_, m)
   return list_, m
コード例 #13
0
 def count(self):
   return list_ops.tensor_list_length(self.list_)
コード例 #14
0
def _tf_tensor_list_len(s):
  return list_ops.tensor_list_length(s)
コード例 #15
0
def _tf_tensor_list_len(s):
  return list_ops.tensor_list_length(s)
コード例 #16
0
 def size(self, name=None):
   """See TensorArray."""
   return list_ops.tensor_list_length(input_handle=self._flow, name=name)
コード例 #17
0
 def size(self, name=None):
   """See TensorArray."""
   return list_ops.tensor_list_length(input_handle=self._flow, name=name)
コード例 #18
0
ファイル: tensor_list.py プロジェクト: AndrewTwinz/tensorflow
 def count(self):
   return list_ops.tensor_list_length(self.list_)