test_base.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:zhusuan 作者: thu-ml 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号