Don't segfault if unable to convert non-rectangular inputs to tensor
PiperOrigin-RevId: 216738986
This commit is contained in:
parent
028410c7f4
commit
55cf8c0db7
@ -347,6 +347,13 @@ class TFETensorUtilTest(test_util.TensorFlowTestCase):
|
|||||||
instance_dir.remove("test_attr")
|
instance_dir.remove("test_attr")
|
||||||
self.assertEqual(instance_dir, type_dir)
|
self.assertEqual(instance_dir, type_dir)
|
||||||
|
|
||||||
|
def testNonRectangularPackAsConstant(self):
|
||||||
|
l = [array_ops.zeros((10, 1)).numpy(), array_ops.zeros(1).numpy()]
|
||||||
|
|
||||||
|
with self.assertRaisesRegexp(
|
||||||
|
ValueError, "non-rectangular Python sequence"):
|
||||||
|
constant_op.constant(l)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test.main()
|
test.main()
|
||||||
|
@ -220,6 +220,7 @@ const char ErrorFoundFloat[] =
|
|||||||
/* Iterate over outer dim, and recursively convert each element. */ \
|
/* Iterate over outer dim, and recursively convert each element. */ \
|
||||||
const int64 s = shape.dim_size(0); \
|
const int64 s = shape.dim_size(0); \
|
||||||
Safe_PyObjectPtr seq = make_safe(PySequence_Fast(obj, "")); \
|
Safe_PyObjectPtr seq = make_safe(PySequence_Fast(obj, "")); \
|
||||||
|
if (TF_PREDICT_FALSE(seq == nullptr)) return ErrorRectangular; \
|
||||||
if (TF_PREDICT_FALSE(s != PySequence_Fast_GET_SIZE(seq.get()))) { \
|
if (TF_PREDICT_FALSE(s != PySequence_Fast_GET_SIZE(seq.get()))) { \
|
||||||
return ErrorRectangular; \
|
return ErrorRectangular; \
|
||||||
} \
|
} \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user