Support DT_UINT64 as a direct conversion type

PiperOrigin-RevId: 246202834
This commit is contained in:
Akshay Modi 2019-05-01 14:46:15 -07:00 committed by TensorFlower Gardener
parent afe4ce1383
commit f9a682e70f
2 changed files with 36 additions and 0 deletions

View File

@ -368,6 +368,13 @@ class TFETensorTest(test_util.TensorFlowTestCase):
"Provided value.*Requested dtype.*"):
_ = ops.convert_to_tensor(1., dtype=dtypes.int32)
def testEagerLargeConstant(self):
for t in [dtypes.uint64, dtypes.uint32, dtypes.int32, dtypes.int64]:
self.assertEqual(
constant_op.constant(t.max, dtype=t).numpy(), t.max)
self.assertEqual(
constant_op.constant(t.min, dtype=t).numpy(), t.min)
class TFETensorUtilTest(test_util.TensorFlowTestCase):

View File

@ -316,6 +316,31 @@ const char* ConvertOneInt64(PyObject* v, int64* out) {
DEFINE_HELPER(ConvertInt64, int64, DT_INT64, ConvertOneInt64);
const char* ConvertOneUint64(PyObject* v, uint64* out) {
#if PY_MAJOR_VERSION < 3
if (TF_PREDICT_TRUE(PyInt_Check(v))) {
*out = PyInt_AsUnsignedLongLongMask(v);
return nullptr;
}
#endif
if (TF_PREDICT_TRUE(PyLong_Check(v) || IsPyDimension(v))) {
*out = PyLong_AsUnsignedLongLong(v);
return nullptr;
}
if (PyIsInstance(v, &PyIntegerArrType_Type)) { // NumPy integers
#if PY_MAJOR_VERSION < 3
Safe_PyObjectPtr as_int = make_safe(PyNumber_Int(v));
#else
Safe_PyObjectPtr as_int = make_safe(PyNumber_Long(v));
#endif
return ConvertOneUint64(as_int.get(), out);
}
if (IsPyFloat(v)) return ErrorFoundFloat;
return ErrorMixedTypes;
}
DEFINE_HELPER(ConvertUint64, uint64, DT_UINT64, ConvertOneUint64);
const char* ConvertOneInt32(PyObject* v, int32* out) {
int64 i;
#if PY_MAJOR_VERSION < 3
@ -522,6 +547,10 @@ Status PySeqToTensor(PyObject* obj, DataType dtype, Tensor* ret) {
if (ConvertInt32(obj, shape, ret) == nullptr) return Status::OK();
break;
case DT_UINT64:
if (ConvertUint64(obj, shape, ret) == nullptr) return Status::OK();
break;
case DT_COMPLEX128:
if (ConvertComplex(obj, shape, ret) == nullptr) return Status::OK();
break;