Merge pull request #40674 from lgeiger:numpy-tostring

PiperOrigin-RevId: 317735359
Change-Id: Ia8fe2425b21411aa2d26f7728e3c70d550fecb9a
This commit is contained in:
TensorFlower Gardener 2020-06-22 14:30:11 -07:00
commit 7a6c2f69d4
3 changed files with 7 additions and 7 deletions

View File

@ -525,7 +525,7 @@ def make_tensor_proto(values, dtype=None, shape=None, verify_shape=False,
if nparray.size * nparray.itemsize >= (1 << 31):
raise ValueError(
"Cannot create a tensor proto whose content is larger than 2GB.")
tensor_proto.tensor_content = nparray.tostring()
tensor_proto.tensor_content = nparray.tobytes()
return tensor_proto
# If we were not given values as a numpy array, compute the proto_values

View File

@ -84,22 +84,22 @@ class DecodeRawOpTest(test.TestCase):
def testToFloat16(self):
result = np.matrix([[1, -2, -3, 4]], dtype="<f2")
self.assertAllEqual(
result, parsing_ops.decode_raw([result.tostring()], dtypes.float16))
result, parsing_ops.decode_raw([result.tobytes()], dtypes.float16))
def testToBool(self):
result = np.matrix([[True, False, False, True]], dtype="<b1")
self.assertAllEqual(
result, parsing_ops.decode_raw([result.tostring()], dtypes.bool))
self.assertAllEqual(result,
parsing_ops.decode_raw([result.tobytes()], dtypes.bool))
def testToComplex64(self):
result = np.matrix([[1 + 1j, 2 - 2j, -3 + 3j, -4 - 4j]], dtype="<c8")
self.assertAllEqual(
result, parsing_ops.decode_raw([result.tostring()], dtypes.complex64))
result, parsing_ops.decode_raw([result.tobytes()], dtypes.complex64))
def testToComplex128(self):
result = np.matrix([[1 + 1j, 2 - 2j, -3 + 3j, -4 - 4j]], dtype="<c16")
self.assertAllEqual(
result, parsing_ops.decode_raw([result.tostring()], dtypes.complex128))
result, parsing_ops.decode_raw([result.tobytes()], dtypes.complex128))
def testEmptyStringInput(self):
for num_inputs in range(3):

View File

@ -295,7 +295,7 @@ class ndarray(composite_tensor.CompositeTensor): # pylint: disable=invalid-name
# TODO(wangpeng): Handle graph mode
if not isinstance(self.data, ops.EagerTensor):
raise TypeError('Indexing using symbolic tensor is not allowed')
return np.asscalar(self.data.numpy())
return self.data.numpy().item()
def tolist(self):
return self.data.numpy().tolist()