Пример #1
0
 def test_make_diagonal_mostly_defined_shapes(self):
   with self.cached_session():
     mostly_defined = array_ops.placeholder(
         shape=[None, 2], dtype=dtypes.float32)
     blocked = math_utils.block_diagonal([[[2.]],
                                          mostly_defined,
                                          [[7.]]])
     self.assertEqual([None, 4],
                      blocked.get_shape().as_list())
     self.assertAllEqual(
         [[2., 0., 0., 0.],
          [0., 3., 4., 0.],
          [0., 5., 6., 0.],
          [0., 0., 0., 7.]],
         blocked.eval(feed_dict={
             mostly_defined: [[3., 4.],
                              [5., 6.]]}))
Пример #2
0
 def test_make_diagonal_undefined_shapes(self):
   with self.cached_session():
     completely_undefined = array_ops.placeholder(dtype=dtypes.float32)
     partly_undefined = array_ops.placeholder(
         shape=[None, None], dtype=dtypes.float32)
     blocked = math_utils.block_diagonal([completely_undefined,
                                          [[2.]],
                                          partly_undefined])
     self.assertEqual([None, None],
                      blocked.get_shape().as_list())
     self.assertAllEqual(
         [[1., 0., 0., 0.],
          [0., 2., 0., 0.],
          [0., 0., 3., 4.],
          [0., 0., 5., 6.]],
         blocked.eval(feed_dict={
             completely_undefined: [[1.]],
             partly_undefined: [[3., 4.],
                                [5., 6.]]}))