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

Function PyObject_ToUInt32

paddle/fluid/pybind/op_function_common.cc:133–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133uint32_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
156int64_t PyObject_ToInt64(PyObject* obj) {
157 int64_t res = 0;

Callers

nothing calls this directly

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