def testDocStringExamples(self): """Example from ragged_to_tensor.__doc__.""" rt = ragged.constant([[9, 8, 7], [], [6, 5], [4]]) dt = ragged.to_tensor(rt) with self.test_session(): self.assertEqual(str(dt.eval()), '[[9 8 7]\n' ' [0 0 0]\n' ' [6 5 0]\n' ' [4 0 0]]') # pyformat: disable
def testRaggedTensorToTensor(self, rt_input, expected, ragged_rank=None, default=None, expected_shape=None): rt = ragged.constant(rt_input, ragged_rank=ragged_rank) dt = ragged.to_tensor(rt, default) self.assertEqual(type(dt), ops.Tensor) self.assertEqual(rt.dtype, dt.dtype) self.assertTrue(dt.shape.is_compatible_with(rt.shape)) with self.test_session(): self.assertEqual(dt.eval().tolist(), expected) if expected_shape is not None: dt_shape = array_ops.shape(dt) self.assertEqual(dt_shape.eval().tolist(), expected_shape)
def testError(self, rt_input, default, error, ragged_rank=None): rt = ragged.constant(rt_input, ragged_rank=ragged_rank) with self.assertRaisesRegexp(error[0], error[1]): ragged.to_tensor(rt, default)