MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / PyUnpack_String

Function PyUnpack_String

oneflow/api/python/framework/tensor_functions_util.h:28–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26using functional::PyObjectPtr;
27
28std::string PyUnpack_String(PyObject* obj) {
29 CHECK_OR_THROW(PyUnicode_Check(obj)) << "PyUnpack_String(): expect a PyUnicode object";
30 Py_ssize_t size = -1;
31 const char* data = PyUnicode_AsUTF8AndSize(obj, &size);
32 CHECK_NOTNULL_OR_THROW(data) << "error unpacking string as utf-8";
33 return std::string(data, (size_t)size);
34}
35
36// For signature like Tensor.reshape(*shape), this function can handle these cases:
37// 1. parse positional arguments only case, like Tensor.reshape(1, 2)

Callers 1

PyParseArgsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected