Beispiel #1
0
 def test_list_index_python(self):
     with context.eager_mode():
         a = constant(3.0)
         b = constant(2.0)
         l = tl.TensorList(a.shape, a.dtype)
         l.append(a)
         self.assertEqual(l[0].numpy(), a.numpy())
         l[0] = ops.convert_to_tensor(b)
         self.assertEqual(l[0].numpy(), b.numpy())
Beispiel #2
0
 def test_list_index_tf(self):
     a = constant(3.0)
     b = constant(2.0)
     l = tl.TensorList(a.shape, a.dtype)
     l.append(a)
     l0 = l[0]
     l[0] = b
     l1 = l[0]
     with self.test_session() as sess:
         l0, l1, a, b = sess.run([l0, l1, a, b])
         self.assertEqual(l0, a)
         self.assertEqual(l1, b)
Beispiel #3
0
 def test_list_append_python(self):
     with context.eager_mode():
         a = constant(3.0)
         l = tl.TensorList(a.shape, a.dtype)
         l.append(a)
         self.assertEqual(l.count().numpy(), 1)
         l.append(a)
         self.assertEqual(l.count().numpy(), 2)
         _ = l.pop()
         self.assertEqual(l.count().numpy(), 1)
         a2 = l.pop()
         self.assertEqual(l.count().numpy(), 0)
         self.assertEqual(a.numpy(), a2.numpy())
Beispiel #4
0
 def test_list_append_tf(self):
     a = constant(3.0)
     l = tl.TensorList(a.shape, a.dtype)
     l.append(a)
     c1 = l.count()
     l.append(a)
     c2 = l.count()
     _ = l.pop()
     c3 = l.count()
     a2 = l.pop()
     c4 = l.count()
     with Session() as sess:
         c1, c2, c3, c4, a, a2 = sess.run([c1, c2, c3, c4, a, a2])
         self.assertEqual(c1, 1)
         self.assertEqual(c2, 2)
         self.assertEqual(c3, 1)
         self.assertEqual(c4, 0)
         self.assertEqual(a, a2)
Beispiel #5
0
    def test_dynamic_list_append(self):
        l = []
        l = tl.dynamic_list_append(l, 1)
        self.assertListEqual(l, [1])

        l = list_ops.empty_tensor_list(self._shape(()), dtypes.int32)
        l = tl.dynamic_list_append(l, 1)
        s = list_ops.tensor_list_stack(l, element_dtype=dtypes.int32)
        with self.test_session() as sess:
            self.assertAllEqual(sess.run(s), [1])

        l = tensor_array_ops.TensorArray(dtypes.int32,
                                         size=0,
                                         dynamic_size=True)
        l = tl.dynamic_list_append(l, 1)
        s = l.stack()
        with self.test_session() as sess:
            self.assertAllEqual(sess.run(s), [1])

        l = tl.TensorList(self._shape(()), dtypes.int32)
        l = tl.dynamic_list_append(l, 1)
        with self.test_session() as sess:
            self.assertAllEqual(sess.run(l[0]), 1)