"The first dimension of paddings must be the rank of inputs",
in1.shape().DebugString(), " ", in0.shape().DebugString()));
- T pad_value(0);
+ T pad_value = T();
if (context->num_inputs() == 3) {
const Tensor& constant_values = context->input(2);
OP_REQUIRES(
PadOp<CPUDevice, type, int64>);
TF_CALL_POD_TYPES(REGISTER_KERNEL);
+TF_CALL_string(REGISTER_KERNEL);
#undef REGISTER_KERNEL
#if GOOGLE_CUDA
x = np.random.rand(3, 2, 1, 1).astype(t)
self._testAll(x + 1j * x, [[0, 0], [0, 0], [0, 0], [0, 0]], 0 + 0j)
+ def testString(self):
+ # Numpy does not support padding strings so we compare padding manually.
+ x = ops.convert_to_tensor([["Hello", "World"],
+ ["Goodnight", "Moon"]])
+
+ constant = array_ops.pad(x, [[1, 0], [0, 1]], mode="CONSTANT",
+ constant_values="PAD")
+ reflect = array_ops.pad(x, [[1, 0], [0, 1]], mode="REFLECT",
+ constant_values="PAD")
+ symmetric = array_ops.pad(x, [[1, 0], [0, 1]], mode="SYMMETRIC",
+ constant_values="PAD")
+ with self.test_session(use_gpu=True):
+ self.assertAllEqual([[b"PAD", b"PAD", b"PAD"],
+ [b"Hello", b"World", b"PAD"],
+ [b"Goodnight", b"Moon", b"PAD"]], constant.eval())
+ self.assertAllEqual([[b"Goodnight", b"Moon", b"Goodnight"],
+ [b"Hello", b"World", b"Hello"],
+ [b"Goodnight", b"Moon", b"Goodnight"]],
+ reflect.eval())
+ self.assertAllEqual([[b"Hello", b"World", b"World"],
+ [b"Hello", b"World", b"World"],
+ [b"Goodnight", b"Moon", b"Moon"]], symmetric.eval())
+
def testShapeFunctionEdgeCases(self):
# Unknown paddings shape.
inp = constant_op.constant(0.0, shape=[4, 4, 4, 4])