Replace deprecated numpy.ndarray.tostring() with tobytes()

This commit is contained in:
Lukas Geiger 2020-06-22 15:44:17 +02:00
parent 3f28ac1b63
commit 2624f6c405
2 changed files with 5 additions and 5 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))
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):