def test_string(self): def fn(entry_lt): op = string_ops.string_join([entry_lt, 'world']) return core.LabeledTensor(op, []) tensor_lt = ops.constant(['hi', 'bye'], axes=['batch']) map_lt = ops.map_fn(fn, tensor_lt) golden_lt = ops.constant(['hiworld', 'byeworld'], axes=['batch']) self.assertLabeledTensorsEqual(map_lt, golden_lt)
def test_existing_axes(self): golden_lt = core.LabeledTensor(constant_op.constant([1, 2]), ['x']) constant_lt = ops.constant([1, 2], axes=golden_lt.axes) self.assertLabeledTensorsEqual(constant_lt, golden_lt)
def test_specify_shape(self): constant_lt = ops.constant(1, axes=[('x', 3)]) golden_lt = core.LabeledTensor(constant_op.constant(1, shape=(3, )), ['x']) self.assertLabeledTensorsEqual(constant_lt, golden_lt)
def test_infer_shape(self): constant_lt = ops.constant([1, 2], axes=['x']) golden_lt = core.LabeledTensor(constant_op.constant([1, 2]), ['x']) self.assertLabeledTensorsEqual(constant_lt, golden_lt)
def test_scalar(self): constant_lt = ops.constant(1) golden_lt = core.LabeledTensor(constant_op.constant(1), []) self.assertLabeledTensorsEqual(constant_lt, golden_lt)
def test_name(self): constant_lt = ops.constant(1) self.assertIn('lt_constant', constant_lt.name)
def test_specify_shape(self): constant_lt = ops.constant(1, axes=[('x', 3)]) golden_lt = core.LabeledTensor(constant_op.constant(1, shape=(3,)), ['x']) self.assertLabeledTensorsEqual(constant_lt, golden_lt)
def test_sum(self): initializer_lt = ops.constant([0, 10], axes=['y']) tensor_lt = ops.constant([[1, 2], [3, 4], [5, 6]], axes=['x', 'y']) foldl_lt = ops.foldl(core.add, tensor_lt, initializer_lt) golden_lt = ops.constant([9, 22], axes=['y']) self.assertLabeledTensorsEqual(foldl_lt, golden_lt)