| 131 | } |
| 132 | |
| 133 | uint32_t PyObject_ToUInt32(PyObject* obj) { |
| 134 | uint32_t res = 0; |
| 135 | if ((PyLong_Check(obj) && !PyBool_Check(obj)) || // NOLINT |
| 136 | PyObject_CheckVarType(obj) || // NOLINT |
| 137 | PyObject_CheckDataType(obj) || // NOLINT |
| 138 | (PyObject_CheckTensor(obj) && |
| 139 | reinterpret_cast<TensorObject*>(obj)->tensor.numel() == 1)) { |
| 140 | res = static_cast<uint32_t>(PyLong_AsUnsignedLong(obj)); |
| 141 | return res; |
| 142 | } |
| 143 | std::string type_name = |
| 144 | std::string(reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name); |
| 145 | if (type_name.find("numpy.int") != std::string::npos) { |
| 146 | auto num_obj = PyNumber_Long(obj); |
| 147 | res = static_cast<uint32_t>(PyLong_AsUnsignedLong(obj)); |
| 148 | Py_DECREF(num_obj); |
| 149 | } else { |
| 150 | PADDLE_THROW( |
| 151 | common::errors::InvalidType("Cannot convert %s to long", type_name)); |
| 152 | } |
| 153 | return res; |
| 154 | } |
| 155 | |
| 156 | int64_t PyObject_ToInt64(PyObject* obj) { |
| 157 | int64_t res = 0; |
nothing calls this directly
no test coverage detected