MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ConvertOneInt32

Function ConvertOneInt32

tensorflow/python/lib/core/py_seq_tensor.cc:345–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343DEFINE_HELPER(ConvertUint64, uint64, DT_UINT64, ConvertOneUint64);
344
345const char* ConvertOneInt32(PyObject* v, int32* out) {
346 int64 i;
347#if PY_MAJOR_VERSION < 3
348 if (TF_PREDICT_TRUE(PyInt_Check(v))) {
349 i = PyInt_AS_LONG(v);
350 } else
351#endif
352 if (PyLong_Check(v) || IsPyDimension(v)) {
353 int overflow = 0;
354 // Have to use LongLong for 64 bits, since long is 32 bits on Windows.
355 i = PyLong_AsLongLongAndOverflow(v, &overflow);
356 if (TF_PREDICT_FALSE(overflow)) return ErrorOutOfRange;
357 } else if (PyIsInstance(v, &PyIntegerArrType_Type)) { // NumPy integers
358#if PY_MAJOR_VERSION < 3
359 Safe_PyObjectPtr as_int = make_safe(PyNumber_Int(v));
360#else
361 Safe_PyObjectPtr as_int = make_safe(PyNumber_Long(v));
362#endif
363 return ConvertOneInt32(as_int.get(), out);
364 } else if (IsPyFloat(v)) {
365 return ErrorFoundFloat;
366 } else {
367 return ErrorMixedTypes;
368 }
369 *out = static_cast<uint32>(static_cast<uint64>(i));
370 // Check for 32-bit overflow.
371 if (TF_PREDICT_FALSE(i != *out)) return ErrorFoundInt64;
372 return nullptr;
373}
374
375DEFINE_HELPER(ConvertInt32, int32, DT_INT32, ConvertOneInt32);
376

Callers

nothing calls this directly

Calls 5

IsPyDimensionFunction · 0.85
PyIsInstanceFunction · 0.85
IsPyFloatFunction · 0.85
make_safeFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected