MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / RegisterType

Function RegisterType

tensorflow/python/util/util.cc:44–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44PyObject* RegisterType(PyObject* type_name, PyObject* type) {
45 if (!PyType_Check(type)) {
46 PyErr_SetString(PyExc_TypeError,
47 tensorflow::strings::StrCat("Expecting a type, got ",
48 Py_TYPE(type)->tp_name)
49 .c_str());
50 return nullptr;
51 }
52
53 string key;
54 if (PyBytes_Check(type_name)) {
55 key = PyBytes_AsString(type_name);
56 }
57#if PY_MAJOR_VERSION >= 3
58 if (PyUnicode_Check(type_name)) {
59 key = PyUnicode_AsUTF8(type_name);
60 }
61#endif
62
63 if (PythonTypesMap()->find(key) != PythonTypesMap()->end()) {
64 PyErr_SetString(PyExc_TypeError, tensorflow::strings::StrCat(
65 "Type already registered for ", key)
66 .c_str());
67 return nullptr;
68 }
69
70 Py_INCREF(type);
71 PythonTypesMap()->emplace(key, type);
72
73 Py_RETURN_NONE;
74}
75
76namespace {
77const int kMaxItemsInCache = 1024;

Callers

nothing calls this directly

Calls 6

PythonTypesMapFunction · 0.85
c_strMethod · 0.80
StrCatFunction · 0.50
findMethod · 0.45
endMethod · 0.45
emplaceMethod · 0.45

Tested by

no test coverage detected