def test_tensor_conversion(self):
with BayesianNet(observed={'a': 1., 'c': 1.}):
a = StochasticTensor('a', Mock(dtype=tf.float32), 1)
b = tf.add(1., a)
c = StochasticTensor('c', Mock(dtype=tf.float32), 1)
# tensorflow will try to convert c to the same type with 1 (int32)
# calling the registered tensor conversion function of c.
# If failed, it will try not to request the type. So an error
# will be raised by the operator.
with self.assertRaisesRegexp(
TypeError, "type float32.*not match.*type int32"):
_ = tf.add(1, c)
with self.test_session(use_gpu=True):
self.assertNear(b.eval(), 2., 1e-6)
with self.assertRaisesRegexp(ValueError, "Ref type not supported"):
_ = StochasticTensor._to_tensor(a, as_ref=True)
评论列表
文章目录