Ejemplo n.º 1
0
    def test_set_attributes(self):
        t = StochasticTensor(self.distrib, tf.constant([1., 2., 3.]))

        self.assertTrue(hasattr(t, '_self_is_observed'))
        self.assertFalse(hasattr(t.__wrapped__, '_self_is_observed'))
        t._self_is_observed = 123
        self.assertEqual(t._self_is_observed, 123)
        self.assertFalse(hasattr(t.__wrapped__, '_self_is_observed'))

        self.assertTrue(hasattr(t, 'log_prob'))
        self.assertFalse(hasattr(t.__wrapped__, 'log_prob'))
        t.log_prob = 456
        self.assertEqual(t.log_prob, 456)
        self.assertTrue(hasattr(t, 'log_prob'))
        self.assertFalse(hasattr(t.__wrapped__, 'log_prob'))

        self.assertTrue(hasattr(t, 'get_shape'))
        self.assertTrue(hasattr(t.__wrapped__, 'get_shape'))
        t.get_shape = 789
        self.assertEqual(t.get_shape, 789)
        self.assertEqual(t.__wrapped__.get_shape, 789)
        self.assertTrue(hasattr(t, 'get_shape'))
        self.assertTrue(hasattr(t.__wrapped__, 'get_shape'))

        t.abc = 1001
        self.assertEqual(t.abc, 1001)
        self.assertEqual(t.__wrapped__.abc, 1001)
        self.assertTrue(hasattr(t, 'abc'))
        self.assertTrue(hasattr(t.__wrapped__, 'abc'))

        t.__wrapped__.xyz = 2002
        self.assertEqual(t.xyz, 2002)
        self.assertEqual(t.__wrapped__.xyz, 2002)
        self.assertTrue(hasattr(t, 'xyz'))
        self.assertTrue(hasattr(t.__wrapped__, 'xyz'))
Ejemplo n.º 2
0
 def test_dynamic_dimension_replaced_by_observed_shape(self):
     distrib = _MyDistribution(tf.placeholder(tf.float32, (None, 3, 4)))
     t = StochasticTensor(
         distrib,
         observed=tf.placeholder(tf.float32, (2, 3, None))
     )
     self.assertEqual(t.get_shape().as_list(), [2, 3, None])