def test_vector_batch_shape_longer_than_matrix_batch_shape(self): batch_shape = [2, 3, 2, 3] for static_batch_shape in [ tf.TensorShape(batch_shape), tf.TensorShape(None)]: with self.test_session(): mat = self._rng.rand(2, 3, 4, 6) vec = operator_pd._flip_matrix_to_vector( mat, batch_shape, static_batch_shape) vec_v = vec.eval() self.assertAllEqual((2, 3, 2, 3, 4), vec_v.shape)
def test_matrix_and_vector_batch_shapes_same_rank_but_permuted(self): batch_shape = [6, 3, 2] for static_batch_shape in [ tf.TensorShape(batch_shape), tf.TensorShape(None)]: with self.test_session(): mat = self._rng.rand(2, 3, 4, 6) vec = operator_pd._flip_matrix_to_vector( mat, batch_shape, static_batch_shape) vec_v = vec.eval() self.assertAllEqual((6, 3, 2, 4), vec_v.shape)
def test_matrix_batch_shape_has_a_singleton_that_vec_batch_shape_doesnt(self): batch_shape = [6, 3] for static_batch_shape in [ tf.TensorShape(batch_shape), tf.TensorShape(None)]: with self.test_session(): mat = self._rng.rand(1, 3, 4, 6) vec = operator_pd._flip_matrix_to_vector( mat, batch_shape, static_batch_shape) vec_v = vec.eval() self.assertAllEqual((6, 3, 4), vec_v.shape) self.assertAllEqual(mat[0, 2, 3, 4], vec_v[4, 2, 3])
def test_vector_batch_shape_longer_than_matrix_batch_shape(self): batch_shape = [2, 3, 2, 3] for static_batch_shape in [ tf.TensorShape(batch_shape), tf.TensorShape(None) ]: with self.test_session(): mat = self._rng.rand(2, 3, 4, 6) vec = operator_pd._flip_matrix_to_vector( mat, batch_shape, static_batch_shape) vec_v = vec.eval() self.assertAllEqual((2, 3, 2, 3, 4), vec_v.shape)
def test_matrix_and_vector_batch_shapes_same_rank_but_permuted(self): batch_shape = [6, 3, 2] for static_batch_shape in [ tf.TensorShape(batch_shape), tf.TensorShape(None) ]: with self.test_session(): mat = self._rng.rand(2, 3, 4, 6) vec = operator_pd._flip_matrix_to_vector( mat, batch_shape, static_batch_shape) vec_v = vec.eval() self.assertAllEqual((6, 3, 2, 4), vec_v.shape)
def test_matrix_batch_shape_has_a_singleton_that_vec_batch_shape_doesnt( self): batch_shape = [6, 3] for static_batch_shape in [ tf.TensorShape(batch_shape), tf.TensorShape(None) ]: with self.test_session(): mat = self._rng.rand(1, 3, 4, 6) vec = operator_pd._flip_matrix_to_vector( mat, batch_shape, static_batch_shape) vec_v = vec.eval() self.assertAllEqual((6, 3, 4), vec_v.shape) self.assertAllEqual(mat[0, 2, 3, 4], vec_v[4, 2, 3])