Beispiel #1
0
 def test_to_representation_for_tf_variable(self):
     v = eager_executor.to_representation_for_type(
         tf.Variable(10, dtype=tf.int32),
         type_spec=computation_types.TensorType(tf.int32))
     self.assertIsInstance(v, tf.Tensor)
     self.assertEqual(v.numpy(), 10)
     self.assertEqual(v.dtype, tf.int32)
    def test_to_representation_for_type_succeeds_on_all_devices(self, device):
        @computations.tf_computation(tf.int32)
        def comp(x):
            return tf.add(x, 1)

        comp_proto = computation_impl.ComputationImpl.get_proto(comp)

        fn = eager_executor.to_representation_for_type(
            comp_proto, comp.type_signature, device='/{}'.format(device))
        result = fn(tf.constant(20))
        self.assertTrue(result.device.endswith(device))
 def test_to_representation_for_type_with_int_on_specific_device(self):
     v = eager_executor.to_representation_for_type(10, tf.int32, '/CPU:0')
     self.assertIsInstance(v, tf.Tensor)
     self.assertEqual(v.numpy(), 10)
     self.assertEqual(v.dtype, tf.int32)
     self.assertTrue(v.device.endswith('CPU:0'))
 def test_to_representation_for_type_with_int(self):
     v = eager_executor.to_representation_for_type(10, tf.int32)
     self.assertIsInstance(v, tf.Tensor)
     self.assertEqual(v.numpy(), 10)
     self.assertEqual(v.dtype, tf.int32)