MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / PyObject_ToInt64

Function PyObject_ToInt64

paddle/fluid/pybind/op_function_common.cc:156–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156int64_t PyObject_ToInt64(PyObject* obj) {
157 int64_t res = 0;
158 if ((PyLong_Check(obj) && !PyBool_Check(obj)) || // NOLINT
159 PyObject_CheckVarType(obj) || // NOLINT
160 PyObject_CheckDataType(obj) || // NOLINT
161 (PyObject_CheckTensor(obj) &&
162 reinterpret_cast<TensorObject*>(obj)->tensor.numel() == 1)) {
163 res = PyLong_AsLongLong(obj);
164 return res;
165 }
166 std::string type_name =
167 std::string(reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name);
168 if (type_name.find("numpy.int") != std::string::npos) {
169 auto num_obj = PyNumber_Long(obj);
170 res = PyLong_AsLongLong(num_obj);
171 Py_DECREF(num_obj);
172 } else {
173 PADDLE_THROW(common::errors::InvalidType("Cannot convert %s to long long",
174 type_name));
175 }
176 return res;
177}
178
179uint64_t PyObject_ToUInt64(PyObject* obj) {
180 uint64_t res = 0;

Callers 7

CastPyArg2AttrLongFunction · 0.85
CastPyArg2VectorOfInt64Function · 0.85
CastPyArg2ScalarArrayFunction · 0.85
CastPyArg2IntArrayFunction · 0.85
CastPyArg2LongFunction · 0.85
CastPyArg2LongsFunction · 0.85
CastPyArg2ScalarsFunction · 0.85

Calls 5

PyObject_CheckVarTypeFunction · 0.85
PyObject_CheckDataTypeFunction · 0.85
PyObject_CheckTensorFunction · 0.85
numelMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected