| 154 | } |
| 155 | |
| 156 | int64_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 | |
| 179 | uint64_t PyObject_ToUInt64(PyObject* obj) { |
| 180 | uint64_t res = 0; |
no test coverage detected